browser_process_impl.cc 9.4 KB

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