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