1 // Copyright (c) 2012 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.
5 // This class gathers state related to a single user profile.
7 #ifndef CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
8 #define CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
12 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/prefs/pref_change_registrar.h"
17 #include "base/timer/timer.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_impl_io_data.h"
20 #include "content/public/browser/content_browser_client.h"
21 #include "content/public/browser/host_zoom_map.h"
23 class NetPrefObserver;
25 class PrefServiceSyncable;
26 class SSLConfigServiceManager;
28 #if defined(OS_CHROMEOS)
30 class LocaleChangeGuard;
36 class SequencedTaskRunner;
39 namespace extensions {
40 class ExtensionSystem;
44 class CloudPolicyManager;
45 class ProfilePolicyConnector;
46 class SchemaRegistryService;
49 namespace user_prefs {
50 class refRegistrySyncable;
53 // The default profile implementation.
54 class ProfileImpl : public Profile {
56 // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
57 static const char* const kPrefExitTypeNormal;
59 virtual ~ProfileImpl();
61 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
63 // Ensures that the preference hash store has been initialized for the profile
65 static void InitializePrefHashStoreIfRequired(
66 const base::FilePath& profile_path);
68 // Resets the contents of the preference hash store for the profile at
70 static void ResetPrefHashStore(const base::FilePath& profile_path);
72 // content::BrowserContext implementation:
73 virtual base::FilePath GetPath() const OVERRIDE;
74 virtual content::DownloadManagerDelegate*
75 GetDownloadManagerDelegate() OVERRIDE;
76 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
77 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
78 int renderer_child_id) OVERRIDE;
79 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
80 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
81 int renderer_child_id) OVERRIDE;
82 virtual net::URLRequestContextGetter*
83 GetMediaRequestContextForStoragePartition(
84 const base::FilePath& partition_path,
85 bool in_memory) OVERRIDE;
86 virtual void RequestMIDISysExPermission(
87 int render_process_id,
90 const GURL& requesting_frame,
91 const MIDISysExPermissionCallback& callback) OVERRIDE;
92 virtual void CancelMIDISysExPermissionRequest(
93 int render_process_id,
96 const GURL& requesting_frame) OVERRIDE;
97 virtual void RequestProtectedMediaIdentifierPermission(
98 int render_process_id,
102 const GURL& requesting_frame,
103 const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
104 virtual void CancelProtectedMediaIdentifierPermissionRequests(
105 int group_id) OVERRIDE;
106 virtual content::ResourceContext* GetResourceContext() OVERRIDE;
107 virtual content::GeolocationPermissionContext*
108 GetGeolocationPermissionContext() OVERRIDE;
109 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
111 // Profile implementation:
112 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE;
113 // Note that this implementation returns the Google-services username, if any,
114 // not the Chrome user's display name.
115 virtual std::string GetProfileName() OVERRIDE;
116 virtual bool IsOffTheRecord() const OVERRIDE;
117 virtual Profile* GetOffTheRecordProfile() OVERRIDE;
118 virtual void DestroyOffTheRecordProfile() OVERRIDE;
119 virtual bool HasOffTheRecordProfile() OVERRIDE;
120 virtual Profile* GetOriginalProfile() OVERRIDE;
121 virtual bool IsManaged() OVERRIDE;
122 virtual history::TopSites* GetTopSites() OVERRIDE;
123 virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE;
124 virtual ExtensionService* GetExtensionService() OVERRIDE;
125 virtual ExtensionSpecialStoragePolicy*
126 GetExtensionSpecialStoragePolicy() OVERRIDE;
127 virtual PrefService* GetPrefs() OVERRIDE;
128 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
129 virtual net::URLRequestContextGetter*
130 GetRequestContextForExtensions() OVERRIDE;
131 virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE;
132 virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE;
133 virtual bool IsSameProfile(Profile* profile) OVERRIDE;
134 virtual base::Time GetStartTime() const OVERRIDE;
135 virtual net::URLRequestContextGetter* CreateRequestContext(
136 content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
137 virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
138 const base::FilePath& partition_path,
140 content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
141 virtual base::FilePath last_selected_directory() OVERRIDE;
142 virtual void set_last_selected_directory(const base::FilePath& path) OVERRIDE;
143 virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE;
144 virtual void ClearNetworkingHistorySince(
146 const base::Closure& completion) OVERRIDE;
147 virtual GURL GetHomePage() OVERRIDE;
148 virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
149 virtual void SetExitType(ExitType exit_type) OVERRIDE;
150 virtual ExitType GetLastSessionExitType() OVERRIDE;
152 #if defined(OS_CHROMEOS)
153 virtual void ChangeAppLocale(const std::string& locale,
154 AppLocaleChangedVia) OVERRIDE;
155 virtual void OnLogin() OVERRIDE;
156 virtual void InitChromeOSPreferences() OVERRIDE;
157 #endif // defined(OS_CHROMEOS)
159 virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE;
162 friend class Profile;
163 friend class BetterSessionRestoreCrashTest;
164 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
165 ProfilesLaunchedAfterCrash);
166 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, ProfileReadmeCreated);
167 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest,
168 ProfileDeletedBeforeReadmeCreated);
170 // Delay, in milliseconds, before README file is created for a new profile.
171 // This is non-const for testing purposes.
172 static int create_readme_delay_ms;
174 ProfileImpl(const base::FilePath& path,
176 CreateMode create_mode,
177 base::SequencedTaskRunner* sequenced_task_runner);
179 // Does final initialization. Should be called after prefs were loaded.
182 void InitHostZoomMap();
184 void OnDefaultZoomLevelChanged();
185 void OnZoomLevelChanged(
186 const content::HostZoomMap::ZoomLevelChange& change);
188 // Does final prefs initialization and calls Init().
189 void OnPrefsLoaded(bool success);
191 base::FilePath GetPrefFilePath();
193 #if defined(ENABLE_SESSION_SERVICE)
194 void StopCreateSessionServiceTimer();
196 void EnsureSessionServiceCreated();
200 void EnsureRequestContextCreated() {
204 void UpdateProfileUserNameCache();
206 // Updates the ProfileInfoCache with data from this profile.
207 void UpdateProfileNameCache();
208 void UpdateProfileAvatarCache();
209 void UpdateProfileIsEphemeralCache();
211 void GetCacheParameters(bool is_media_context,
212 base::FilePath* cache_path,
215 PrefProxyConfigTracker* CreateProxyConfigTracker();
217 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
218 PrefChangeRegistrar pref_change_registrar_;
220 base::FilePath path_;
221 base::FilePath base_cache_path_;
223 // !!! BIG HONKING WARNING !!!
224 // The order of the members below is important. Do not change it unless
225 // you know what you're doing. Also, if adding a new member here make sure
226 // that the declaration occurs AFTER things it depends on as destruction
227 // happens in reverse order of declaration.
229 // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
230 // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
231 // This can be removed once |prefs_| becomes a BrowserContextKeyedService too.
232 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
233 // which depends on |schema_registry_service_|.
234 #if defined(ENABLE_CONFIGURATION_POLICY)
235 scoped_ptr<policy::SchemaRegistryService> schema_registry_service_;
236 scoped_ptr<policy::CloudPolicyManager> cloud_policy_manager_;
238 scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
240 // Keep |prefs_| on top for destruction order because |extension_prefs_|,
241 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
242 // shall be destructed first.
243 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
244 scoped_ptr<PrefServiceSyncable> prefs_;
245 scoped_ptr<PrefServiceSyncable> otr_prefs_;
246 ProfileImplIOData::Handle io_data_;
247 scoped_refptr<ExtensionSpecialStoragePolicy>
248 extension_special_storage_policy_;
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<history::ShortcutsBackend> shortcuts_backend_;
254 // Exit type the last time the profile was opened. This is set only once from
256 ExitType last_session_exit_type_;
258 #if defined(ENABLE_SESSION_SERVICE)
259 base::OneShotTimer<ProfileImpl> create_session_service_timer_;
262 scoped_ptr<Profile> off_the_record_profile_;
264 // See GetStartTime for details.
265 base::Time start_time_;
267 scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails.
269 #if defined(OS_CHROMEOS)
270 scoped_ptr<chromeos::Preferences> chromeos_preferences_;
272 scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_;
274 bool is_login_profile_;
277 scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
279 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
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:
285 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
287 // and you can read the raw headers here:
289 // components/browser_context_keyed_service/browser_context_dependency_manager.{h,cc}
290 // components/browser_context_keyed_service/browser_context_keyed_service.h
291 // components/browser_context_keyed_service/browser_context_keyed_service_factory.{h,cc}
293 Profile::Delegate* delegate_;
295 chrome_browser_net::Predictor* predictor_;
297 DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
300 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_