browser_process_impl.cc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/browser_process_impl.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "chrome/common/chrome_switches.h"
  8. #include "components/prefs/in_memory_pref_store.h"
  9. #include "components/prefs/overlay_user_pref_store.h"
  10. #include "components/prefs/pref_registry.h"
  11. #include "components/prefs/pref_registry_simple.h"
  12. #include "components/prefs/pref_service_factory.h"
  13. #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
  14. #include "components/proxy_config/proxy_config_dictionary.h"
  15. #include "components/proxy_config/proxy_config_pref_names.h"
  16. #include "content/public/common/content_switches.h"
  17. #include "net/proxy_resolution/proxy_config.h"
  18. #include "net/proxy_resolution/proxy_config_service.h"
  19. #include "net/proxy_resolution/proxy_config_with_annotation.h"
  20. #include "net/proxy_resolution/proxy_resolution_service.h"
  21. #include "services/network/public/cpp/network_switches.h"
  22. #if BUILDFLAG(ENABLE_PRINTING)
  23. #include "chrome/browser/printing/print_job_manager.h"
  24. #endif
  25. BrowserProcessImpl::BrowserProcessImpl() {
  26. g_browser_process = this;
  27. }
  28. BrowserProcessImpl::~BrowserProcessImpl() {
  29. g_browser_process = nullptr;
  30. }
  31. // static
  32. void BrowserProcessImpl::ApplyProxyModeFromCommandLine(
  33. ValueMapPrefStore* pref_store) {
  34. if (!pref_store)
  35. return;
  36. auto* command_line = base::CommandLine::ForCurrentProcess();
  37. if (command_line->HasSwitch(switches::kNoProxyServer)) {
  38. pref_store->SetValue(
  39. proxy_config::prefs::kProxy,
  40. std::make_unique<base::Value>(ProxyConfigDictionary::CreateDirect()),
  41. WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
  42. } else if (command_line->HasSwitch(switches::kProxyPacUrl)) {
  43. std::string pac_script_url =
  44. command_line->GetSwitchValueASCII(switches::kProxyPacUrl);
  45. pref_store->SetValue(
  46. proxy_config::prefs::kProxy,
  47. std::make_unique<base::Value>(ProxyConfigDictionary::CreatePacScript(
  48. pac_script_url, false /* pac_mandatory */)),
  49. WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
  50. } else if (command_line->HasSwitch(switches::kProxyAutoDetect)) {
  51. pref_store->SetValue(proxy_config::prefs::kProxy,
  52. std::make_unique<base::Value>(
  53. ProxyConfigDictionary::CreateAutoDetect()),
  54. WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
  55. } else if (command_line->HasSwitch(switches::kProxyServer)) {
  56. std::string proxy_server =
  57. command_line->GetSwitchValueASCII(switches::kProxyServer);
  58. std::string bypass_list =
  59. command_line->GetSwitchValueASCII(switches::kProxyBypassList);
  60. pref_store->SetValue(
  61. proxy_config::prefs::kProxy,
  62. std::make_unique<base::Value>(ProxyConfigDictionary::CreateFixedServers(
  63. proxy_server, bypass_list)),
  64. WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
  65. }
  66. }
  67. void BrowserProcessImpl::PostEarlyInitialization() {
  68. // Mock user prefs, as we only need to track changes for a
  69. // in memory pref store. There are no persistent preferences
  70. PrefServiceFactory prefs_factory;
  71. auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
  72. PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get());
  73. auto pref_store = base::MakeRefCounted<ValueMapPrefStore>();
  74. ApplyProxyModeFromCommandLine(pref_store.get());
  75. prefs_factory.set_command_line_prefs(std::move(pref_store));
  76. prefs_factory.set_user_prefs(new OverlayUserPrefStore(new InMemoryPrefStore));
  77. local_state_ = prefs_factory.Create(std::move(pref_registry));
  78. }
  79. void BrowserProcessImpl::PreCreateThreads() {
  80. // Must be created before the IOThread.
  81. // Once IOThread class is no longer needed,
  82. // this can be created on first use.
  83. if (!SystemNetworkContextManager::GetInstance())
  84. SystemNetworkContextManager::CreateInstance(local_state_.get());
  85. }
  86. void BrowserProcessImpl::PostMainMessageLoopRun() {
  87. if (local_state_)
  88. local_state_->CommitPendingWrite();
  89. // This expects to be destroyed before the task scheduler is torn down.
  90. SystemNetworkContextManager::DeleteInstance();
  91. }
  92. bool BrowserProcessImpl::IsShuttingDown() {
  93. return false;
  94. }
  95. metrics_services_manager::MetricsServicesManager*
  96. BrowserProcessImpl::GetMetricsServicesManager() {
  97. return nullptr;
  98. }
  99. metrics::MetricsService* BrowserProcessImpl::metrics_service() {
  100. return nullptr;
  101. }
  102. rappor::RapporServiceImpl* BrowserProcessImpl::rappor_service() {
  103. return nullptr;
  104. }
  105. ProfileManager* BrowserProcessImpl::profile_manager() {
  106. return nullptr;
  107. }
  108. PrefService* BrowserProcessImpl::local_state() {
  109. DCHECK(local_state_.get());
  110. return local_state_.get();
  111. }
  112. scoped_refptr<network::SharedURLLoaderFactory>
  113. BrowserProcessImpl::shared_url_loader_factory() {
  114. return system_network_context_manager()->GetSharedURLLoaderFactory();
  115. }
  116. variations::VariationsService* BrowserProcessImpl::variations_service() {
  117. return nullptr;
  118. }
  119. BrowserProcessPlatformPart* BrowserProcessImpl::platform_part() {
  120. return nullptr;
  121. }
  122. extensions::EventRouterForwarder*
  123. BrowserProcessImpl::extension_event_router_forwarder() {
  124. return nullptr;
  125. }
  126. NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
  127. return nullptr;
  128. }
  129. NotificationPlatformBridge* BrowserProcessImpl::notification_platform_bridge() {
  130. return nullptr;
  131. }
  132. SystemNetworkContextManager*
  133. BrowserProcessImpl::system_network_context_manager() {
  134. DCHECK(SystemNetworkContextManager::GetInstance());
  135. return SystemNetworkContextManager::GetInstance();
  136. }
  137. network::NetworkQualityTracker* BrowserProcessImpl::network_quality_tracker() {
  138. return nullptr;
  139. }
  140. WatchDogThread* BrowserProcessImpl::watchdog_thread() {
  141. return nullptr;
  142. }
  143. policy::ChromeBrowserPolicyConnector*
  144. BrowserProcessImpl::browser_policy_connector() {
  145. return nullptr;
  146. }
  147. policy::PolicyService* BrowserProcessImpl::policy_service() {
  148. return nullptr;
  149. }
  150. IconManager* BrowserProcessImpl::icon_manager() {
  151. return nullptr;
  152. }
  153. GpuModeManager* BrowserProcessImpl::gpu_mode_manager() {
  154. return nullptr;
  155. }
  156. printing::PrintPreviewDialogController*
  157. BrowserProcessImpl::print_preview_dialog_controller() {
  158. return nullptr;
  159. }
  160. printing::BackgroundPrintingManager*
  161. BrowserProcessImpl::background_printing_manager() {
  162. return nullptr;
  163. }
  164. IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
  165. return nullptr;
  166. }
  167. DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
  168. return nullptr;
  169. }
  170. DownloadRequestLimiter* BrowserProcessImpl::download_request_limiter() {
  171. return nullptr;
  172. }
  173. BackgroundModeManager* BrowserProcessImpl::background_mode_manager() {
  174. return nullptr;
  175. }
  176. StatusTray* BrowserProcessImpl::status_tray() {
  177. return nullptr;
  178. }
  179. safe_browsing::SafeBrowsingService*
  180. BrowserProcessImpl::safe_browsing_service() {
  181. return nullptr;
  182. }
  183. safe_browsing::ClientSideDetectionService*
  184. BrowserProcessImpl::safe_browsing_detection_service() {
  185. return nullptr;
  186. }
  187. subresource_filter::RulesetService*
  188. BrowserProcessImpl::subresource_filter_ruleset_service() {
  189. return nullptr;
  190. }
  191. optimization_guide::OptimizationGuideService*
  192. BrowserProcessImpl::optimization_guide_service() {
  193. return nullptr;
  194. }
  195. component_updater::ComponentUpdateService*
  196. BrowserProcessImpl::component_updater() {
  197. return nullptr;
  198. }
  199. MediaFileSystemRegistry* BrowserProcessImpl::media_file_system_registry() {
  200. return nullptr;
  201. }
  202. WebRtcLogUploader* BrowserProcessImpl::webrtc_log_uploader() {
  203. return nullptr;
  204. }
  205. network_time::NetworkTimeTracker* BrowserProcessImpl::network_time_tracker() {
  206. return nullptr;
  207. }
  208. gcm::GCMDriver* BrowserProcessImpl::gcm_driver() {
  209. return nullptr;
  210. }
  211. resource_coordinator::ResourceCoordinatorParts*
  212. BrowserProcessImpl::resource_coordinator_parts() {
  213. return nullptr;
  214. }
  215. resource_coordinator::TabManager* BrowserProcessImpl::GetTabManager() {
  216. return nullptr;
  217. }
  218. void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
  219. locale_ = locale;
  220. }
  221. const std::string& BrowserProcessImpl::GetApplicationLocale() {
  222. return locale_;
  223. }
  224. printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
  225. #if BUILDFLAG(ENABLE_PRINTING)
  226. if (!print_job_manager_)
  227. print_job_manager_ = std::make_unique<printing::PrintJobManager>();
  228. return print_job_manager_.get();
  229. #else
  230. return nullptr;
  231. #endif
  232. }
  233. StartupData* BrowserProcessImpl::startup_data() {
  234. return nullptr;
  235. }