• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 The Chromium Embedded Framework Authors.
2 // Portions (c) 2011 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #include "libcef/browser/alloy/chrome_browser_process_alloy.h"
7 
8 #include "libcef/browser/alloy/chrome_profile_manager_alloy.h"
9 #include "libcef/browser/browser_context.h"
10 #include "libcef/browser/context.h"
11 #include "libcef/browser/extensions/extensions_browser_client.h"
12 #include "libcef/browser/prefs/browser_prefs.h"
13 #include "libcef/browser/thread_util.h"
14 #include "libcef/common/cef_switches.h"
15 #include "libcef/common/extensions/extensions_client.h"
16 #include "libcef/common/extensions/extensions_util.h"
17 
18 #include "base/command_line.h"
19 #include "chrome/browser/component_updater/chrome_component_updater_configurator.h"
20 #include "chrome/browser/net/system_network_context_manager.h"
21 #include "chrome/browser/policy/chrome_browser_policy_connector.h"
22 #include "chrome/browser/printing/background_printing_manager.h"
23 #include "chrome/browser/printing/print_job_manager.h"
24 #include "chrome/browser/printing/print_preview_dialog_controller.h"
25 #include "chrome/browser/ui/prefs/pref_watcher.h"
26 #include "components/component_updater/component_updater_service.h"
27 #include "components/component_updater/timer_update_scheduler.h"
28 #include "components/net_log/chrome_net_log.h"
29 #include "components/prefs/pref_service.h"
30 #include "content/browser/startup_helper.h"
31 #include "content/public/common/content_switches.h"
32 #include "net/log/net_log_capture_mode.h"
33 #include "services/network/public/cpp/network_switches.h"
34 #include "services/network/public/cpp/shared_url_loader_factory.h"
35 
ChromeBrowserProcessAlloy()36 ChromeBrowserProcessAlloy::ChromeBrowserProcessAlloy()
37     : initialized_(false),
38       context_initialized_(false),
39       shutdown_(false),
40       locale_("en-US") {}
41 
~ChromeBrowserProcessAlloy()42 ChromeBrowserProcessAlloy::~ChromeBrowserProcessAlloy() {
43   DCHECK((!initialized_ && !context_initialized_) || shutdown_);
44 
45   if (extensions::ExtensionsEnabled()) {
46     extensions::ExtensionsBrowserClient::Set(nullptr);
47     extensions_browser_client_.reset();
48   }
49 }
50 
Initialize()51 void ChromeBrowserProcessAlloy::Initialize() {
52   DCHECK(!initialized_);
53   DCHECK(!context_initialized_);
54   DCHECK(!shutdown_);
55   DCHECK(!field_trial_list_);
56 
57   // Initialize this early before any code tries to check feature flags.
58   field_trial_list_ = content::SetUpFieldTrialsAndFeatureList();
59 
60   if (extensions::ExtensionsEnabled()) {
61     // Initialize extension global objects before creating the global
62     // BrowserContext.
63     extensions_client_.reset(new extensions::CefExtensionsClient());
64     extensions::ExtensionsClient::Set(extensions_client_.get());
65     extensions_browser_client_.reset(
66         new extensions::CefExtensionsBrowserClient);
67     extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get());
68   }
69 
70   initialized_ = true;
71 }
72 
OnContextInitialized()73 void ChromeBrowserProcessAlloy::OnContextInitialized() {
74   CEF_REQUIRE_UIT();
75   DCHECK(initialized_);
76   DCHECK(!context_initialized_);
77   DCHECK(!shutdown_);
78 
79   // Must be created after the NotificationService.
80   print_job_manager_.reset(new printing::PrintJobManager());
81   profile_manager_.reset(new ChromeProfileManagerAlloy());
82   event_router_forwarder_ = new extensions::EventRouterForwarder();
83   context_initialized_ = true;
84 }
85 
CleanupOnUIThread()86 void ChromeBrowserProcessAlloy::CleanupOnUIThread() {
87   CEF_REQUIRE_UIT();
88   DCHECK(initialized_);
89   DCHECK(context_initialized_);
90   DCHECK(!shutdown_);
91 
92   // Wait for the pending print jobs to finish. Don't do this later, since
93   // this might cause a nested message loop to run, and we don't want pending
94   // tasks to run once teardown has started.
95   print_job_manager_->Shutdown();
96   print_job_manager_.reset(nullptr);
97   print_preview_dialog_controller_ = nullptr;
98 
99   profile_manager_.reset();
100   event_router_forwarder_ = nullptr;
101 
102   if (SystemNetworkContextManager::GetInstance()) {
103     SystemNetworkContextManager::DeleteInstance();
104   }
105 
106   // Release any references held by objects associated with a Profile. The
107   // Profile will be deleted later.
108   for (const auto& browser_context : CefBrowserContext::GetAll()) {
109     // Release any references to |local_state_|.
110     auto profile = browser_context->AsProfile();
111     PrefWatcher* pref_watcher = PrefWatcher::Get(profile);
112     if (pref_watcher)
113       pref_watcher->Shutdown();
114 
115     // Unregister observers for |background_printing_manager_|.
116     if (background_printing_manager_) {
117       background_printing_manager_->DeletePreviewContentsForBrowserContext(
118           profile);
119     }
120   }
121 
122   local_state_.reset();
123   browser_policy_connector_.reset();
124   background_printing_manager_.reset();
125   field_trial_list_.reset();
126   component_updater_.reset();
127 
128   shutdown_ = true;
129 }
130 
EndSession()131 void ChromeBrowserProcessAlloy::EndSession() {
132   NOTREACHED();
133 }
134 
FlushLocalStateAndReply(base::OnceClosure reply)135 void ChromeBrowserProcessAlloy::FlushLocalStateAndReply(
136     base::OnceClosure reply) {
137   NOTREACHED();
138 }
139 
140 metrics_services_manager::MetricsServicesManager*
GetMetricsServicesManager()141 ChromeBrowserProcessAlloy::GetMetricsServicesManager() {
142   NOTREACHED();
143   return nullptr;
144 }
145 
metrics_service()146 metrics::MetricsService* ChromeBrowserProcessAlloy::metrics_service() {
147   NOTREACHED();
148   return nullptr;
149 }
150 
151 SystemNetworkContextManager*
system_network_context_manager()152 ChromeBrowserProcessAlloy::system_network_context_manager() {
153   DCHECK(SystemNetworkContextManager::GetInstance());
154   return SystemNetworkContextManager::GetInstance();
155 }
156 
157 network::NetworkQualityTracker*
network_quality_tracker()158 ChromeBrowserProcessAlloy::network_quality_tracker() {
159   NOTREACHED();
160   return nullptr;
161 }
162 
profile_manager()163 ProfileManager* ChromeBrowserProcessAlloy::profile_manager() {
164   DCHECK(context_initialized_);
165   return profile_manager_.get();
166 }
167 
local_state()168 PrefService* ChromeBrowserProcessAlloy::local_state() {
169   DCHECK(initialized_);
170   if (!local_state_) {
171     // Use a location that is shared by all request contexts.
172     const CefSettings& settings = CefContext::Get()->settings();
173     const base::FilePath& root_cache_path =
174         base::FilePath(CefString(&settings.root_cache_path));
175 
176     // Used for very early NetworkService initialization.
177     // Always persist preferences for this PrefService if possible because it
178     // contains the cookie encryption key on Windows.
179     local_state_ =
180         browser_prefs::CreatePrefService(nullptr /* profile */, root_cache_path,
181                                          true /* persist_user_preferences */);
182   }
183   return local_state_.get();
184 }
185 
186 scoped_refptr<network::SharedURLLoaderFactory>
shared_url_loader_factory()187 ChromeBrowserProcessAlloy::shared_url_loader_factory() {
188   NOTREACHED();
189   return nullptr;
190 }
191 
variations_service()192 variations::VariationsService* ChromeBrowserProcessAlloy::variations_service() {
193   NOTREACHED();
194   return nullptr;
195 }
196 
platform_part()197 BrowserProcessPlatformPart* ChromeBrowserProcessAlloy::platform_part() {
198   NOTREACHED();
199   return nullptr;
200 }
201 
202 extensions::EventRouterForwarder*
extension_event_router_forwarder()203 ChromeBrowserProcessAlloy::extension_event_router_forwarder() {
204   DCHECK(context_initialized_);
205   return event_router_forwarder_.get();
206 }
207 
notification_ui_manager()208 NotificationUIManager* ChromeBrowserProcessAlloy::notification_ui_manager() {
209   NOTREACHED();
210   return nullptr;
211 }
212 
213 NotificationPlatformBridge*
notification_platform_bridge()214 ChromeBrowserProcessAlloy::notification_platform_bridge() {
215   NOTREACHED();
216   return nullptr;
217 }
218 
219 policy::ChromeBrowserPolicyConnector*
browser_policy_connector()220 ChromeBrowserProcessAlloy::browser_policy_connector() {
221   if (!browser_policy_connector_) {
222     browser_policy_connector_ =
223         std::make_unique<policy::ChromeBrowserPolicyConnector>();
224   }
225   return browser_policy_connector_.get();
226 }
227 
policy_service()228 policy::PolicyService* ChromeBrowserProcessAlloy::policy_service() {
229   return browser_policy_connector()->GetPolicyService();
230 }
231 
icon_manager()232 IconManager* ChromeBrowserProcessAlloy::icon_manager() {
233   NOTREACHED();
234   return nullptr;
235 }
236 
gpu_mode_manager()237 GpuModeManager* ChromeBrowserProcessAlloy::gpu_mode_manager() {
238   NOTREACHED();
239   return nullptr;
240 }
241 
CreateDevToolsProtocolHandler()242 void ChromeBrowserProcessAlloy::CreateDevToolsProtocolHandler() {
243   NOTREACHED();
244 }
245 
CreateDevToolsAutoOpener()246 void ChromeBrowserProcessAlloy::CreateDevToolsAutoOpener() {
247   NOTREACHED();
248 }
249 
IsShuttingDown()250 bool ChromeBrowserProcessAlloy::IsShuttingDown() {
251   NOTREACHED();
252   return false;
253 }
254 
print_job_manager()255 printing::PrintJobManager* ChromeBrowserProcessAlloy::print_job_manager() {
256   DCHECK(context_initialized_);
257   return print_job_manager_.get();
258 }
259 
260 printing::PrintPreviewDialogController*
print_preview_dialog_controller()261 ChromeBrowserProcessAlloy::print_preview_dialog_controller() {
262   if (!print_preview_dialog_controller_.get()) {
263     print_preview_dialog_controller_ =
264         new printing::PrintPreviewDialogController();
265   }
266   return print_preview_dialog_controller_.get();
267 }
268 
269 printing::BackgroundPrintingManager*
background_printing_manager()270 ChromeBrowserProcessAlloy::background_printing_manager() {
271   if (!background_printing_manager_.get()) {
272     background_printing_manager_.reset(
273         new printing::BackgroundPrintingManager());
274   }
275   return background_printing_manager_.get();
276 }
277 
278 IntranetRedirectDetector*
intranet_redirect_detector()279 ChromeBrowserProcessAlloy::intranet_redirect_detector() {
280   NOTREACHED();
281   return nullptr;
282 }
283 
GetApplicationLocale()284 const std::string& ChromeBrowserProcessAlloy::GetApplicationLocale() {
285   DCHECK(!locale_.empty());
286   return locale_;
287 }
288 
SetApplicationLocale(const std::string & locale)289 void ChromeBrowserProcessAlloy::SetApplicationLocale(
290     const std::string& locale) {
291   locale_ = locale;
292 }
293 
download_status_updater()294 DownloadStatusUpdater* ChromeBrowserProcessAlloy::download_status_updater() {
295   NOTREACHED();
296   return nullptr;
297 }
298 
download_request_limiter()299 DownloadRequestLimiter* ChromeBrowserProcessAlloy::download_request_limiter() {
300   NOTREACHED();
301   return nullptr;
302 }
303 
304 #if BUILDFLAG(ENABLE_BACKGROUND_MODE)
background_mode_manager()305 BackgroundModeManager* ChromeBrowserProcessAlloy::background_mode_manager() {
306   NOTREACHED();
307   return nullptr;
308 }
309 
set_background_mode_manager_for_test(std::unique_ptr<BackgroundModeManager> manager)310 void ChromeBrowserProcessAlloy::set_background_mode_manager_for_test(
311     std::unique_ptr<BackgroundModeManager> manager) {
312   NOTREACHED();
313 }
314 #endif
315 
status_tray()316 StatusTray* ChromeBrowserProcessAlloy::status_tray() {
317   NOTREACHED();
318   return nullptr;
319 }
320 
321 safe_browsing::SafeBrowsingService*
safe_browsing_service()322 ChromeBrowserProcessAlloy::safe_browsing_service() {
323   return nullptr;
324 }
325 
326 subresource_filter::RulesetService*
subresource_filter_ruleset_service()327 ChromeBrowserProcessAlloy::subresource_filter_ruleset_service() {
328   NOTREACHED();
329   return nullptr;
330 }
331 
332 federated_learning::FlocSortingLshClustersService*
floc_sorting_lsh_clusters_service()333 ChromeBrowserProcessAlloy::floc_sorting_lsh_clusters_service() {
334   NOTREACHED();
335   return nullptr;
336 }
337 
startup_data()338 StartupData* ChromeBrowserProcessAlloy::startup_data() {
339   NOTREACHED();
340   return nullptr;
341 }
342 
343 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
StartAutoupdateTimer()344 void ChromeBrowserProcessAlloy::StartAutoupdateTimer() {}
345 #endif
346 
347 component_updater::ComponentUpdateService*
component_updater()348 ChromeBrowserProcessAlloy::component_updater() {
349   if (component_updater_)
350     return component_updater_.get();
351 
352   if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
353     return nullptr;
354   }
355 
356   std::unique_ptr<component_updater::UpdateScheduler> scheduler =
357       std::make_unique<component_updater::TimerUpdateScheduler>();
358 
359   component_updater_ = component_updater::ComponentUpdateServiceFactory(
360       component_updater::MakeChromeComponentUpdaterConfigurator(
361           base::CommandLine::ForCurrentProcess(),
362           g_browser_process->local_state()),
363       std::move(scheduler), /*brand=*/std::string());
364 
365   return component_updater_.get();
366 }
367 
368 MediaFileSystemRegistry*
media_file_system_registry()369 ChromeBrowserProcessAlloy::media_file_system_registry() {
370   NOTREACHED();
371   return nullptr;
372 }
373 
webrtc_log_uploader()374 WebRtcLogUploader* ChromeBrowserProcessAlloy::webrtc_log_uploader() {
375   NOTREACHED();
376   return nullptr;
377 }
378 
379 network_time::NetworkTimeTracker*
network_time_tracker()380 ChromeBrowserProcessAlloy::network_time_tracker() {
381   NOTREACHED();
382   return nullptr;
383 }
384 
gcm_driver()385 gcm::GCMDriver* ChromeBrowserProcessAlloy::gcm_driver() {
386   NOTREACHED();
387   return nullptr;
388 }
389 
GetTabManager()390 resource_coordinator::TabManager* ChromeBrowserProcessAlloy::GetTabManager() {
391   NOTREACHED();
392   return nullptr;
393 }
394 
395 resource_coordinator::ResourceCoordinatorParts*
resource_coordinator_parts()396 ChromeBrowserProcessAlloy::resource_coordinator_parts() {
397   NOTREACHED();
398   return nullptr;
399 }
400 
GetBuildState()401 BuildState* ChromeBrowserProcessAlloy::GetBuildState() {
402   NOTREACHED();
403   return nullptr;
404 }
405 
406 SerialPolicyAllowedPorts*
serial_policy_allowed_ports()407 ChromeBrowserProcessAlloy::serial_policy_allowed_ports() {
408   NOTREACHED();
409   return nullptr;
410 }
411 
412 breadcrumbs::BreadcrumbPersistentStorageManager*
GetBreadcrumbPersistentStorageManager()413 ChromeBrowserProcessAlloy::GetBreadcrumbPersistentStorageManager() {
414   NOTREACHED();
415   return nullptr;
416 }
417