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 // content::BrowserContext implementation:
64 virtual base::FilePath
GetPath() const OVERRIDE
;
65 virtual content::DownloadManagerDelegate
*
66 GetDownloadManagerDelegate() OVERRIDE
;
67 virtual net::URLRequestContextGetter
* GetRequestContext() OVERRIDE
;
68 virtual net::URLRequestContextGetter
* GetRequestContextForRenderProcess(
69 int renderer_child_id
) OVERRIDE
;
70 virtual net::URLRequestContextGetter
* GetMediaRequestContext() OVERRIDE
;
71 virtual net::URLRequestContextGetter
* GetMediaRequestContextForRenderProcess(
72 int renderer_child_id
) OVERRIDE
;
73 virtual net::URLRequestContextGetter
*
74 GetMediaRequestContextForStoragePartition(
75 const base::FilePath
& partition_path
,
76 bool in_memory
) OVERRIDE
;
77 virtual void RequestMIDISysExPermission(
78 int render_process_id
,
81 const GURL
& requesting_frame
,
82 const MIDISysExPermissionCallback
& callback
) OVERRIDE
;
83 virtual void CancelMIDISysExPermissionRequest(
84 int render_process_id
,
87 const GURL
& requesting_frame
) OVERRIDE
;
88 virtual void RequestProtectedMediaIdentifierPermission(
89 int render_process_id
,
93 const GURL
& requesting_frame
,
94 const ProtectedMediaIdentifierPermissionCallback
& callback
) OVERRIDE
;
95 virtual void CancelProtectedMediaIdentifierPermissionRequests(
96 int group_id
) OVERRIDE
;
97 virtual content::ResourceContext
* GetResourceContext() OVERRIDE
;
98 virtual content::GeolocationPermissionContext
*
99 GetGeolocationPermissionContext() OVERRIDE
;
100 virtual quota::SpecialStoragePolicy
* GetSpecialStoragePolicy() OVERRIDE
;
102 // Profile implementation:
103 virtual scoped_refptr
<base::SequencedTaskRunner
> GetIOTaskRunner() OVERRIDE
;
104 // Note that this implementation returns the Google-services username, if any,
105 // not the Chrome user's display name.
106 virtual std::string
GetProfileName() OVERRIDE
;
107 virtual bool IsOffTheRecord() const OVERRIDE
;
108 virtual Profile
* GetOffTheRecordProfile() OVERRIDE
;
109 virtual void DestroyOffTheRecordProfile() OVERRIDE
;
110 virtual bool HasOffTheRecordProfile() OVERRIDE
;
111 virtual Profile
* GetOriginalProfile() OVERRIDE
;
112 virtual bool IsManaged() OVERRIDE
;
113 virtual history::TopSites
* GetTopSites() OVERRIDE
;
114 virtual history::TopSites
* GetTopSitesWithoutCreating() OVERRIDE
;
115 virtual ExtensionService
* GetExtensionService() OVERRIDE
;
116 virtual ExtensionSpecialStoragePolicy
*
117 GetExtensionSpecialStoragePolicy() OVERRIDE
;
118 virtual PrefService
* GetPrefs() OVERRIDE
;
119 virtual PrefService
* GetOffTheRecordPrefs() OVERRIDE
;
120 virtual net::URLRequestContextGetter
*
121 GetRequestContextForExtensions() OVERRIDE
;
122 virtual net::SSLConfigService
* GetSSLConfigService() OVERRIDE
;
123 virtual HostContentSettingsMap
* GetHostContentSettingsMap() OVERRIDE
;
124 virtual bool IsSameProfile(Profile
* profile
) OVERRIDE
;
125 virtual base::Time
GetStartTime() const OVERRIDE
;
126 virtual net::URLRequestContextGetter
* CreateRequestContext(
127 content::ProtocolHandlerMap
* protocol_handlers
) OVERRIDE
;
128 virtual net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
129 const base::FilePath
& partition_path
,
131 content::ProtocolHandlerMap
* protocol_handlers
) OVERRIDE
;
132 virtual base::FilePath
last_selected_directory() OVERRIDE
;
133 virtual void set_last_selected_directory(const base::FilePath
& path
) OVERRIDE
;
134 virtual chrome_browser_net::Predictor
* GetNetworkPredictor() OVERRIDE
;
135 virtual void ClearNetworkingHistorySince(
137 const base::Closure
& completion
) OVERRIDE
;
138 virtual GURL
GetHomePage() OVERRIDE
;
139 virtual bool WasCreatedByVersionOrLater(const std::string
& version
) OVERRIDE
;
140 virtual void SetExitType(ExitType exit_type
) OVERRIDE
;
141 virtual ExitType
GetLastSessionExitType() OVERRIDE
;
143 #if defined(OS_CHROMEOS)
144 virtual void ChangeAppLocale(const std::string
& locale
,
145 AppLocaleChangedVia
) OVERRIDE
;
146 virtual void OnLogin() OVERRIDE
;
147 virtual void InitChromeOSPreferences() OVERRIDE
;
148 #endif // defined(OS_CHROMEOS)
150 virtual PrefProxyConfigTracker
* GetProxyConfigTracker() OVERRIDE
;
153 friend class Profile
;
154 friend class BetterSessionRestoreCrashTest
;
155 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
,
156 ProfilesLaunchedAfterCrash
);
157 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest
, ProfileReadmeCreated
);
158 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest
,
159 ProfileDeletedBeforeReadmeCreated
);
161 // Delay, in milliseconds, before README file is created for a new profile.
162 // This is non-const for testing purposes.
163 static int create_readme_delay_ms
;
165 ProfileImpl(const base::FilePath
& path
,
167 CreateMode create_mode
,
168 base::SequencedTaskRunner
* sequenced_task_runner
);
170 // Does final initialization. Should be called after prefs were loaded.
173 void InitHostZoomMap();
175 void OnDefaultZoomLevelChanged();
176 void OnZoomLevelChanged(
177 const content::HostZoomMap::ZoomLevelChange
& change
);
179 // Does final prefs initialization and calls Init().
180 void OnPrefsLoaded(bool success
);
182 base::FilePath
GetPrefFilePath();
184 #if defined(ENABLE_SESSION_SERVICE)
185 void StopCreateSessionServiceTimer();
187 void EnsureSessionServiceCreated();
191 void EnsureRequestContextCreated() {
195 void UpdateProfileUserNameCache();
197 // Updates the ProfileInfoCache with data from this profile.
198 void UpdateProfileNameCache();
199 void UpdateProfileAvatarCache();
200 void UpdateProfileIsEphemeralCache();
202 void GetCacheParameters(bool is_media_context
,
203 base::FilePath
* cache_path
,
206 PrefProxyConfigTracker
* CreateProxyConfigTracker();
208 scoped_ptr
<content::HostZoomMap::Subscription
> zoom_subscription_
;
209 PrefChangeRegistrar pref_change_registrar_
;
211 base::FilePath path_
;
212 base::FilePath base_cache_path_
;
214 // !!! BIG HONKING WARNING !!!
215 // The order of the members below is important. Do not change it unless
216 // you know what you're doing. Also, if adding a new member here make sure
217 // that the declaration occurs AFTER things it depends on as destruction
218 // happens in reverse order of declaration.
220 // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
221 // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
222 // This can be removed once |prefs_| becomes a BrowserContextKeyedService too.
223 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
224 // which depends on |schema_registry_service_|.
225 #if defined(ENABLE_CONFIGURATION_POLICY)
226 scoped_ptr
<policy::SchemaRegistryService
> schema_registry_service_
;
227 scoped_ptr
<policy::CloudPolicyManager
> cloud_policy_manager_
;
229 scoped_ptr
<policy::ProfilePolicyConnector
> profile_policy_connector_
;
231 // Keep |prefs_| on top for destruction order because |extension_prefs_|,
232 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
233 // shall be destructed first.
234 scoped_refptr
<user_prefs::PrefRegistrySyncable
> pref_registry_
;
235 scoped_ptr
<PrefServiceSyncable
> prefs_
;
236 scoped_ptr
<PrefServiceSyncable
> otr_prefs_
;
237 ProfileImplIOData::Handle io_data_
;
238 scoped_refptr
<ExtensionSpecialStoragePolicy
>
239 extension_special_storage_policy_
;
240 scoped_ptr
<NetPrefObserver
> net_pref_observer_
;
241 scoped_ptr
<SSLConfigServiceManager
> ssl_config_service_manager_
;
242 scoped_refptr
<HostContentSettingsMap
> host_content_settings_map_
;
243 scoped_refptr
<history::ShortcutsBackend
> shortcuts_backend_
;
245 // Exit type the last time the profile was opened. This is set only once from
247 ExitType last_session_exit_type_
;
249 #if defined(ENABLE_SESSION_SERVICE)
250 base::OneShotTimer
<ProfileImpl
> create_session_service_timer_
;
253 scoped_ptr
<Profile
> off_the_record_profile_
;
255 // See GetStartTime for details.
256 base::Time start_time_
;
258 scoped_refptr
<history::TopSites
> top_sites_
; // For history and thumbnails.
260 #if defined(OS_CHROMEOS)
261 scoped_ptr
<chromeos::Preferences
> chromeos_preferences_
;
263 scoped_ptr
<chromeos::LocaleChangeGuard
> locale_change_guard_
;
265 bool is_login_profile_
;
268 scoped_ptr
<PrefProxyConfigTracker
> pref_proxy_config_tracker_
;
270 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
272 // Instead, make your Service/Manager/whatever object you're hanging off the
273 // Profile use our new BrowserContextKeyedServiceFactory system instead.
274 // You can find the design document here:
276 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
278 // and you can read the raw headers here:
280 // components/browser_context_keyed_service/browser_context_dependency_manager.{h,cc}
281 // components/browser_context_keyed_service/browser_context_keyed_service.h
282 // components/browser_context_keyed_service/browser_context_keyed_service_factory.{h,cc}
284 Profile::Delegate
* delegate_
;
286 chrome_browser_net::Predictor
* predictor_
;
288 DISALLOW_COPY_AND_ASSIGN(ProfileImpl
);
291 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_