browser_process_impl.cc 8.6 KB

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