browser_process_impl.cc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 BUILDFLAG(IS_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(electron::DIR_SESSION_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. policy::ChromeBrowserPolicyConnector*
  170. BrowserProcessImpl::browser_policy_connector() {
  171. return nullptr;
  172. }
  173. policy::PolicyService* BrowserProcessImpl::policy_service() {
  174. return nullptr;
  175. }
  176. IconManager* BrowserProcessImpl::icon_manager() {
  177. return nullptr;
  178. }
  179. GpuModeManager* BrowserProcessImpl::gpu_mode_manager() {
  180. return nullptr;
  181. }
  182. printing::PrintPreviewDialogController*
  183. BrowserProcessImpl::print_preview_dialog_controller() {
  184. return nullptr;
  185. }
  186. printing::BackgroundPrintingManager*
  187. BrowserProcessImpl::background_printing_manager() {
  188. return nullptr;
  189. }
  190. IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
  191. return nullptr;
  192. }
  193. DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
  194. return nullptr;
  195. }
  196. DownloadRequestLimiter* BrowserProcessImpl::download_request_limiter() {
  197. return nullptr;
  198. }
  199. BackgroundModeManager* BrowserProcessImpl::background_mode_manager() {
  200. return nullptr;
  201. }
  202. StatusTray* BrowserProcessImpl::status_tray() {
  203. return nullptr;
  204. }
  205. safe_browsing::SafeBrowsingService*
  206. BrowserProcessImpl::safe_browsing_service() {
  207. return nullptr;
  208. }
  209. subresource_filter::RulesetService*
  210. BrowserProcessImpl::subresource_filter_ruleset_service() {
  211. return nullptr;
  212. }
  213. component_updater::ComponentUpdateService*
  214. BrowserProcessImpl::component_updater() {
  215. return nullptr;
  216. }
  217. MediaFileSystemRegistry* BrowserProcessImpl::media_file_system_registry() {
  218. return nullptr;
  219. }
  220. WebRtcLogUploader* BrowserProcessImpl::webrtc_log_uploader() {
  221. return nullptr;
  222. }
  223. network_time::NetworkTimeTracker* BrowserProcessImpl::network_time_tracker() {
  224. return nullptr;
  225. }
  226. gcm::GCMDriver* BrowserProcessImpl::gcm_driver() {
  227. return nullptr;
  228. }
  229. resource_coordinator::ResourceCoordinatorParts*
  230. BrowserProcessImpl::resource_coordinator_parts() {
  231. return nullptr;
  232. }
  233. resource_coordinator::TabManager* BrowserProcessImpl::GetTabManager() {
  234. return nullptr;
  235. }
  236. SerialPolicyAllowedPorts* BrowserProcessImpl::serial_policy_allowed_ports() {
  237. return nullptr;
  238. }
  239. HidPolicyAllowedDevices* BrowserProcessImpl::hid_policy_allowed_devices() {
  240. return nullptr;
  241. }
  242. void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
  243. locale_ = locale;
  244. }
  245. const std::string& BrowserProcessImpl::GetApplicationLocale() {
  246. return locale_;
  247. }
  248. printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
  249. #if BUILDFLAG(ENABLE_PRINTING)
  250. if (!print_job_manager_)
  251. print_job_manager_ = std::make_unique<printing::PrintJobManager>();
  252. return print_job_manager_.get();
  253. #else
  254. return nullptr;
  255. #endif
  256. }
  257. StartupData* BrowserProcessImpl::startup_data() {
  258. return nullptr;
  259. }