1 // Copyright 2013 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 
5 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
6 
7 #include <memory>
8 #include <utility>
9 
10 #include "build/build_config.h"
11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
12 #include "chrome/browser/autocomplete/in_memory_url_index_factory.h"
13 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h"
14 #include "chrome/browser/autofill/autofill_offer_manager_factory.h"
15 #include "chrome/browser/autofill/personal_data_manager_factory.h"
16 #include "chrome/browser/background/background_contents_service_factory.h"
17 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
18 #include "chrome/browser/browsing_data/access_context_audit_service_factory.h"
19 #include "chrome/browser/browsing_data/browsing_data_history_observer_service.h"
20 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.h"
21 #include "chrome/browser/chrome_browser_main.h"
22 #include "chrome/browser/client_hints/client_hints_factory.h"
23 #include "chrome/browser/consent_auditor/consent_auditor_factory.h"
24 #include "chrome/browser/content_settings/cookie_settings_factory.h"
25 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
26 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
27 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
28 #include "chrome/browser/domain_reliability/service_factory.h"
29 #include "chrome/browser/download/download_core_service_factory.h"
30 #include "chrome/browser/download/download_service_factory.h"
31 #include "chrome/browser/engagement/site_engagement_service.h"
32 #include "chrome/browser/engagement/site_engagement_service_factory.h"
33 #include "chrome/browser/favicon/favicon_service_factory.h"
34 #include "chrome/browser/favicon/history_ui_favicon_request_handler_factory.h"
35 #include "chrome/browser/feature_engagement/tracker_factory.h"
36 #include "chrome/browser/google/google_search_domain_mixing_metrics_emitter_factory.h"
37 #include "chrome/browser/history/domain_diversity_reporter_factory.h"
38 #include "chrome/browser/history/history_service_factory.h"
39 #include "chrome/browser/history/top_sites_factory.h"
40 #include "chrome/browser/language/language_model_manager_factory.h"
41 #include "chrome/browser/language/url_language_histogram_factory.h"
42 #include "chrome/browser/media/history/media_history_keyed_service_factory.h"
43 #include "chrome/browser/media/media_engagement_service.h"
44 #include "chrome/browser/media/media_engagement_service_factory.h"
45 #include "chrome/browser/media/router/chrome_media_router_factory.h"
46 #include "chrome/browser/media/router/presentation/chrome_local_presentation_manager_factory.h"
47 #include "chrome/browser/media/webrtc/webrtc_event_log_manager_keyed_service_factory.h"
48 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h"
49 #include "chrome/browser/notifications/notifier_state_tracker_factory.h"
50 #include "chrome/browser/page_load_metrics/observers/https_engagement_metrics/https_engagement_service_factory.h"
51 #include "chrome/browser/password_manager/password_store_factory.h"
52 #include "chrome/browser/permissions/adaptive_quiet_notification_permission_ui_enabler.h"
53 #include "chrome/browser/permissions/last_tab_standing_tracker_factory.h"
54 #include "chrome/browser/persisted_state_db/persisted_state_db_content.pb.h"
55 #include "chrome/browser/persisted_state_db/profile_proto_db_factory.h"
56 #include "chrome/browser/plugins/plugin_prefs_factory.h"
57 #include "chrome/browser/policy/cloud/user_cloud_policy_invalidator_factory.h"
58 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h"
59 #include "chrome/browser/predictors/loading_predictor_factory.h"
60 #include "chrome/browser/predictors/predictor_database_factory.h"
61 #include "chrome/browser/prefetch/no_state_prefetch/prerender_link_manager_factory.h"
62 #include "chrome/browser/prefetch/no_state_prefetch/prerender_manager_factory.h"
63 #include "chrome/browser/prefs/pref_metrics_service.h"
64 #include "chrome/browser/profiles/gaia_info_update_service_factory.h"
65 #include "chrome/browser/profiles/renderer_updater_factory.h"
66 #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h"
67 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
68 #include "chrome/browser/search_engines/template_url_fetcher_factory.h"
69 #include "chrome/browser/search_engines/template_url_service_factory.h"
70 #include "chrome/browser/send_tab_to_self/send_tab_to_self_client_service_factory.h"
71 #include "chrome/browser/sessions/tab_restore_service_factory.h"
72 #include "chrome/browser/sharing/sharing_service_factory.h"
73 #include "chrome/browser/signin/about_signin_internals_factory.h"
74 #include "chrome/browser/signin/account_consistency_mode_manager_factory.h"
75 #include "chrome/browser/signin/account_investigator_factory.h"
76 #include "chrome/browser/signin/account_reconcilor_factory.h"
77 #include "chrome/browser/signin/chrome_signin_client_factory.h"
78 #include "chrome/browser/signin/identity_manager_factory.h"
79 #include "chrome/browser/signin/signin_profile_attributes_updater_factory.h"
80 #include "chrome/browser/ssl/sct_reporting_service_factory.h"
81 #include "chrome/browser/sync/model_type_store_service_factory.h"
82 #include "chrome/browser/sync/profile_sync_service_factory.h"
83 #include "chrome/browser/sync/user_event_service_factory.h"
84 #include "chrome/browser/themes/theme_service_factory.h"
85 #include "chrome/browser/translate/translate_ranker_factory.h"
86 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
87 #include "chrome/browser/ui/find_bar/find_bar_state_factory.h"
88 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
89 #include "chrome/browser/ui/read_later/reading_list_model_factory.h"
90 #include "chrome/browser/ui/tabs/pinned_tab_service_factory.h"
91 #include "chrome/browser/ui/toolbar/toolbar_actions_model_factory.h"
92 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
93 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
94 #include "chrome/browser/undo/bookmark_undo_service_factory.h"
95 #include "chrome/browser/unified_consent/unified_consent_service_factory.h"
96 #include "chrome/browser/web_data_service_factory.h"
97 #include "chrome/common/buildflags.h"
98 #include "components/captive_portal/core/buildflags.h"
99 #include "components/permissions/features.h"
100 #include "components/reading_list/features/reading_list_switches.h"
101 #include "components/safe_browsing/buildflags.h"
102 #include "components/signin/public/base/signin_buildflags.h"
103 #include "components/spellcheck/spellcheck_buildflags.h"
104 #include "extensions/buildflags/buildflags.h"
105 #include "media/base/media_switches.h"
106 #include "ppapi/buildflags/buildflags.h"
107 #include "printing/buildflags/buildflags.h"
108 
109 #if defined(OS_ANDROID)
110 #include "chrome/browser/android/explore_sites/explore_sites_service_factory.h"
111 #include "chrome/browser/android/reading_list/reading_list_manager_factory.h"
112 #include "chrome/browser/android/search_permissions/search_permissions_service.h"
113 #include "chrome/browser/android/thin_webview/chrome_thin_webview_initializer.h"
114 #include "chrome/browser/media/android/cdm/media_drm_origin_id_manager_factory.h"
115 #else
116 #include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
117 #include "chrome/browser/browsing_data/chrome_browsing_data_lifetime_manager_factory.h"
118 #include "chrome/browser/feedback/feedback_uploader_factory_chrome.h"
119 #include "chrome/browser/media/feeds/media_feeds_service_factory.h"
120 #include "chrome/browser/metrics/desktop_session_duration/desktop_profile_session_durations_service_factory.h"
121 #include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_facade_factory.h"
122 #include "chrome/browser/profiles/profile_theme_update_service_factory.h"
123 #include "chrome/browser/search/instant_service_factory.h"
124 #include "chrome/browser/storage/storage_notification_service_factory.h"
125 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
126 #include "chrome/browser/ui/media_router/media_router_ui_service_factory.h"
127 #include "chrome/browser/usb/usb_chooser_context_factory.h"
128 #endif
129 
130 #if defined(OS_CHROMEOS)
131 #include "chrome/browser/chromeos/browser_context_keyed_service_factories.h"
132 #else
133 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h"
134 #endif
135 
136 #if defined(OS_WIN)
137 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h"
138 #endif
139 
140 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
141 #include "chrome/browser/captive_portal/captive_portal_service_factory.h"
142 #endif
143 
144 #if BUILDFLAG(ENABLE_DICE_SUPPORT)
145 #include "chrome/browser/signin/dice_web_signin_interceptor_factory.h"
146 #include "chrome/browser/signin/signin_manager_factory.h"
147 #endif
148 
149 #if BUILDFLAG(ENABLE_EXTENSIONS)
150 #include "apps/browser_context_keyed_service_factories.h"
151 #include "chrome/browser/apps/platform_apps/api/browser_context_keyed_service_factories.h"
152 #include "chrome/browser/apps/platform_apps/browser_context_keyed_service_factories.h"
153 #include "chrome/browser/extensions/browser_context_keyed_service_factories.h"
154 #include "chrome/browser/ui/web_applications/web_app_metrics_factory.h"
155 #include "chrome/browser/web_applications/web_app_provider_factory.h"
156 #include "extensions/browser/browser_context_keyed_service_factories.h"
157 #endif
158 
159 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS)
160 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
161 #endif
162 
163 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
164 #include "chrome/browser/printing/cloud_print/privet_notifications_factory.h"
165 #endif
166 
167 #if BUILDFLAG(ENABLE_SESSION_SERVICE)
168 #include "chrome/browser/sessions/session_service_factory.h"
169 #endif
170 
171 #if BUILDFLAG(ENABLE_SPELLCHECK)
172 #include "chrome/browser/spellchecker/spellcheck_factory.h"
173 #endif
174 
175 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
176 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
177 #endif
178 
179 #if BUILDFLAG(FULL_SAFE_BROWSING)
180 #include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h"
181 #endif
182 
183 #if defined(OS_CHROMEOS)
184 #include "chrome/browser/chromeos/login/security_token_session_controller_factory.h"
185 #include "chrome/browser/nearby_sharing/nearby_sharing_service_factory.h"
186 #endif
187 
188 namespace chrome {
189 
AddProfilesExtraParts(ChromeBrowserMainParts * main_parts)190 void AddProfilesExtraParts(ChromeBrowserMainParts* main_parts) {
191   main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsProfiles>());
192 }
193 
194 }  // namespace chrome
195 
ChromeBrowserMainExtraPartsProfiles()196 ChromeBrowserMainExtraPartsProfiles::ChromeBrowserMainExtraPartsProfiles() {}
197 
~ChromeBrowserMainExtraPartsProfiles()198 ChromeBrowserMainExtraPartsProfiles::~ChromeBrowserMainExtraPartsProfiles() {}
199 
200 // This method gets the instance of each ServiceFactory. We do this so that
201 // each ServiceFactory initializes itself and registers its dependencies with
202 // the global PreferenceDependencyManager. We need to have a complete
203 // dependency graph when we create a profile so we can dispatch the profile
204 // creation message to the services that want to create their services at
205 // profile creation time.
206 //
207 // TODO(erg): This needs to be something else. I don't think putting every
208 // FooServiceFactory here will scale or is desirable long term.
209 //
210 // static
211 void ChromeBrowserMainExtraPartsProfiles::
EnsureBrowserContextKeyedServiceFactoriesBuilt()212     EnsureBrowserContextKeyedServiceFactoriesBuilt() {
213 #if BUILDFLAG(ENABLE_EXTENSIONS)
214   apps::EnsureBrowserContextKeyedServiceFactoriesBuilt();
215   chrome_apps::EnsureBrowserContextKeyedServiceFactoriesBuilt();
216   chrome_apps::api::EnsureBrowserContextKeyedServiceFactoriesBuilt();
217   chrome_extensions::EnsureBrowserContextKeyedServiceFactoriesBuilt();
218   extensions::EnsureBrowserContextKeyedServiceFactoriesBuilt();
219 #endif
220 #if defined(OS_CHROMEOS)
221   chromeos::login::SecurityTokenSessionControllerFactory::GetInstance();
222   chromeos::EnsureBrowserContextKeyedServiceFactoriesBuilt();
223 #endif
224 
225   AboutSigninInternalsFactory::GetInstance();
226 #if !defined(OS_ANDROID)
227   AccessContextAuditServiceFactory::GetInstance();
228 #endif
229   AccountConsistencyModeManagerFactory::GetInstance();
230   AccountInvestigatorFactory::GetInstance();
231   AccountReconcilorFactory::GetInstance();
232   AdaptiveQuietNotificationPermissionUiEnabler::Factory::GetInstance();
233 #if defined(OS_CHROMEOS)
234   app_list::AppListSyncableServiceFactory::GetInstance();
235 #endif
236 #if !defined(OS_ANDROID)
237   apps::AppServiceProxyFactory::GetInstance();
238 #endif
239   AutocompleteClassifierFactory::GetInstance();
240   autofill::PersonalDataManagerFactory::GetInstance();
241   autofill::AutofillOfferManagerFactory::GetInstance();
242 #if BUILDFLAG(ENABLE_BACKGROUND_CONTENTS)
243   BackgroundContentsServiceFactory::GetInstance();
244 #endif
245   BookmarkModelFactory::GetInstance();
246   BookmarkUndoServiceFactory::GetInstance();
247   browser_sync::UserEventServiceFactory::GetInstance();
248   BrowsingDataHistoryObserverService::Factory::GetInstance();
249 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
250   CaptivePortalServiceFactory::GetInstance();
251 #endif
252   CertificateReportingServiceFactory::GetInstance();
253 #if !defined(OS_ANDROID)
254   ChromeBrowsingDataLifetimeManagerFactory::GetInstance();
255 #endif
256   ChromeBrowsingDataRemoverDelegateFactory::GetInstance();
257   ChromeSigninClientFactory::GetInstance();
258   ClientHintsFactory::GetInstance();
259 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
260   cloud_print::PrivetNotificationServiceFactory::GetInstance();
261 #endif
262 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) && !defined(OS_CHROMEOS)
263   CloudPrintProxyServiceFactory::GetInstance();
264 #endif
265   ConsentAuditorFactory::GetInstance();
266   CookieSettingsFactory::GetInstance();
267 #if BUILDFLAG(ENABLE_DICE_SUPPORT)
268   DiceWebSigninInterceptorFactory::GetInstance();
269 #endif
270   DomainDiversityReporterFactory::GetInstance();
271   dom_distiller::DomDistillerServiceFactory::GetInstance();
272   DownloadCoreServiceFactory::GetInstance();
273   DownloadServiceFactory::GetInstance();
274 #if defined(OS_ANDROID)
275   explore_sites::ExploreSitesServiceFactory::GetInstance();
276 #endif
277   FaviconServiceFactory::GetInstance();
278   feature_engagement::TrackerFactory::GetInstance();
279 #if !defined(OS_ANDROID)
280   feedback::FeedbackUploaderFactoryChrome::GetInstance();
281 #endif
282   FindBarStateFactory::GetInstance();
283   GAIAInfoUpdateServiceFactory::GetInstance();
284 #if !defined(OS_ANDROID)
285   GlobalErrorServiceFactory::GetInstance();
286 #endif
287   GoogleSearchDomainMixingMetricsEmitterFactory::GetInstance();
288   HistoryServiceFactory::GetInstance();
289   HistoryUiFaviconRequestHandlerFactory::GetInstance();
290   HostContentSettingsMapFactory::GetInstance();
291   HttpsEngagementServiceFactory::GetInstance();
292   IdentityManagerFactory::EnsureFactoryAndDependeeFactoriesBuilt();
293   InMemoryURLIndexFactory::GetInstance();
294 #if !defined(OS_ANDROID)
295   InstantServiceFactory::GetInstance();
296 #endif
297   LanguageModelManagerFactory::GetInstance();
298   if (base::FeatureList::IsEnabled(
299           permissions::features::kOneTimeGeolocationPermission)) {
300     LastTabStandingTrackerFactory::GetInstance();
301   }
302 #if !defined(OS_ANDROID)
303   LoginUIServiceFactory::GetInstance();
304 #endif
305 #if defined(OS_ANDROID)
306   MediaDrmOriginIdManagerFactory::GetInstance();
307 #endif
308   if (MediaEngagementService::IsEnabled())
309     MediaEngagementServiceFactory::GetInstance();
310 #if !defined(OS_ANDROID)
311   media_feeds::MediaFeedsServiceFactory::GetInstance();
312   MediaGalleriesPreferencesFactory::GetInstance();
313 #endif
314   if (base::FeatureList::IsEnabled(media::kUseMediaHistoryStore))
315     media_history::MediaHistoryKeyedServiceFactory::GetInstance();
316   media_router::ChromeLocalPresentationManagerFactory::GetInstance();
317   media_router::ChromeMediaRouterFactory::GetInstance();
318 #if !defined(OS_ANDROID)
319   media_router::MediaRouterUIServiceFactory::GetInstance();
320 #endif
321 #if defined(OS_WIN) || defined(OS_MAC) || \
322     (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_BSD)
323   metrics::DesktopProfileSessionDurationsServiceFactory::GetInstance();
324 #endif
325   ModelTypeStoreServiceFactory::GetInstance();
326 #if defined(OS_CHROMEOS)
327   NearbySharingServiceFactory::GetInstance();
328 #endif
329   NotifierStateTrackerFactory::GetInstance();
330 #if !defined(OS_ANDROID)
331   NTPResourceCacheFactory::GetInstance();
332 #endif
333   PasswordStoreFactory::GetInstance();
334   ProfileProtoDBFactory<
335       persisted_state_db::PersistedStateContentProto>::GetInstance();
336 #if !defined(OS_ANDROID)
337   PinnedTabServiceFactory::GetInstance();
338 #endif
339 #if BUILDFLAG(ENABLE_PLUGINS)
340   PluginPrefsFactory::GetInstance();
341 #endif
342   PrefMetricsService::Factory::GetInstance();
343   PrefsTabHelper::GetServiceInstance();
344   policy::UserCloudPolicyInvalidatorFactory::GetInstance();
345 #if !defined(OS_CHROMEOS)
346   policy::UserPolicySigninServiceFactory::GetInstance();
347 #endif
348   predictors::AutocompleteActionPredictorFactory::GetInstance();
349   predictors::LoadingPredictorFactory::GetInstance();
350   predictors::PredictorDatabaseFactory::GetInstance();
351   prerender::PrerenderLinkManagerFactory::GetInstance();
352   prerender::PrerenderManagerFactory::GetInstance();
353   ProfileSyncServiceFactory::GetInstance();
354 #if !defined(OS_ANDROID)
355   ProfileThemeUpdateServiceFactory::GetInstance();
356 #endif
357   ProtocolHandlerRegistryFactory::GetInstance();
358   if (base::FeatureList::IsEnabled(reading_list::switches::kReadLater)) {
359     ReadingListModelFactory::GetInstance();
360 
361 #if defined(OS_ANDROID)
362     ReadingListManagerFactory::GetInstance();
363 #endif
364   }
365 
366   RendererUpdaterFactory::GetInstance();
367 #if !defined(OS_ANDROID)
368   performance_manager::SiteDataCacheFacadeFactory::GetInstance();
369 #endif
370 #if BUILDFLAG(FULL_SAFE_BROWSING)
371   safe_browsing::AdvancedProtectionStatusManagerFactory::GetInstance();
372 #endif
373   SCTReportingServiceFactory::GetInstance();
374 #if defined(OS_ANDROID)
375   SearchPermissionsService::Factory::GetInstance();
376 #endif
377   send_tab_to_self::SendTabToSelfClientServiceFactory::GetInstance();
378 #if BUILDFLAG(ENABLE_SESSION_SERVICE)
379   SessionServiceFactory::GetInstance();
380 #endif
381   SharingServiceFactory::GetInstance();
382   ShortcutsBackendFactory::GetInstance();
383   SigninProfileAttributesUpdaterFactory::GetInstance();
384   if (SiteEngagementService::IsEnabled())
385     SiteEngagementServiceFactory::GetInstance();
386 #if BUILDFLAG(ENABLE_DICE_SUPPORT)
387   SigninManagerFactory::GetInstance();
388 #endif
389 #if BUILDFLAG(ENABLE_SPELLCHECK)
390   SpellcheckServiceFactory::GetInstance();
391 #endif
392 #if !defined(OS_ANDROID)
393   StorageNotificationServiceFactory::GetInstance();
394 #endif
395   suggestions::SuggestionsServiceFactory::GetInstance();
396 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
397   SupervisedUserServiceFactory::GetInstance();
398 #endif
399   TabRestoreServiceFactory::GetInstance();
400   TemplateURLFetcherFactory::GetInstance();
401   TemplateURLServiceFactory::GetInstance();
402 #if !defined(OS_ANDROID)
403   ThemeServiceFactory::GetInstance();
404 #endif
405 #if defined(OS_ANDROID)
406   thin_webview::android::ChromeThinWebViewInitializer::Initialize();
407 #endif
408 #if BUILDFLAG(ENABLE_EXTENSIONS)
409   ToolbarActionsModelFactory::GetInstance();
410 #endif
411   TopSitesFactory::GetInstance();
412   translate::TranslateRankerFactory::GetInstance();
413 #if defined(OS_WIN)
414   TriggeredProfileResetterFactory::GetInstance();
415 #endif
416   UnifiedConsentServiceFactory::GetInstance();
417   UrlLanguageHistogramFactory::GetInstance();
418 #if !defined(OS_ANDROID)
419   UsbChooserContextFactory::GetInstance();
420 #endif
421 #if BUILDFLAG(ENABLE_EXTENSIONS)
422   web_app::WebAppMetricsFactory::GetInstance();
423   web_app::WebAppProviderFactory::GetInstance();
424 #endif
425   WebDataServiceFactory::GetInstance();
426   webrtc_event_logging::WebRtcEventLogManagerKeyedServiceFactory::GetInstance();
427 }
428 
PreProfileInit()429 void ChromeBrowserMainExtraPartsProfiles::PreProfileInit() {
430   EnsureBrowserContextKeyedServiceFactoriesBuilt();
431 }
432