browser_process_impl.cc 9.5 KB

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