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 "chrome/browser/ui/zoom/chrome_zoom_level_prefs.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
;
36 class SupervisedUserTestBase
;
41 class SequencedTaskRunner
;
44 namespace data_reduction_proxy
{
45 class DataReductionProxyParams
;
48 class DataReductionProxyChromeSettings
;
50 namespace domain_reliability
{
51 class DomainReliabilityMonitor
;
54 namespace extensions
{
55 class ExtensionSystem
;
59 class CloudPolicyManager
;
60 class ProfilePolicyConnector
;
61 class SchemaRegistryService
;
64 namespace user_prefs
{
65 class refRegistrySyncable
;
68 // The default profile implementation.
69 class ProfileImpl
: public Profile
{
71 // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
72 static const char* const kPrefExitTypeNormal
;
74 virtual ~ProfileImpl();
76 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
78 // content::BrowserContext implementation:
79 virtual base::FilePath
GetPath() const override
;
80 virtual content::DownloadManagerDelegate
*
81 GetDownloadManagerDelegate() override
;
82 virtual net::URLRequestContextGetter
* GetRequestContext() override
;
83 virtual net::URLRequestContextGetter
* GetRequestContextForRenderProcess(
84 int renderer_child_id
) override
;
85 virtual net::URLRequestContextGetter
* GetMediaRequestContext() override
;
86 virtual net::URLRequestContextGetter
* GetMediaRequestContextForRenderProcess(
87 int renderer_child_id
) override
;
88 virtual net::URLRequestContextGetter
*
89 GetMediaRequestContextForStoragePartition(
90 const base::FilePath
& partition_path
,
91 bool in_memory
) override
;
92 virtual content::ResourceContext
* GetResourceContext() override
;
93 virtual content::BrowserPluginGuestManager
* GetGuestManager() override
;
94 virtual storage::SpecialStoragePolicy
* GetSpecialStoragePolicy() override
;
95 virtual content::PushMessagingService
* GetPushMessagingService() override
;
96 virtual content::SSLHostStateDelegate
* GetSSLHostStateDelegate() override
;
98 // Profile implementation:
99 virtual scoped_refptr
<base::SequencedTaskRunner
> GetIOTaskRunner() override
;
100 // Note that this implementation returns the Google-services username, if any,
101 // not the Chrome user's display name.
102 virtual std::string
GetProfileName() override
;
103 virtual ProfileType
GetProfileType() const override
;
104 virtual bool IsOffTheRecord() const override
;
105 virtual Profile
* GetOffTheRecordProfile() override
;
106 virtual void DestroyOffTheRecordProfile() override
;
107 virtual bool HasOffTheRecordProfile() override
;
108 virtual Profile
* GetOriginalProfile() override
;
109 virtual bool IsSupervised() override
;
110 virtual history::TopSites
* GetTopSites() override
;
111 virtual history::TopSites
* GetTopSitesWithoutCreating() override
;
112 virtual ExtensionSpecialStoragePolicy
*
113 GetExtensionSpecialStoragePolicy() override
;
114 virtual PrefService
* GetPrefs() override
;
115 virtual chrome::ChromeZoomLevelPrefs
* GetZoomLevelPrefs() override
;
116 virtual PrefService
* GetOffTheRecordPrefs() override
;
117 virtual net::URLRequestContextGetter
*
118 GetRequestContextForExtensions() override
;
119 virtual net::SSLConfigService
* GetSSLConfigService() override
;
120 virtual HostContentSettingsMap
* GetHostContentSettingsMap() override
;
121 virtual bool IsSameProfile(Profile
* profile
) override
;
122 virtual base::Time
GetStartTime() const override
;
123 virtual net::URLRequestContextGetter
* CreateRequestContext(
124 content::ProtocolHandlerMap
* protocol_handlers
,
125 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
126 virtual net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
127 const base::FilePath
& partition_path
,
129 content::ProtocolHandlerMap
* protocol_handlers
,
130 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
131 virtual base::FilePath
last_selected_directory() override
;
132 virtual void set_last_selected_directory(const base::FilePath
& path
) override
;
133 virtual chrome_browser_net::Predictor
* GetNetworkPredictor() override
;
134 virtual DevToolsNetworkController
* GetDevToolsNetworkController() 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 #if defined(OS_CHROMEOS)
154 friend class chromeos::KioskTest
;
155 friend class chromeos::SupervisedUserTestBase
;
157 friend class Profile
;
158 friend class BetterSessionRestoreCrashTest
;
159 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
,
160 ProfilesLaunchedAfterCrash
);
161 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest
, DISABLED_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 // TODO(wjmaclean): Delete this once the HostZoomMap moves to
179 void InitHostZoomMap();
181 // Does final prefs initialization and calls Init().
182 void OnPrefsLoaded(bool success
);
184 #if defined(ENABLE_SESSION_SERVICE)
185 void StopCreateSessionServiceTimer();
187 void EnsureSessionServiceCreated();
191 void EnsureRequestContextCreated() {
195 // Updates the ProfileInfoCache with data from this profile.
196 void UpdateProfileUserNameCache();
197 void UpdateProfileSupervisedUserIdCache();
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
<domain_reliability::DomainReliabilityMonitor
>
209 CreateDomainReliabilityMonitor(PrefService
* local_state
);
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 |pref_validation_delegate_| above |prefs_| so that the former outlives
235 scoped_ptr
<TrackedPreferenceValidationDelegate
> pref_validation_delegate_
;
237 // Keep |prefs_| on top for destruction order because |extension_prefs_|,
238 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
239 // shall be destructed first.
240 scoped_refptr
<user_prefs::PrefRegistrySyncable
> pref_registry_
;
241 scoped_ptr
<PrefServiceSyncable
> prefs_
;
242 scoped_ptr
<PrefServiceSyncable
> otr_prefs_
;
243 // TODO(wjmaclean): This is only here temporarily until HostZoomMap moves
244 // into StoragePartition, after which it will also move to StoragePartition.
245 // Must declare this here so it is destroyed before the profile prefs service.
246 scoped_ptr
<chrome::ChromeZoomLevelPrefs
> zoom_level_prefs_
;
247 ProfileImplIOData::Handle io_data_
;
248 #if defined(ENABLE_EXTENSIONS)
249 scoped_refptr
<ExtensionSpecialStoragePolicy
>
250 extension_special_storage_policy_
;
252 scoped_ptr
<NetPrefObserver
> net_pref_observer_
;
253 scoped_ptr
<SSLConfigServiceManager
> ssl_config_service_manager_
;
254 scoped_refptr
<HostContentSettingsMap
> host_content_settings_map_
;
255 scoped_refptr
<ShortcutsBackend
> shortcuts_backend_
;
257 // Exit type the last time the profile was opened. This is set only once from
259 ExitType last_session_exit_type_
;
261 #if defined(ENABLE_SESSION_SERVICE)
262 base::OneShotTimer
<ProfileImpl
> create_session_service_timer_
;
265 scoped_ptr
<Profile
> off_the_record_profile_
;
267 // See GetStartTime for details.
268 base::Time start_time_
;
270 scoped_refptr
<history::TopSites
> top_sites_
; // For history and thumbnails.
272 #if defined(OS_CHROMEOS)
273 scoped_ptr
<chromeos::Preferences
> chromeos_preferences_
;
275 scoped_ptr
<chromeos::LocaleChangeGuard
> locale_change_guard_
;
277 bool is_login_profile_
;
280 scoped_ptr
<PrefProxyConfigTracker
> pref_proxy_config_tracker_
;
282 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
284 // Instead, make your Service/Manager/whatever object you're hanging off the
285 // Profile use our new BrowserContextKeyedServiceFactory system instead.
286 // You can find the design document here:
288 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
290 // and you can read the raw headers here:
292 // components/keyed_service/content/browser_context_dependency_manager.*
293 // components/keyed_service/core/keyed_service.h
294 // components/keyed_service/content/browser_context_keyed_service_factory.*
296 Profile::Delegate
* delegate_
;
298 chrome_browser_net::Predictor
* predictor_
;
300 DISALLOW_COPY_AND_ASSIGN(ProfileImpl
);
303 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_