1// Copyright (c) 2011 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// This class gathers state related to a single user profile.
6
7#ifndef CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
8#define CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
9#pragma once
10
11#include "base/file_path.h"
12#include "base/memory/ref_counted.h"
13#include "base/memory/scoped_ptr.h"
14#include "base/timer.h"
15#include "chrome/browser/prefs/pref_change_registrar.h"
16#include "chrome/browser/profiles/profile.h"
17#include "chrome/browser/profiles/profile_impl_io_data.h"
18#include "chrome/browser/spellcheck_host_observer.h"
19#include "content/common/notification_observer.h"
20#include "content/common/notification_registrar.h"
21
22class ExtensionPrefs;
23class ExtensionPrefValueMap;
24class PrefService;
25
26#if defined(OS_CHROMEOS)
27namespace chromeos {
28class EnterpriseExtensionObserver;
29class LocaleChangeGuard;
30class Preferences;
31}
32#endif
33
34class NetPrefObserver;
35
36// The default profile implementation.
37class ProfileImpl : public Profile,
38                    public SpellCheckHostObserver,
39                    public NotificationObserver,
40                    public PrefService::Delegate {
41 public:
42  virtual ~ProfileImpl();
43
44  static void RegisterUserPrefs(PrefService* prefs);
45
46  // Profile implementation.
47  virtual ProfileId GetRuntimeId();
48  virtual FilePath GetPath();
49  virtual bool IsOffTheRecord();
50  virtual Profile* GetOffTheRecordProfile();
51  virtual void DestroyOffTheRecordProfile();
52  virtual bool HasOffTheRecordProfile();
53  virtual Profile* GetOriginalProfile();
54  virtual ChromeAppCacheService* GetAppCacheService();
55  virtual webkit_database::DatabaseTracker* GetDatabaseTracker();
56  virtual history::TopSites* GetTopSites();
57  virtual history::TopSites* GetTopSitesWithoutCreating();
58  virtual VisitedLinkMaster* GetVisitedLinkMaster();
59  virtual UserScriptMaster* GetUserScriptMaster();
60  virtual SSLHostState* GetSSLHostState();
61  virtual net::TransportSecurityState* GetTransportSecurityState();
62  virtual ExtensionService* GetExtensionService();
63  virtual ExtensionDevToolsManager* GetExtensionDevToolsManager();
64  virtual ExtensionProcessManager* GetExtensionProcessManager();
65  virtual ExtensionMessageService* GetExtensionMessageService();
66  virtual ExtensionEventRouter* GetExtensionEventRouter();
67  virtual ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy();
68  virtual FaviconService* GetFaviconService(ServiceAccessType sat);
69  virtual HistoryService* GetHistoryService(ServiceAccessType sat);
70  virtual HistoryService* GetHistoryServiceWithoutCreating();
71  virtual AutocompleteClassifier* GetAutocompleteClassifier();
72  virtual WebDataService* GetWebDataService(ServiceAccessType sat);
73  virtual WebDataService* GetWebDataServiceWithoutCreating();
74  virtual PasswordStore* GetPasswordStore(ServiceAccessType sat);
75  virtual PrefService* GetPrefs();
76  virtual PrefService* GetOffTheRecordPrefs();
77  virtual TemplateURLModel* GetTemplateURLModel();
78  virtual TemplateURLFetcher* GetTemplateURLFetcher();
79  virtual DownloadManager* GetDownloadManager();
80  virtual PersonalDataManager* GetPersonalDataManager();
81  virtual fileapi::FileSystemContext* GetFileSystemContext();
82  virtual bool HasCreatedDownloadManager() const;
83  virtual net::URLRequestContextGetter* GetRequestContext();
84  virtual net::URLRequestContextGetter* GetRequestContextForPossibleApp(
85      const Extension* installed_app);
86  virtual net::URLRequestContextGetter* GetRequestContextForMedia();
87  virtual net::URLRequestContextGetter* GetRequestContextForExtensions();
88  virtual net::URLRequestContextGetter* GetRequestContextForIsolatedApp(
89      const std::string& app_id);
90  virtual const content::ResourceContext& GetResourceContext();
91  virtual void RegisterExtensionWithRequestContexts(const Extension* extension);
92  virtual void UnregisterExtensionWithRequestContexts(
93      const std::string& extension_id,
94      const UnloadedExtensionInfo::Reason reason);
95  virtual net::SSLConfigService* GetSSLConfigService();
96  virtual HostContentSettingsMap* GetHostContentSettingsMap();
97  virtual HostZoomMap* GetHostZoomMap();
98  virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap();
99  virtual GeolocationPermissionContext* GetGeolocationPermissionContext();
100  virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher();
101  virtual FindBarState* GetFindBarState();
102  virtual SessionService* GetSessionService();
103  virtual void ShutdownSessionService();
104  virtual bool HasSessionService() const;
105  virtual bool HasProfileSyncService() const;
106  virtual bool DidLastSessionExitCleanly();
107  virtual BookmarkModel* GetBookmarkModel();
108  virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry();
109  virtual bool IsSameProfile(Profile* profile);
110  virtual base::Time GetStartTime() const;
111  virtual TabRestoreService* GetTabRestoreService();
112  virtual void ResetTabRestoreService();
113  virtual SpellCheckHost* GetSpellCheckHost();
114  virtual void ReinitializeSpellCheckHost(bool force);
115  virtual WebKitContext* GetWebKitContext();
116  virtual StatusTray* GetStatusTray();
117  virtual void MarkAsCleanShutdown();
118  virtual void InitExtensions(bool extensions_enabled);
119  virtual void InitPromoResources();
120  virtual void InitRegisteredProtocolHandlers();
121  virtual NTPResourceCache* GetNTPResourceCache();
122  virtual FilePath last_selected_directory();
123  virtual void set_last_selected_directory(const FilePath& path);
124  virtual ProfileSyncService* GetProfileSyncService();
125  virtual ProfileSyncService* GetProfileSyncService(
126      const std::string& cros_user);
127  virtual TokenService* GetTokenService();
128  void InitSyncService(const std::string& cros_user);
129  virtual CloudPrintProxyService* GetCloudPrintProxyService();
130  void InitCloudPrintProxyService();
131  virtual ChromeBlobStorageContext* GetBlobStorageContext();
132  virtual ExtensionInfoMap* GetExtensionInfoMap();
133  virtual PromoCounter* GetInstantPromoCounter();
134  virtual BrowserSignin* GetBrowserSignin();
135  virtual policy::ProfilePolicyConnector* GetPolicyConnector();
136  virtual ChromeURLDataManager* GetChromeURLDataManager();
137
138#if defined(OS_CHROMEOS)
139  virtual void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia);
140  virtual void OnLogin();
141  virtual void SetupChromeOSEnterpriseExtensionObserver();
142  virtual void InitChromeOSPreferences();
143#endif  // defined(OS_CHROMEOS)
144
145  virtual PrefProxyConfigTracker* GetProxyConfigTracker();
146  virtual prerender::PrerenderManager* GetPrerenderManager();
147
148  // NotificationObserver implementation.
149  virtual void Observe(NotificationType type,
150                       const NotificationSource& source,
151                       const NotificationDetails& details);
152
153  // SpellCheckHostObserver implementation.
154  virtual void SpellCheckHostInitialized();
155
156 private:
157  friend class Profile;
158
159  ProfileImpl(const FilePath& path,
160              Profile::Delegate* delegate);
161
162  // Does final initialization. Should be called after prefs were loaded.
163  void DoFinalInit();
164
165  // PrefService::Delegate implementation. Does final prefs initialization and
166  // calls Init().
167  virtual void OnPrefsLoaded(PrefService* prefs, bool success);
168
169  void CreateWebDataService();
170  FilePath GetPrefFilePath();
171
172  void CreatePasswordStore();
173
174  void StopCreateSessionServiceTimer();
175
176  void EnsureRequestContextCreated() {
177    GetRequestContext();
178  }
179
180  void EnsureSessionServiceCreated() {
181    GetSessionService();
182  }
183
184  void RegisterComponentExtensions();
185
186  ExtensionPrefValueMap* GetExtensionPrefValueMap();
187
188  NotificationRegistrar registrar_;
189  PrefChangeRegistrar pref_change_registrar_;
190
191  FilePath path_;
192  FilePath base_cache_path_;
193  scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_;
194  // Keep |prefs_| on top for destruction order because |extension_prefs_|,
195  // |net_pref_observer_|, |web_resource_service_|, and |io_data_| store
196  // pointers to |prefs_| and shall be destructed first.
197  scoped_ptr<PrefService> prefs_;
198  scoped_ptr<PrefService> otr_prefs_;
199  scoped_ptr<VisitedLinkEventListener> visited_link_event_listener_;
200  scoped_ptr<VisitedLinkMaster> visited_link_master_;
201  // Keep extension_prefs_ on top of extensions_service_ because the latter
202  // maintains a pointer to the first and shall be destructed first.
203  scoped_ptr<ExtensionPrefs> extension_prefs_;
204  scoped_refptr<ExtensionService> extensions_service_;
205  scoped_refptr<UserScriptMaster> user_script_master_;
206  scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_;
207  scoped_ptr<ExtensionProcessManager> extension_process_manager_;
208  scoped_refptr<ExtensionMessageService> extension_message_service_;
209  scoped_ptr<ExtensionEventRouter> extension_event_router_;
210  scoped_refptr<ExtensionSpecialStoragePolicy>
211      extension_special_storage_policy_;
212  scoped_ptr<SSLHostState> ssl_host_state_;
213  scoped_refptr<net::TransportSecurityState>
214      transport_security_state_;
215  scoped_refptr<TransportSecurityPersister>
216      transport_security_persister_;
217  scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
218  scoped_refptr<prerender::PrerenderManager> prerender_manager_;
219  scoped_ptr<NetPrefObserver> net_pref_observer_;
220  scoped_ptr<TemplateURLFetcher> template_url_fetcher_;
221  scoped_ptr<TemplateURLModel> template_url_model_;
222  scoped_ptr<BookmarkModel> bookmark_bar_model_;
223  scoped_refptr<PromoResourceService> promo_resource_service_;
224  scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_;
225  scoped_ptr<NTPResourceCache> ntp_resource_cache_;
226
227  scoped_ptr<TokenService> token_service_;
228  scoped_ptr<ProfileSyncFactory> profile_sync_factory_;
229  scoped_ptr<ProfileSyncService> sync_service_;
230  scoped_refptr<CloudPrintProxyService> cloud_print_proxy_service_;
231
232  ProfileImplIOData::Handle io_data_;
233
234  scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
235
236  scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
237  scoped_refptr<HostZoomMap> host_zoom_map_;
238  scoped_refptr<GeolocationContentSettingsMap>
239      geolocation_content_settings_map_;
240  scoped_refptr<GeolocationPermissionContext>
241      geolocation_permission_context_;
242  scoped_refptr<UserStyleSheetWatcher> user_style_sheet_watcher_;
243  scoped_ptr<FindBarState> find_bar_state_;
244  scoped_refptr<DownloadManager> download_manager_;
245  scoped_refptr<HistoryService> history_service_;
246  scoped_refptr<FaviconService> favicon_service_;
247  scoped_ptr<AutocompleteClassifier> autocomplete_classifier_;
248  scoped_refptr<WebDataService> web_data_service_;
249  scoped_refptr<PasswordStore> password_store_;
250  scoped_refptr<SessionService> session_service_;
251  scoped_refptr<WebKitContext> webkit_context_;
252  scoped_ptr<StatusTray> status_tray_;
253  scoped_refptr<PersonalDataManager> personal_data_manager_;
254  scoped_refptr<fileapi::FileSystemContext> file_system_context_;
255  scoped_ptr<BrowserSignin> browser_signin_;
256  bool history_service_created_;
257  bool favicon_service_created_;
258  bool created_web_data_service_;
259  bool created_password_store_;
260  bool created_download_manager_;
261  bool clear_local_state_on_exit_;
262  // Whether or not the last session exited cleanly. This is set only once.
263  bool last_session_exited_cleanly_;
264
265  base::OneShotTimer<ProfileImpl> create_session_service_timer_;
266
267  scoped_ptr<Profile> off_the_record_profile_;
268
269  // See GetStartTime for details.
270  base::Time start_time_;
271
272  scoped_refptr<TabRestoreService> tab_restore_service_;
273
274  scoped_refptr<SpellCheckHost> spellcheck_host_;
275
276  // Indicates whether |spellcheck_host_| has told us initialization is
277  // finished.
278  bool spellcheck_host_ready_;
279
280#if defined(OS_WIN)
281  bool checked_instant_promo_;
282  scoped_ptr<PromoCounter> instant_promo_counter_;
283#endif
284
285  // Set to true when ShutdownSessionService is invoked. If true
286  // GetSessionService won't recreate the SessionService.
287  bool shutdown_session_service_;
288
289  // The AppCacheService for this profile, shared by all requests contexts
290  // associated with this profile. Should only be used on the IO thread.
291  scoped_refptr<ChromeAppCacheService> appcache_service_;
292
293  // The main database tracker for this profile.
294  // Should be used only on the file thread.
295  scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
296
297  scoped_refptr<history::TopSites> top_sites_;  // For history and thumbnails.
298
299  scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
300
301  scoped_refptr<ExtensionInfoMap> extension_info_map_;
302
303#if defined(OS_CHROMEOS)
304  scoped_ptr<chromeos::Preferences> chromeos_preferences_;
305
306  scoped_ptr<chromeos::EnterpriseExtensionObserver>
307      chromeos_enterprise_extension_observer_;
308
309  scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_;
310#endif
311
312  scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
313
314  scoped_ptr<ChromeURLDataManager> chrome_url_data_manager_;
315
316  Profile::Delegate* delegate_;
317
318  DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
319};
320
321#endif  // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
322