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