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 ~ProfileImpl() override
;
76 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
78 // content::BrowserContext implementation:
79 scoped_ptr
<content::ZoomLevelDelegate
> CreateZoomLevelDelegate(
80 const base::FilePath
& partition_path
) override
;
81 base::FilePath
GetPath() const override
;
82 content::DownloadManagerDelegate
* GetDownloadManagerDelegate() override
;
83 net::URLRequestContextGetter
* GetRequestContext() override
;
84 net::URLRequestContextGetter
* GetRequestContextForRenderProcess(
85 int renderer_child_id
) override
;
86 net::URLRequestContextGetter
* GetMediaRequestContext() override
;
87 net::URLRequestContextGetter
* GetMediaRequestContextForRenderProcess(
88 int renderer_child_id
) override
;
89 net::URLRequestContextGetter
* GetMediaRequestContextForStoragePartition(
90 const base::FilePath
& partition_path
,
91 bool in_memory
) override
;
92 content::ResourceContext
* GetResourceContext() override
;
93 content::BrowserPluginGuestManager
* GetGuestManager() override
;
94 storage::SpecialStoragePolicy
* GetSpecialStoragePolicy() override
;
95 content::PushMessagingService
* GetPushMessagingService() override
;
96 content::SSLHostStateDelegate
* GetSSLHostStateDelegate() override
;
98 // Profile implementation:
99 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 std::string
GetProfileName() override
;
103 ProfileType
GetProfileType() const override
;
104 bool IsOffTheRecord() const override
;
105 Profile
* GetOffTheRecordProfile() override
;
106 void DestroyOffTheRecordProfile() override
;
107 bool HasOffTheRecordProfile() override
;
108 Profile
* GetOriginalProfile() override
;
109 bool IsSupervised() override
;
110 bool IsChild() override
;
111 bool IsLegacySupervised() override
;
112 history::TopSites
* GetTopSites() override
;
113 history::TopSites
* GetTopSitesWithoutCreating() override
;
114 ExtensionSpecialStoragePolicy
* GetExtensionSpecialStoragePolicy() override
;
115 PrefService
* GetPrefs() override
;
116 chrome::ChromeZoomLevelPrefs
* GetZoomLevelPrefs() override
;
117 PrefService
* GetOffTheRecordPrefs() override
;
118 net::URLRequestContextGetter
* GetRequestContextForExtensions() override
;
119 net::SSLConfigService
* GetSSLConfigService() override
;
120 HostContentSettingsMap
* GetHostContentSettingsMap() override
;
121 bool IsSameProfile(Profile
* profile
) override
;
122 base::Time
GetStartTime() const override
;
123 net::URLRequestContextGetter
* CreateRequestContext(
124 content::ProtocolHandlerMap
* protocol_handlers
,
125 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
126 net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
127 const base::FilePath
& partition_path
,
129 content::ProtocolHandlerMap
* protocol_handlers
,
130 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
131 base::FilePath
last_selected_directory() override
;
132 void set_last_selected_directory(const base::FilePath
& path
) override
;
133 chrome_browser_net::Predictor
* GetNetworkPredictor() override
;
134 DevToolsNetworkController
* GetDevToolsNetworkController() override
;
135 void ClearNetworkingHistorySince(base::Time time
,
136 const base::Closure
& completion
) override
;
137 GURL
GetHomePage() override
;
138 bool WasCreatedByVersionOrLater(const std::string
& version
) override
;
139 void SetExitType(ExitType exit_type
) override
;
140 ExitType
GetLastSessionExitType() override
;
142 #if defined(OS_CHROMEOS)
143 virtual void ChangeAppLocale(const std::string
& locale
,
144 AppLocaleChangedVia
) override
;
145 virtual void OnLogin() override
;
146 virtual void InitChromeOSPreferences() override
;
147 #endif // defined(OS_CHROMEOS)
149 PrefProxyConfigTracker
* GetProxyConfigTracker() override
;
152 #if defined(OS_CHROMEOS)
153 friend class chromeos::KioskTest
;
154 friend class chromeos::SupervisedUserTestBase
;
156 friend class Profile
;
157 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
,
158 ProfilesLaunchedAfterCrash
);
159 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest
, DISABLED_ProfileReadmeCreated
);
160 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest
,
161 ProfileDeletedBeforeReadmeCreated
);
163 // Delay, in milliseconds, before README file is created for a new profile.
164 // This is non-const for testing purposes.
165 static int create_readme_delay_ms
;
167 ProfileImpl(const base::FilePath
& path
,
169 CreateMode create_mode
,
170 base::SequencedTaskRunner
* sequenced_task_runner
);
172 // Does final initialization. Should be called after prefs were loaded.
175 // Does final prefs initialization and calls Init().
176 void OnPrefsLoaded(bool success
);
178 #if defined(ENABLE_SESSION_SERVICE)
179 void StopCreateSessionServiceTimer();
181 void EnsureSessionServiceCreated();
185 void EnsureRequestContextCreated() {
189 // Updates the ProfileInfoCache with data from this profile.
190 void UpdateProfileSupervisedUserIdCache();
191 void UpdateProfileNameCache();
192 void UpdateProfileAvatarCache();
193 void UpdateProfileIsEphemeralCache();
195 void GetCacheParameters(bool is_media_context
,
196 base::FilePath
* cache_path
,
199 PrefProxyConfigTracker
* CreateProxyConfigTracker();
201 scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
202 CreateDomainReliabilityMonitor(PrefService
* local_state
);
204 PrefChangeRegistrar pref_change_registrar_
;
206 base::FilePath path_
;
207 base::FilePath base_cache_path_
;
209 // !!! BIG HONKING WARNING !!!
210 // The order of the members below is important. Do not change it unless
211 // you know what you're doing. Also, if adding a new member here make sure
212 // that the declaration occurs AFTER things it depends on as destruction
213 // happens in reverse order of declaration.
215 // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
216 // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
217 // This can be removed once |prefs_| becomes a KeyedService too.
218 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
219 // which depends on |schema_registry_service_|.
220 #if defined(ENABLE_CONFIGURATION_POLICY)
221 scoped_ptr
<policy::SchemaRegistryService
> schema_registry_service_
;
222 scoped_ptr
<policy::CloudPolicyManager
> cloud_policy_manager_
;
224 scoped_ptr
<policy::ProfilePolicyConnector
> profile_policy_connector_
;
226 // Keep |pref_validation_delegate_| above |prefs_| so that the former outlives
228 scoped_ptr
<TrackedPreferenceValidationDelegate
> pref_validation_delegate_
;
230 // Keep |prefs_| on top for destruction order because |extension_prefs_|,
231 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
232 // shall be destructed first.
233 scoped_refptr
<user_prefs::PrefRegistrySyncable
> pref_registry_
;
234 scoped_ptr
<PrefServiceSyncable
> prefs_
;
235 scoped_ptr
<PrefServiceSyncable
> otr_prefs_
;
236 ProfileImplIOData::Handle io_data_
;
237 #if defined(ENABLE_EXTENSIONS)
238 scoped_refptr
<ExtensionSpecialStoragePolicy
>
239 extension_special_storage_policy_
;
241 scoped_ptr
<NetPrefObserver
> net_pref_observer_
;
242 scoped_ptr
<SSLConfigServiceManager
> ssl_config_service_manager_
;
243 scoped_refptr
<HostContentSettingsMap
> host_content_settings_map_
;
244 scoped_refptr
<ShortcutsBackend
> shortcuts_backend_
;
246 // Exit type the last time the profile was opened. This is set only once from
248 ExitType last_session_exit_type_
;
250 #if defined(ENABLE_SESSION_SERVICE)
251 base::OneShotTimer
<ProfileImpl
> create_session_service_timer_
;
254 scoped_ptr
<Profile
> off_the_record_profile_
;
256 // See GetStartTime for details.
257 base::Time start_time_
;
259 scoped_refptr
<history::TopSites
> top_sites_
; // For history and thumbnails.
261 #if defined(OS_CHROMEOS)
262 scoped_ptr
<chromeos::Preferences
> chromeos_preferences_
;
264 scoped_ptr
<chromeos::LocaleChangeGuard
> locale_change_guard_
;
266 bool is_login_profile_
;
269 scoped_ptr
<PrefProxyConfigTracker
> pref_proxy_config_tracker_
;
271 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
273 // Instead, make your Service/Manager/whatever object you're hanging off the
274 // Profile use our new BrowserContextKeyedServiceFactory system instead.
275 // You can find the design document here:
277 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
279 // and you can read the raw headers here:
281 // components/keyed_service/content/browser_context_dependency_manager.*
282 // components/keyed_service/core/keyed_service.h
283 // components/keyed_service/content/browser_context_keyed_service_factory.*
285 Profile::Delegate
* delegate_
;
287 chrome_browser_net::Predictor
* predictor_
;
289 DISALLOW_COPY_AND_ASSIGN(ProfileImpl
);
292 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_