profile_impl.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
16462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org// Copyright (c) 2012 The Chromium Authors. All rights reserved.
26462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org// Use of this source code is governed by a BSD-style license that can be
36462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org// found in the LICENSE file.
46462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org
56462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org// This class gathers state related to a single user profile.
66462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org
76462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#ifndef CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
86462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#define CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
96462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org
106462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include <string>
116462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org
126462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "base/files/file_path.h"
136462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "base/gtest_prod_util.h"
146462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "base/memory/ref_counted.h"
156462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "base/memory/scoped_ptr.h"
166462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "base/prefs/pref_change_registrar.h"
176462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "base/timer/timer.h"
186462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "chrome/browser/profiles/profile.h"
196462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "chrome/browser/profiles/profile_impl_io_data.h"
206462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "content/public/browser/content_browser_client.h"
216462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#include "content/public/browser/host_zoom_map.h"
226462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org
236462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass NetPrefObserver;
246462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass PrefService;
256462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass PrefServiceSyncable;
266462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass ShortcutsBackend;
276462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass SSLConfigServiceManager;
286462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass TrackedPreferenceValidationDelegate;
296462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org
306462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#if defined(OS_CHROMEOS)
316462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgnamespace chromeos {
326462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass KioskTest;
336462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass LocaleChangeGuard;
346462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass Preferences;
356462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass SupervisedUserTestBase;
366462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org}
376462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org#endif
386462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org
396462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgnamespace base {
406462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.orgclass SequencedTaskRunner;
416462c58fa123bb89baf1ec4b7538d8f2c682dc8bbashi@chromium.org}
42
43namespace data_reduction_proxy {
44class DataReductionProxyParams;
45}
46
47class DataReductionProxyChromeSettings;
48
49namespace domain_reliability {
50class DomainReliabilityMonitor;
51}
52
53namespace extensions {
54class ExtensionSystem;
55}
56
57namespace policy {
58class CloudPolicyManager;
59class ProfilePolicyConnector;
60class SchemaRegistryService;
61}
62
63namespace user_prefs {
64class refRegistrySyncable;
65}
66
67// The default profile implementation.
68class ProfileImpl : public Profile {
69 public:
70  // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
71  static const char* const kPrefExitTypeNormal;
72
73  virtual ~ProfileImpl();
74
75  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
76
77  // content::BrowserContext implementation:
78  virtual base::FilePath GetPath() const OVERRIDE;
79  virtual content::DownloadManagerDelegate*
80      GetDownloadManagerDelegate() OVERRIDE;
81  virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
82  virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
83      int renderer_child_id) OVERRIDE;
84  virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
85  virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
86      int renderer_child_id) OVERRIDE;
87  virtual net::URLRequestContextGetter*
88      GetMediaRequestContextForStoragePartition(
89          const base::FilePath& partition_path,
90          bool in_memory) OVERRIDE;
91  virtual content::ResourceContext* GetResourceContext() OVERRIDE;
92  virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE;
93  virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
94  virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE;
95  virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() OVERRIDE;
96
97  // Profile implementation:
98  virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE;
99  // Note that this implementation returns the Google-services username, if any,
100  // not the Chrome user's display name.
101  virtual std::string GetProfileName() OVERRIDE;
102  virtual ProfileType GetProfileType() const OVERRIDE;
103  virtual bool IsOffTheRecord() const OVERRIDE;
104  virtual Profile* GetOffTheRecordProfile() OVERRIDE;
105  virtual void DestroyOffTheRecordProfile() OVERRIDE;
106  virtual bool HasOffTheRecordProfile() OVERRIDE;
107  virtual Profile* GetOriginalProfile() OVERRIDE;
108  virtual bool IsSupervised() OVERRIDE;
109  virtual history::TopSites* GetTopSites() OVERRIDE;
110  virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE;
111  virtual ExtensionSpecialStoragePolicy*
112      GetExtensionSpecialStoragePolicy() OVERRIDE;
113  virtual PrefService* GetPrefs() OVERRIDE;
114  virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
115  virtual net::URLRequestContextGetter*
116      GetRequestContextForExtensions() OVERRIDE;
117  virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE;
118  virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE;
119  virtual bool IsSameProfile(Profile* profile) OVERRIDE;
120  virtual base::Time GetStartTime() const OVERRIDE;
121  virtual net::URLRequestContextGetter* CreateRequestContext(
122      content::ProtocolHandlerMap* protocol_handlers,
123      content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE;
124  virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
125      const base::FilePath& partition_path,
126      bool in_memory,
127      content::ProtocolHandlerMap* protocol_handlers,
128      content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE;
129  virtual base::FilePath last_selected_directory() OVERRIDE;
130  virtual void set_last_selected_directory(const base::FilePath& path) OVERRIDE;
131  virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE;
132  virtual DevToolsNetworkController* GetDevToolsNetworkController() OVERRIDE;
133  virtual void ClearNetworkingHistorySince(
134      base::Time time,
135      const base::Closure& completion) OVERRIDE;
136  virtual GURL GetHomePage() OVERRIDE;
137  virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
138  virtual void SetExitType(ExitType exit_type) OVERRIDE;
139  virtual ExitType GetLastSessionExitType() OVERRIDE;
140
141#if defined(OS_CHROMEOS)
142  virtual void ChangeAppLocale(const std::string& locale,
143                               AppLocaleChangedVia) OVERRIDE;
144  virtual void OnLogin() OVERRIDE;
145  virtual void InitChromeOSPreferences() OVERRIDE;
146#endif  // defined(OS_CHROMEOS)
147
148  virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE;
149
150 private:
151#if defined(OS_CHROMEOS)
152  friend class chromeos::KioskTest;
153  friend class chromeos::SupervisedUserTestBase;
154#endif
155  friend class Profile;
156  friend class BetterSessionRestoreCrashTest;
157  FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
158                           ProfilesLaunchedAfterCrash);
159  FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, DISABLED_ProfileReadmeCreated);
160  FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest,
161                           ProfileDeletedBeforeReadmeCreated);
162
163  // Delay, in milliseconds, before README file is created for a new profile.
164  // This is non-const for testing purposes.
165  static int create_readme_delay_ms;
166
167  ProfileImpl(const base::FilePath& path,
168              Delegate* delegate,
169              CreateMode create_mode,
170              base::SequencedTaskRunner* sequenced_task_runner);
171
172  // Does final initialization. Should be called after prefs were loaded.
173  void DoFinalInit();
174
175  void InitHostZoomMap();
176
177  void OnDefaultZoomLevelChanged();
178  void OnZoomLevelChanged(
179      const content::HostZoomMap::ZoomLevelChange& change);
180
181  // Does final prefs initialization and calls Init().
182  void OnPrefsLoaded(bool success);
183
184#if defined(ENABLE_SESSION_SERVICE)
185  void StopCreateSessionServiceTimer();
186
187  void EnsureSessionServiceCreated();
188#endif
189
190
191  void EnsureRequestContextCreated() {
192    GetRequestContext();
193  }
194
195  // Updates the ProfileInfoCache with data from this profile.
196  void UpdateProfileUserNameCache();
197  void UpdateProfileSupervisedUserIdCache();
198  void UpdateProfileNameCache();
199  void UpdateProfileAvatarCache();
200  void UpdateProfileIsEphemeralCache();
201
202  void GetCacheParameters(bool is_media_context,
203                          base::FilePath* cache_path,
204                          int* max_size);
205
206  PrefProxyConfigTracker* CreateProxyConfigTracker();
207
208  scoped_ptr<domain_reliability::DomainReliabilityMonitor>
209      CreateDomainReliabilityMonitor();
210
211  scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
212  PrefChangeRegistrar pref_change_registrar_;
213
214  base::FilePath path_;
215  base::FilePath base_cache_path_;
216
217  // !!! BIG HONKING WARNING !!!
218  //  The order of the members below is important. Do not change it unless
219  //  you know what you're doing. Also, if adding a new member here make sure
220  //  that the declaration occurs AFTER things it depends on as destruction
221  //  happens in reverse order of declaration.
222
223  // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
224  // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
225// This can be removed once |prefs_| becomes a KeyedService too.
226// |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
227// which depends on |schema_registry_service_|.
228#if defined(ENABLE_CONFIGURATION_POLICY)
229  scoped_ptr<policy::SchemaRegistryService> schema_registry_service_;
230  scoped_ptr<policy::CloudPolicyManager> cloud_policy_manager_;
231#endif
232  scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
233
234  // Keep |pref_validation_delegate_| above |prefs_| so that the former outlives
235  // the latter.
236  scoped_ptr<TrackedPreferenceValidationDelegate> pref_validation_delegate_;
237
238  // Keep |prefs_| on top for destruction order because |extension_prefs_|,
239  // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
240  // shall be destructed first.
241  scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
242  scoped_ptr<PrefServiceSyncable> prefs_;
243  scoped_ptr<PrefServiceSyncable> otr_prefs_;
244  ProfileImplIOData::Handle io_data_;
245#if defined(ENABLE_EXTENSIONS)
246  scoped_refptr<ExtensionSpecialStoragePolicy>
247      extension_special_storage_policy_;
248#endif
249  scoped_ptr<NetPrefObserver> net_pref_observer_;
250  scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
251  scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
252  scoped_refptr<ShortcutsBackend> shortcuts_backend_;
253
254  // Exit type the last time the profile was opened. This is set only once from
255  // prefs.
256  ExitType last_session_exit_type_;
257
258#if defined(ENABLE_SESSION_SERVICE)
259  base::OneShotTimer<ProfileImpl> create_session_service_timer_;
260#endif
261
262  scoped_ptr<Profile> off_the_record_profile_;
263
264  // See GetStartTime for details.
265  base::Time start_time_;
266
267  scoped_refptr<history::TopSites> top_sites_;  // For history and thumbnails.
268
269#if defined(OS_CHROMEOS)
270  scoped_ptr<chromeos::Preferences> chromeos_preferences_;
271
272  scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_;
273
274  bool is_login_profile_;
275#endif
276
277  scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
278
279  // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
280  //
281  // Instead, make your Service/Manager/whatever object you're hanging off the
282  // Profile use our new BrowserContextKeyedServiceFactory system instead.
283  // You can find the design document here:
284  //
285  //   https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
286  //
287  // and you can read the raw headers here:
288  //
289  // components/keyed_service/content/browser_context_dependency_manager.*
290  // components/keyed_service/core/keyed_service.h
291  // components/keyed_service/content/browser_context_keyed_service_factory.*
292
293  Profile::Delegate* delegate_;
294
295  chrome_browser_net::Predictor* predictor_;
296
297  DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
298};
299
300#endif  // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
301