browser_process_impl.cc 8.7 KB

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