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 "chrome/browser/autocomplete/shortcuts_backend_factory.h"
8#include "chrome/browser/autofill/personal_data_manager_factory.h"
9#include "chrome/browser/background/background_contents_service_factory.h"
10#include "chrome/browser/bookmarks/bookmark_model_factory.h"
11#include "chrome/browser/chrome_browser_main.h"
12#include "chrome/browser/content_settings/cookie_settings.h"
13#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
14#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
15#include "chrome/browser/domain_reliability/service_factory.h"
16#include "chrome/browser/download/download_service_factory.h"
17#include "chrome/browser/extensions/extension_management.h"
18#include "chrome/browser/favicon/favicon_service_factory.h"
19#include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
20#include "chrome/browser/google/google_url_tracker_factory.h"
21#include "chrome/browser/history/history_service_factory.h"
22#include "chrome/browser/invalidation/profile_invalidation_provider_factory.h"
23#include "chrome/browser/media_galleries/media_galleries_preferences_factory.h"
24#include "chrome/browser/notifications/desktop_notification_service_factory.h"
25#include "chrome/browser/password_manager/password_store_factory.h"
26#include "chrome/browser/plugins/plugin_prefs_factory.h"
27#include "chrome/browser/policy/profile_policy_connector_factory.h"
28#include "chrome/browser/predictors/autocomplete_action_predictor_factory.h"
29#include "chrome/browser/predictors/predictor_database_factory.h"
30#include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
31#include "chrome/browser/prerender/prerender_link_manager_factory.h"
32#include "chrome/browser/prerender/prerender_manager_factory.h"
33#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
34#include "chrome/browser/profiles/gaia_info_update_service_factory.h"
35#include "chrome/browser/search/instant_service_factory.h"
36#include "chrome/browser/search/suggestions/suggestions_service_factory.h"
37#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
38#include "chrome/browser/search_engines/template_url_service_factory.h"
39#include "chrome/browser/sessions/session_service_factory.h"
40#include "chrome/browser/sessions/tab_restore_service_factory.h"
41#include "chrome/browser/signin/about_signin_internals_factory.h"
42#include "chrome/browser/signin/account_tracker_service_factory.h"
43#include "chrome/browser/signin/signin_manager_factory.h"
44#include "chrome/browser/sync/profile_sync_service_factory.h"
45#include "chrome/browser/themes/theme_service_factory.h"
46#include "chrome/browser/thumbnails/thumbnail_service_factory.h"
47#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
48#include "chrome/browser/ui/find_bar/find_bar_state_factory.h"
49#include "chrome/browser/ui/global_error/global_error_service_factory.h"
50#include "chrome/browser/ui/tabs/pinned_tab_service_factory.h"
51#include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
52#include "chrome/browser/undo/bookmark_undo_service_factory.h"
53#include "chrome/browser/webdata/web_data_service_factory.h"
54
55#if defined(ENABLE_EXTENSIONS)
56#include "apps/browser_context_keyed_service_factories.h"
57#include "chrome/browser/apps/ephemeral_app_service_factory.h"
58#include "chrome/browser/apps/shortcut_manager_factory.h"
59#include "chrome/browser/extensions/browser_context_keyed_service_factories.h"
60#include "chrome/browser/search/hotword_service_factory.h"
61#include "chrome/browser/signin/easy_unlock_service_factory.h"
62#include "extensions/browser/browser_context_keyed_service_factories.h"
63#endif
64
65#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
66#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
67#endif
68
69#if defined(ENABLE_CONFIGURATION_POLICY)
70#include "chrome/browser/policy/cloud/policy_header_service_factory.h"
71#include "chrome/browser/policy/cloud/user_cloud_policy_invalidator_factory.h"
72#include "chrome/browser/policy/schema_registry_service_factory.h"
73#if defined(OS_CHROMEOS)
74#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h"
75#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
76#include "chrome/browser/chromeos/policy/recommendation_restorer_factory.h"
77#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h"
78#include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder_factory.h"
79#include "chrome/browser/chromeos/policy/user_network_configuration_updater_factory.h"
80#else
81#include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
82#if !defined(OS_IOS)
83#include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h"
84#endif
85#endif
86#endif
87
88#if defined(ENABLE_MANAGED_USERS)
89#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
90#include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h"
91#if defined(OS_CHROMEOS)
92#include "chrome/browser/supervised_user/chromeos/manager_password_service_factory.h"
93#include "chrome/browser/supervised_user/chromeos/supervised_user_password_service_factory.h"
94#endif
95#endif
96
97#if defined(USE_AURA)
98#include "chrome/browser/ui/gesture_prefs_observer_factory_aura.h"
99#endif
100
101#if defined(OS_ANDROID)
102#include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
103#else
104#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_factory.h"
105#include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
106#endif
107
108#if defined(ENABLE_SPELLCHECK)
109#include "chrome/browser/spellchecker/spellcheck_factory.h"
110#endif
111
112#if defined(ENABLE_SERVICE_DISCOVERY)
113#include "chrome/browser/local_discovery/privet_notifications_factory.h"
114#endif
115
116namespace chrome {
117
118void AddProfilesExtraParts(ChromeBrowserMainParts* main_parts) {
119  main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiles());
120}
121
122}  // namespace chrome
123
124ChromeBrowserMainExtraPartsProfiles::ChromeBrowserMainExtraPartsProfiles() {
125}
126
127ChromeBrowserMainExtraPartsProfiles::~ChromeBrowserMainExtraPartsProfiles() {
128}
129
130// This method gets the instance of each ServiceFactory. We do this so that
131// each ServiceFactory initializes itself and registers its dependencies with
132// the global PreferenceDependencyManager. We need to have a complete
133// dependency graph when we create a profile so we can dispatch the profile
134// creation message to the services that want to create their services at
135// profile creation time.
136//
137// TODO(erg): This needs to be something else. I don't think putting every
138// FooServiceFactory here will scale or is desirable long term.
139//
140// static
141void ChromeBrowserMainExtraPartsProfiles::
142EnsureBrowserContextKeyedServiceFactoriesBuilt() {
143#if defined(ENABLE_EXTENSIONS)
144  apps::EnsureBrowserContextKeyedServiceFactoriesBuilt();
145  extensions::EnsureBrowserContextKeyedServiceFactoriesBuilt();
146  extensions::ExtensionManagementFactory::GetInstance();
147  chrome_extensions::EnsureBrowserContextKeyedServiceFactoriesBuilt();
148  AppShortcutManagerFactory::GetInstance();
149  EphemeralAppServiceFactory::GetInstance();
150#endif
151
152#if defined(ENABLE_APP_LIST)
153  app_list::AppListSyncableServiceFactory::GetInstance();
154#endif
155
156  AboutSigninInternalsFactory::GetInstance();
157  AccountTrackerServiceFactory::GetInstance();
158  autofill::PersonalDataManagerFactory::GetInstance();
159#if !defined(OS_ANDROID)
160  AutomaticProfileResetterFactory::GetInstance();
161#endif
162#if defined(ENABLE_BACKGROUND)
163  BackgroundContentsServiceFactory::GetInstance();
164#endif
165  BookmarkModelFactory::GetInstance();
166  BookmarkUndoServiceFactory::GetInstance();
167#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
168  CaptivePortalServiceFactory::GetInstance();
169#endif
170  GeolocationPermissionContextFactory::GetInstance();
171#if defined(OS_ANDROID)
172  ProtectedMediaIdentifierPermissionContextFactory::GetInstance();
173#endif
174#if defined(ENABLE_FULL_PRINTING)
175  CloudPrintProxyServiceFactory::GetInstance();
176#endif
177  CookieSettings::Factory::GetInstance();
178#if defined(ENABLE_NOTIFICATIONS)
179  DesktopNotificationServiceFactory::GetInstance();
180#endif
181  dom_distiller::DomDistillerServiceFactory::GetInstance();
182  domain_reliability::DomainReliabilityServiceFactory::GetInstance();
183  DownloadServiceFactory::GetInstance();
184#if defined(ENABLE_EXTENSIONS)
185  EasyUnlockServiceFactory::GetInstance();
186#endif
187  FaviconServiceFactory::GetInstance();
188  FindBarStateFactory::GetInstance();
189  GAIAInfoUpdateServiceFactory::GetInstance();
190#if defined(USE_AURA)
191  GesturePrefsObserverFactoryAura::GetInstance();
192#endif
193  GlobalErrorServiceFactory::GetInstance();
194  GoogleURLTrackerFactory::GetInstance();
195  HistoryServiceFactory::GetInstance();
196#if defined(ENABLE_EXTENSIONS)
197  HotwordServiceFactory::GetInstance();
198#endif
199  invalidation::ProfileInvalidationProviderFactory::GetInstance();
200  InstantServiceFactory::GetInstance();
201#if defined(ENABLE_SERVICE_DISCOVERY)
202  local_discovery::PrivetNotificationServiceFactory::GetInstance();
203#endif
204#if defined(ENABLE_MANAGED_USERS)
205#if defined(OS_CHROMEOS)
206  chromeos::SupervisedUserPasswordServiceFactory::GetInstance();
207  chromeos::ManagerPasswordServiceFactory::GetInstance();
208#endif
209  SupervisedUserServiceFactory::GetInstance();
210  SupervisedUserSyncServiceFactory::GetInstance();
211#endif
212#if !defined(OS_ANDROID)
213  MediaGalleriesPreferencesFactory::GetInstance();
214  notifier::ChromeNotifierServiceFactory::GetInstance();
215  NTPResourceCacheFactory::GetInstance();
216#endif
217  PasswordStoreFactory::GetInstance();
218#if !defined(OS_ANDROID)
219  PinnedTabServiceFactory::GetInstance();
220#endif
221#if defined(ENABLE_PLUGINS)
222  PluginPrefsFactory::GetInstance();
223#endif
224  policy::ProfilePolicyConnectorFactory::GetInstance();
225#if defined(ENABLE_CONFIGURATION_POLICY)
226#if defined(OS_CHROMEOS)
227  chromeos::OwnerSettingsServiceChromeOSFactory::GetInstance();
228  policy::PolicyCertServiceFactory::GetInstance();
229  policy::RecommendationRestorerFactory::GetInstance();
230  policy::UserCloudPolicyManagerFactoryChromeOS::GetInstance();
231  policy::UserCloudPolicyTokenForwarderFactory::GetInstance();
232  policy::UserNetworkConfigurationUpdaterFactory::GetInstance();
233#else
234  policy::UserCloudPolicyManagerFactory::GetInstance();
235#if !defined(OS_IOS)
236  policy::UserPolicySigninServiceFactory::GetInstance();
237#endif
238#endif
239  policy::PolicyHeaderServiceFactory::GetInstance();
240  policy::SchemaRegistryServiceFactory::GetInstance();
241  policy::UserCloudPolicyInvalidatorFactory::GetInstance();
242#endif
243  predictors::AutocompleteActionPredictorFactory::GetInstance();
244  predictors::PredictorDatabaseFactory::GetInstance();
245  predictors::ResourcePrefetchPredictorFactory::GetInstance();
246  prerender::PrerenderManagerFactory::GetInstance();
247  prerender::PrerenderLinkManagerFactory::GetInstance();
248  ProfileSyncServiceFactory::GetInstance();
249  ProtocolHandlerRegistryFactory::GetInstance();
250#if defined(ENABLE_SESSION_SERVICE)
251  SessionServiceFactory::GetInstance();
252#endif
253  ShortcutsBackendFactory::GetInstance();
254  SigninManagerFactory::GetInstance();
255#if defined(ENABLE_SPELLCHECK)
256  SpellcheckServiceFactory::GetInstance();
257#endif
258  suggestions::SuggestionsServiceFactory::GetInstance();
259  ThumbnailServiceFactory::GetInstance();
260  TabRestoreServiceFactory::GetInstance();
261  TemplateURLFetcherFactory::GetInstance();
262  TemplateURLServiceFactory::GetInstance();
263#if defined(ENABLE_THEMES)
264  ThemeServiceFactory::GetInstance();
265#endif
266  WebDataServiceFactory::GetInstance();
267}
268
269void ChromeBrowserMainExtraPartsProfiles::PreProfileInit() {
270  EnsureBrowserContextKeyedServiceFactoriesBuilt();
271}
272