browser_process_impl.cc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 "atom/browser/browser_process_impl.h"
  5. #include <utility>
  6. #include "chrome/browser/net/chrome_net_log_helper.h"
  7. #include "chrome/common/chrome_switches.h"
  8. #include "components/net_log/chrome_net_log.h"
  9. #include "components/net_log/net_export_file_writer.h"
  10. #include "components/prefs/in_memory_pref_store.h"
  11. #include "components/prefs/overlay_user_pref_store.h"
  12. #include "components/prefs/pref_registry.h"
  13. #include "components/prefs/pref_registry_simple.h"
  14. #include "components/prefs/pref_service_factory.h"
  15. #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
  16. #include "components/proxy_config/proxy_config_dictionary.h"
  17. #include "components/proxy_config/proxy_config_pref_names.h"
  18. #include "content/public/common/content_switches.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 "net/proxy_resolution/proxy_resolution_service.h"
  23. #include "services/network/public/cpp/network_switches.h"
  24. #include "ui/base/l10n/l10n_util.h"
  25. #if BUILDFLAG(ENABLE_PRINTING)
  26. #include "chrome/browser/printing/print_job_manager.h"
  27. #endif
  28. BrowserProcessImpl::BrowserProcessImpl() {
  29. g_browser_process = this;
  30. }
  31. BrowserProcessImpl::~BrowserProcessImpl() {
  32. g_browser_process = nullptr;
  33. }
  34. // static
  35. void BrowserProcessImpl::ApplyProxyModeFromCommandLine(
  36. ValueMapPrefStore* pref_store) {
  37. if (!pref_store)
  38. return;
  39. auto* command_line = base::CommandLine::ForCurrentProcess();
  40. if (command_line->HasSwitch(switches::kNoProxyServer)) {
  41. pref_store->SetValue(
  42. proxy_config::prefs::kProxy,
  43. std::make_unique<base::Value>(ProxyConfigDictionary::CreateDirect()),
  44. WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
  45. } else if (command_line->HasSwitch(switches::kProxyPacUrl)) {
  46. std::string pac_script_url =
  47. command_line->GetSwitchValueASCII(switches::kProxyPacUrl);
  48. pref_store->SetValue(
  49. proxy_config::prefs::kProxy,
  50. std::make_unique<base::Value>(ProxyConfigDictionary::CreatePacScript(
  51. pac_script_url, false /* pac_mandatory */)),
  52. WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
  53. } else if (command_line->HasSwitch(switches::kProxyAutoDetect)) {
  54. pref_store->SetValue(proxy_config::prefs::kProxy,
  55. std::make_unique<base::Value>(
  56. ProxyConfigDictionary::CreateAutoDetect()),
  57. WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
  58. } else if (command_line->HasSwitch(switches::kProxyServer)) {
  59. std::string proxy_server =
  60. command_line->GetSwitchValueASCII(switches::kProxyServer);
  61. std::string bypass_list =
  62. command_line->GetSwitchValueASCII(switches::kProxyBypassList);
  63. pref_store->SetValue(
  64. proxy_config::prefs::kProxy,
  65. std::make_unique<base::Value>(ProxyConfigDictionary::CreateFixedServers(
  66. proxy_server, bypass_list)),
  67. WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
  68. }
  69. }
  70. void BrowserProcessImpl::PostEarlyInitialization() {
  71. // Mock user prefs, as we only need to track changes for a
  72. // in memory pref store. There are no persistent preferences
  73. PrefServiceFactory prefs_factory;
  74. auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
  75. PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get());
  76. auto pref_store = base::MakeRefCounted<ValueMapPrefStore>();
  77. ApplyProxyModeFromCommandLine(pref_store.get());
  78. prefs_factory.set_command_line_prefs(std::move(pref_store));
  79. prefs_factory.set_user_prefs(new OverlayUserPrefStore(new InMemoryPrefStore));
  80. local_state_ = prefs_factory.Create(std::move(pref_registry));
  81. }
  82. void BrowserProcessImpl::PreCreateThreads(
  83. const base::CommandLine& command_line) {
  84. // Must be created before the IOThread.
  85. // Once IOThread class is no longer needed,
  86. // this can be created on first use.
  87. system_network_context_manager_ =
  88. std::make_unique<SystemNetworkContextManager>();
  89. net_log_ = std::make_unique<net_log::ChromeNetLog>();
  90. // start net log trace if --log-net-log is passed in the command line.
  91. if (command_line.HasSwitch(network::switches::kLogNetLog)) {
  92. base::FilePath log_file =
  93. command_line.GetSwitchValuePath(network::switches::kLogNetLog);
  94. if (!log_file.empty()) {
  95. net_log_->StartWritingToFile(
  96. log_file, GetNetCaptureModeFromCommandLine(command_line),
  97. command_line.GetCommandLineString(), std::string());
  98. }
  99. }
  100. // Initialize net log file exporter.
  101. system_network_context_manager_->GetNetExportFileWriter()->Initialize();
  102. // Manage global state of net and other IO thread related.
  103. io_thread_ = std::make_unique<IOThread>(
  104. net_log_.get(), system_network_context_manager_.get());
  105. }
  106. void BrowserProcessImpl::PostDestroyThreads() {
  107. io_thread_.reset();
  108. }
  109. void BrowserProcessImpl::PostMainMessageLoopRun() {
  110. // This expects to be destroyed before the task scheduler is torn down.
  111. system_network_context_manager_.reset();
  112. }
  113. bool BrowserProcessImpl::IsShuttingDown() {
  114. return false;
  115. }
  116. metrics_services_manager::MetricsServicesManager*
  117. BrowserProcessImpl::GetMetricsServicesManager() {
  118. return nullptr;
  119. }
  120. metrics::MetricsService* BrowserProcessImpl::metrics_service() {
  121. return nullptr;
  122. }
  123. rappor::RapporServiceImpl* BrowserProcessImpl::rappor_service() {
  124. return nullptr;
  125. }
  126. ProfileManager* BrowserProcessImpl::profile_manager() {
  127. return nullptr;
  128. }
  129. PrefService* BrowserProcessImpl::local_state() {
  130. DCHECK(local_state_.get());
  131. return local_state_.get();
  132. }
  133. net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
  134. return nullptr;
  135. }
  136. scoped_refptr<network::SharedURLLoaderFactory>
  137. BrowserProcessImpl::shared_url_loader_factory() {
  138. return system_network_context_manager()->GetSharedURLLoaderFactory();
  139. }
  140. variations::VariationsService* BrowserProcessImpl::variations_service() {
  141. return nullptr;
  142. }
  143. BrowserProcessPlatformPart* BrowserProcessImpl::platform_part() {
  144. return nullptr;
  145. }
  146. extensions::EventRouterForwarder*
  147. BrowserProcessImpl::extension_event_router_forwarder() {
  148. return nullptr;
  149. }
  150. NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
  151. return nullptr;
  152. }
  153. NotificationPlatformBridge* BrowserProcessImpl::notification_platform_bridge() {
  154. return nullptr;
  155. }
  156. IOThread* BrowserProcessImpl::io_thread() {
  157. DCHECK(io_thread_.get());
  158. return io_thread_.get();
  159. }
  160. SystemNetworkContextManager*
  161. BrowserProcessImpl::system_network_context_manager() {
  162. DCHECK(system_network_context_manager_.get());
  163. return system_network_context_manager_.get();
  164. }
  165. network::NetworkQualityTracker* BrowserProcessImpl::network_quality_tracker() {
  166. return nullptr;
  167. }
  168. WatchDogThread* BrowserProcessImpl::watchdog_thread() {
  169. return nullptr;
  170. }
  171. policy::ChromeBrowserPolicyConnector*
  172. BrowserProcessImpl::browser_policy_connector() {
  173. return nullptr;
  174. }
  175. policy::PolicyService* BrowserProcessImpl::policy_service() {
  176. return nullptr;
  177. }
  178. IconManager* BrowserProcessImpl::icon_manager() {
  179. return nullptr;
  180. }
  181. GpuModeManager* BrowserProcessImpl::gpu_mode_manager() {
  182. return nullptr;
  183. }
  184. printing::PrintPreviewDialogController*
  185. BrowserProcessImpl::print_preview_dialog_controller() {
  186. return nullptr;
  187. }
  188. printing::BackgroundPrintingManager*
  189. BrowserProcessImpl::background_printing_manager() {
  190. return nullptr;
  191. }
  192. IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
  193. return nullptr;
  194. }
  195. DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
  196. return nullptr;
  197. }
  198. DownloadRequestLimiter* BrowserProcessImpl::download_request_limiter() {
  199. return nullptr;
  200. }
  201. BackgroundModeManager* BrowserProcessImpl::background_mode_manager() {
  202. return nullptr;
  203. }
  204. StatusTray* BrowserProcessImpl::status_tray() {
  205. return nullptr;
  206. }
  207. safe_browsing::SafeBrowsingService*
  208. BrowserProcessImpl::safe_browsing_service() {
  209. return nullptr;
  210. }
  211. safe_browsing::ClientSideDetectionService*
  212. BrowserProcessImpl::safe_browsing_detection_service() {
  213. return nullptr;
  214. }
  215. subresource_filter::RulesetService*
  216. BrowserProcessImpl::subresource_filter_ruleset_service() {
  217. return nullptr;
  218. }
  219. optimization_guide::OptimizationGuideService*
  220. BrowserProcessImpl::optimization_guide_service() {
  221. return nullptr;
  222. }
  223. net_log::ChromeNetLog* BrowserProcessImpl::net_log() {
  224. DCHECK(net_log_.get());
  225. return net_log_.get();
  226. }
  227. component_updater::ComponentUpdateService*
  228. BrowserProcessImpl::component_updater() {
  229. return nullptr;
  230. }
  231. component_updater::SupervisedUserWhitelistInstaller*
  232. BrowserProcessImpl::supervised_user_whitelist_installer() {
  233. return nullptr;
  234. }
  235. MediaFileSystemRegistry* BrowserProcessImpl::media_file_system_registry() {
  236. return nullptr;
  237. }
  238. WebRtcLogUploader* BrowserProcessImpl::webrtc_log_uploader() {
  239. return nullptr;
  240. }
  241. network_time::NetworkTimeTracker* BrowserProcessImpl::network_time_tracker() {
  242. return nullptr;
  243. }
  244. gcm::GCMDriver* BrowserProcessImpl::gcm_driver() {
  245. return nullptr;
  246. }
  247. resource_coordinator::ResourceCoordinatorParts*
  248. BrowserProcessImpl::resource_coordinator_parts() {
  249. return nullptr;
  250. }
  251. resource_coordinator::TabManager* BrowserProcessImpl::GetTabManager() {
  252. return nullptr;
  253. }
  254. shell_integration::DefaultWebClientState
  255. BrowserProcessImpl::CachedDefaultWebClientState() {
  256. return shell_integration::UNKNOWN_DEFAULT;
  257. }
  258. prefs::InProcessPrefServiceFactory* BrowserProcessImpl::pref_service_factory()
  259. const {
  260. return nullptr;
  261. }
  262. void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
  263. locale_ = locale;
  264. }
  265. const std::string& BrowserProcessImpl::GetApplicationLocale() {
  266. return locale_;
  267. }
  268. printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
  269. #if BUILDFLAG(ENABLE_PRINTING)
  270. if (!print_job_manager_)
  271. print_job_manager_.reset(new printing::PrintJobManager());
  272. return print_job_manager_.get();
  273. #else
  274. return nullptr;
  275. #endif
  276. }