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 "components/domain_reliability/clear_mode.h"
21 #include "content/public/browser/content_browser_client.h"
22 #include "content/public/browser/host_zoom_map.h"
24 class NetPrefObserver
;
26 class PrefServiceSyncable
;
27 class ShortcutsBackend
;
28 class SSLConfigServiceManager
;
29 class TrackedPreferenceValidationDelegate
;
31 #if defined(OS_CHROMEOS)
34 class LocaleChangeGuard
;
35 class ManagedUserTestBase
;
41 class SequencedTaskRunner
;
44 namespace extensions
{
45 class ExtensionSystem
;
49 class CloudPolicyManager
;
50 class ProfilePolicyConnector
;
51 class SchemaRegistryService
;
54 namespace user_prefs
{
55 class refRegistrySyncable
;
58 // The default profile implementation.
59 class ProfileImpl
: public Profile
{
61 // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
62 static const char* const kPrefExitTypeNormal
;
64 virtual ~ProfileImpl();
66 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
68 // content::BrowserContext implementation:
69 virtual base::FilePath
GetPath() const OVERRIDE
;
70 virtual content::DownloadManagerDelegate
*
71 GetDownloadManagerDelegate() OVERRIDE
;
72 virtual net::URLRequestContextGetter
* GetRequestContext() OVERRIDE
;
73 virtual net::URLRequestContextGetter
* GetRequestContextForRenderProcess(
74 int renderer_child_id
) OVERRIDE
;
75 virtual net::URLRequestContextGetter
* GetMediaRequestContext() OVERRIDE
;
76 virtual net::URLRequestContextGetter
* GetMediaRequestContextForRenderProcess(
77 int renderer_child_id
) OVERRIDE
;
78 virtual net::URLRequestContextGetter
*
79 GetMediaRequestContextForStoragePartition(
80 const base::FilePath
& partition_path
,
81 bool in_memory
) OVERRIDE
;
82 virtual void RequestMidiSysExPermission(
83 int render_process_id
,
86 const GURL
& requesting_frame
,
88 const MidiSysExPermissionCallback
& callback
) OVERRIDE
;
89 virtual void CancelMidiSysExPermissionRequest(
90 int render_process_id
,
93 const GURL
& requesting_frame
) OVERRIDE
;
94 virtual void RequestProtectedMediaIdentifierPermission(
95 int render_process_id
,
98 const ProtectedMediaIdentifierPermissionCallback
& callback
) OVERRIDE
;
99 virtual void CancelProtectedMediaIdentifierPermissionRequests(
100 int render_process_id
,
102 const GURL
& origin
) OVERRIDE
;
103 virtual content::ResourceContext
* GetResourceContext() OVERRIDE
;
104 virtual content::GeolocationPermissionContext
*
105 GetGeolocationPermissionContext() OVERRIDE
;
106 virtual content::BrowserPluginGuestManager
* GetGuestManager() OVERRIDE
;
107 virtual quota::SpecialStoragePolicy
* GetSpecialStoragePolicy() OVERRIDE
;
109 // Profile implementation:
110 virtual scoped_refptr
<base::SequencedTaskRunner
> GetIOTaskRunner() OVERRIDE
;
111 // Note that this implementation returns the Google-services username, if any,
112 // not the Chrome user's display name.
113 virtual std::string
GetProfileName() OVERRIDE
;
114 virtual ProfileType
GetProfileType() const OVERRIDE
;
115 virtual bool IsOffTheRecord() const OVERRIDE
;
116 virtual Profile
* GetOffTheRecordProfile() OVERRIDE
;
117 virtual void DestroyOffTheRecordProfile() OVERRIDE
;
118 virtual bool HasOffTheRecordProfile() OVERRIDE
;
119 virtual Profile
* GetOriginalProfile() OVERRIDE
;
120 virtual bool IsManaged() OVERRIDE
;
121 virtual history::TopSites
* GetTopSites() OVERRIDE
;
122 virtual history::TopSites
* GetTopSitesWithoutCreating() OVERRIDE
;
123 virtual ExtensionService
* GetExtensionService() OVERRIDE
;
124 virtual ExtensionSpecialStoragePolicy
*
125 GetExtensionSpecialStoragePolicy() OVERRIDE
;
126 virtual PrefService
* GetPrefs() OVERRIDE
;
127 virtual PrefService
* GetOffTheRecordPrefs() OVERRIDE
;
128 virtual net::URLRequestContextGetter
*
129 GetRequestContextForExtensions() OVERRIDE
;
130 virtual net::SSLConfigService
* GetSSLConfigService() OVERRIDE
;
131 virtual HostContentSettingsMap
* GetHostContentSettingsMap() OVERRIDE
;
132 virtual bool IsSameProfile(Profile
* profile
) OVERRIDE
;
133 virtual base::Time
GetStartTime() const OVERRIDE
;
134 virtual net::URLRequestContextGetter
* CreateRequestContext(
135 content::ProtocolHandlerMap
* protocol_handlers
,
136 content::URLRequestInterceptorScopedVector request_interceptors
) OVERRIDE
;
137 virtual net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
138 const base::FilePath
& partition_path
,
140 content::ProtocolHandlerMap
* protocol_handlers
,
141 content::URLRequestInterceptorScopedVector request_interceptors
) OVERRIDE
;
142 virtual base::FilePath
last_selected_directory() OVERRIDE
;
143 virtual void set_last_selected_directory(const base::FilePath
& path
) OVERRIDE
;
144 virtual chrome_browser_net::Predictor
* GetNetworkPredictor() OVERRIDE
;
145 virtual DevToolsNetworkController
* GetDevToolsNetworkController() OVERRIDE
;
146 virtual void ClearNetworkingHistorySince(
148 const base::Closure
& completion
) OVERRIDE
;
149 virtual void ClearDomainReliabilityMonitor(
150 domain_reliability::DomainReliabilityClearMode mode
,
151 const base::Closure
& completion
) OVERRIDE
;
152 virtual GURL
GetHomePage() OVERRIDE
;
153 virtual bool WasCreatedByVersionOrLater(const std::string
& version
) OVERRIDE
;
154 virtual void SetExitType(ExitType exit_type
) OVERRIDE
;
155 virtual ExitType
GetLastSessionExitType() OVERRIDE
;
157 #if defined(OS_CHROMEOS)
158 virtual void ChangeAppLocale(const std::string
& locale
,
159 AppLocaleChangedVia
) OVERRIDE
;
160 virtual void OnLogin() OVERRIDE
;
161 virtual void InitChromeOSPreferences() OVERRIDE
;
162 #endif // defined(OS_CHROMEOS)
164 virtual PrefProxyConfigTracker
* GetProxyConfigTracker() OVERRIDE
;
167 #if defined(OS_CHROMEOS)
168 friend class chromeos::KioskTest
;
169 friend class chromeos::ManagedUserTestBase
;
171 friend class Profile
;
172 friend class BetterSessionRestoreCrashTest
;
173 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
,
174 ProfilesLaunchedAfterCrash
);
175 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest
, ProfileReadmeCreated
);
176 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest
,
177 ProfileDeletedBeforeReadmeCreated
);
179 // Delay, in milliseconds, before README file is created for a new profile.
180 // This is non-const for testing purposes.
181 static int create_readme_delay_ms
;
183 ProfileImpl(const base::FilePath
& path
,
185 CreateMode create_mode
,
186 base::SequencedTaskRunner
* sequenced_task_runner
);
188 // Does final initialization. Should be called after prefs were loaded.
191 void InitHostZoomMap();
193 void OnDefaultZoomLevelChanged();
194 void OnZoomLevelChanged(
195 const content::HostZoomMap::ZoomLevelChange
& change
);
197 // Does final prefs initialization and calls Init().
198 void OnPrefsLoaded(bool success
);
200 #if defined(ENABLE_SESSION_SERVICE)
201 void StopCreateSessionServiceTimer();
203 void EnsureSessionServiceCreated();
207 void EnsureRequestContextCreated() {
211 // Updates the ProfileInfoCache with data from this profile.
212 void UpdateProfileUserNameCache();
213 void UpdateProfileManagedUserIdCache();
214 void UpdateProfileNameCache();
215 void UpdateProfileAvatarCache();
216 void UpdateProfileIsEphemeralCache();
218 void GetCacheParameters(bool is_media_context
,
219 base::FilePath
* cache_path
,
222 PrefProxyConfigTracker
* CreateProxyConfigTracker();
224 scoped_ptr
<content::HostZoomMap::Subscription
> zoom_subscription_
;
225 PrefChangeRegistrar pref_change_registrar_
;
227 base::FilePath path_
;
228 base::FilePath base_cache_path_
;
230 // !!! BIG HONKING WARNING !!!
231 // The order of the members below is important. Do not change it unless
232 // you know what you're doing. Also, if adding a new member here make sure
233 // that the declaration occurs AFTER things it depends on as destruction
234 // happens in reverse order of declaration.
236 // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
237 // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
238 // This can be removed once |prefs_| becomes a KeyedService too.
239 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
240 // which depends on |schema_registry_service_|.
241 #if defined(ENABLE_CONFIGURATION_POLICY)
242 scoped_ptr
<policy::SchemaRegistryService
> schema_registry_service_
;
243 scoped_ptr
<policy::CloudPolicyManager
> cloud_policy_manager_
;
245 scoped_ptr
<policy::ProfilePolicyConnector
> profile_policy_connector_
;
247 // Keep |pref_validation_delegate_| above |prefs_| so that the former outlives
249 scoped_ptr
<TrackedPreferenceValidationDelegate
> pref_validation_delegate_
;
251 // Keep |prefs_| on top for destruction order because |extension_prefs_|,
252 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
253 // shall be destructed first.
254 scoped_refptr
<user_prefs::PrefRegistrySyncable
> pref_registry_
;
255 scoped_ptr
<PrefServiceSyncable
> prefs_
;
256 scoped_ptr
<PrefServiceSyncable
> otr_prefs_
;
257 ProfileImplIOData::Handle io_data_
;
258 scoped_refptr
<ExtensionSpecialStoragePolicy
>
259 extension_special_storage_policy_
;
260 scoped_ptr
<NetPrefObserver
> net_pref_observer_
;
261 scoped_ptr
<SSLConfigServiceManager
> ssl_config_service_manager_
;
262 scoped_refptr
<HostContentSettingsMap
> host_content_settings_map_
;
263 scoped_refptr
<ShortcutsBackend
> shortcuts_backend_
;
265 // Exit type the last time the profile was opened. This is set only once from
267 ExitType last_session_exit_type_
;
269 #if defined(ENABLE_SESSION_SERVICE)
270 base::OneShotTimer
<ProfileImpl
> create_session_service_timer_
;
273 scoped_ptr
<Profile
> off_the_record_profile_
;
275 // See GetStartTime for details.
276 base::Time start_time_
;
278 scoped_refptr
<history::TopSites
> top_sites_
; // For history and thumbnails.
280 #if defined(OS_CHROMEOS)
281 scoped_ptr
<chromeos::Preferences
> chromeos_preferences_
;
283 scoped_ptr
<chromeos::LocaleChangeGuard
> locale_change_guard_
;
285 bool is_login_profile_
;
288 scoped_ptr
<PrefProxyConfigTracker
> pref_proxy_config_tracker_
;
290 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
292 // Instead, make your Service/Manager/whatever object you're hanging off the
293 // Profile use our new BrowserContextKeyedServiceFactory system instead.
294 // You can find the design document here:
296 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
298 // and you can read the raw headers here:
300 // components/keyed_service/content/browser_context_dependency_manager.*
301 // components/keyed_service/core/keyed_service.h
302 // components/keyed_service/content/browser_context_keyed_service_factory.*
304 Profile::Delegate
* delegate_
;
306 chrome_browser_net::Predictor
* predictor_
;
308 DISALLOW_COPY_AND_ASSIGN(ProfileImpl
);
311 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_