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 domain_reliability
{
45 class DomainReliabilityMonitor
;
48 namespace extensions
{
49 class ExtensionSystem
;
53 class CloudPolicyManager
;
54 class ProfilePolicyConnector
;
55 class SchemaRegistryService
;
58 namespace user_prefs
{
59 class refRegistrySyncable
;
62 // The default profile implementation.
63 class ProfileImpl
: public Profile
{
65 // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
66 static const char* const kPrefExitTypeNormal
;
68 ~ProfileImpl() override
;
70 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
72 // content::BrowserContext implementation:
73 scoped_ptr
<content::ZoomLevelDelegate
> CreateZoomLevelDelegate(
74 const base::FilePath
& partition_path
) override
;
75 base::FilePath
GetPath() const override
;
76 content::DownloadManagerDelegate
* GetDownloadManagerDelegate() override
;
77 net::URLRequestContextGetter
* GetRequestContext() override
;
78 net::URLRequestContextGetter
* GetRequestContextForRenderProcess(
79 int renderer_child_id
) override
;
80 net::URLRequestContextGetter
* GetMediaRequestContext() override
;
81 net::URLRequestContextGetter
* GetMediaRequestContextForRenderProcess(
82 int renderer_child_id
) override
;
83 net::URLRequestContextGetter
* GetMediaRequestContextForStoragePartition(
84 const base::FilePath
& partition_path
,
85 bool in_memory
) override
;
86 content::ResourceContext
* GetResourceContext() override
;
87 content::BrowserPluginGuestManager
* GetGuestManager() override
;
88 storage::SpecialStoragePolicy
* GetSpecialStoragePolicy() override
;
89 content::PushMessagingService
* GetPushMessagingService() override
;
90 content::SSLHostStateDelegate
* GetSSLHostStateDelegate() override
;
91 content::PermissionManager
* GetPermissionManager() override
;
93 // Profile implementation:
94 scoped_refptr
<base::SequencedTaskRunner
> GetIOTaskRunner() override
;
95 // Note that this implementation returns the Google-services username, if any,
96 // not the Chrome user's display name.
97 std::string
GetProfileUserName() const override
;
98 ProfileType
GetProfileType() const override
;
99 bool IsOffTheRecord() const override
;
100 Profile
* GetOffTheRecordProfile() override
;
101 void DestroyOffTheRecordProfile() override
;
102 bool HasOffTheRecordProfile() override
;
103 Profile
* GetOriginalProfile() override
;
104 bool IsSupervised() override
;
105 bool IsChild() override
;
106 bool IsLegacySupervised() override
;
107 ExtensionSpecialStoragePolicy
* GetExtensionSpecialStoragePolicy() override
;
108 PrefService
* GetPrefs() override
;
109 const PrefService
* GetPrefs() const override
;
110 chrome::ChromeZoomLevelPrefs
* GetZoomLevelPrefs() override
;
111 PrefService
* GetOffTheRecordPrefs() override
;
112 net::URLRequestContextGetter
* GetRequestContextForExtensions() override
;
113 net::SSLConfigService
* GetSSLConfigService() override
;
114 HostContentSettingsMap
* GetHostContentSettingsMap() override
;
115 bool IsSameProfile(Profile
* profile
) override
;
116 base::Time
GetStartTime() const override
;
117 net::URLRequestContextGetter
* CreateRequestContext(
118 content::ProtocolHandlerMap
* protocol_handlers
,
119 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
120 net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
121 const base::FilePath
& partition_path
,
123 content::ProtocolHandlerMap
* protocol_handlers
,
124 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
125 base::FilePath
last_selected_directory() override
;
126 void set_last_selected_directory(const base::FilePath
& path
) override
;
127 chrome_browser_net::Predictor
* GetNetworkPredictor() override
;
128 DevToolsNetworkController
* GetDevToolsNetworkController() override
;
129 void ClearNetworkingHistorySince(base::Time time
,
130 const base::Closure
& completion
) override
;
131 GURL
GetHomePage() override
;
132 bool WasCreatedByVersionOrLater(const std::string
& version
) override
;
133 void SetExitType(ExitType exit_type
) override
;
134 ExitType
GetLastSessionExitType() override
;
136 #if defined(OS_CHROMEOS)
137 void ChangeAppLocale(const std::string
& locale
, AppLocaleChangedVia
) override
;
138 void OnLogin() override
;
139 void InitChromeOSPreferences() override
;
140 #endif // defined(OS_CHROMEOS)
142 PrefProxyConfigTracker
* GetProxyConfigTracker() override
;
145 #if defined(OS_CHROMEOS)
146 friend class chromeos::KioskTest
;
147 friend class chromeos::SupervisedUserTestBase
;
149 friend class Profile
;
150 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
,
151 ProfilesLaunchedAfterCrash
);
152 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest
, DISABLED_ProfileReadmeCreated
);
153 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest
,
154 ProfileDeletedBeforeReadmeCreated
);
156 // Delay, in milliseconds, before README file is created for a new profile.
157 // This is non-const for testing purposes.
158 static int create_readme_delay_ms
;
160 ProfileImpl(const base::FilePath
& path
,
162 CreateMode create_mode
,
163 base::SequencedTaskRunner
* sequenced_task_runner
);
165 // Does final initialization. Should be called after prefs were loaded.
168 // Switch locale (when possible) and proceed to OnLocaleReady().
169 void OnPrefsLoaded(CreateMode create_mode
, bool success
);
171 // Does final prefs initialization and calls Init().
172 void OnLocaleReady();
174 #if defined(ENABLE_SESSION_SERVICE)
175 void StopCreateSessionServiceTimer();
177 void EnsureSessionServiceCreated();
181 void EnsureRequestContextCreated() {
185 // Updates the ProfileInfoCache with data from this profile.
186 void UpdateProfileSupervisedUserIdCache();
187 void UpdateProfileNameCache();
188 void UpdateProfileAvatarCache();
189 void UpdateProfileIsEphemeralCache();
191 void GetCacheParameters(bool is_media_context
,
192 base::FilePath
* cache_path
,
195 PrefProxyConfigTracker
* CreateProxyConfigTracker();
197 scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
198 CreateDomainReliabilityMonitor(PrefService
* local_state
);
200 PrefChangeRegistrar pref_change_registrar_
;
202 base::FilePath path_
;
203 base::FilePath base_cache_path_
;
205 // !!! BIG HONKING WARNING !!!
206 // The order of the members below is important. Do not change it unless
207 // you know what you're doing. Also, if adding a new member here make sure
208 // that the declaration occurs AFTER things it depends on as destruction
209 // happens in reverse order of declaration.
211 // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
212 // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
213 // This can be removed once |prefs_| becomes a KeyedService too.
214 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
215 // which depends on |schema_registry_service_|.
216 #if defined(ENABLE_CONFIGURATION_POLICY)
217 scoped_ptr
<policy::SchemaRegistryService
> schema_registry_service_
;
218 scoped_ptr
<policy::CloudPolicyManager
> cloud_policy_manager_
;
220 scoped_ptr
<policy::ProfilePolicyConnector
> profile_policy_connector_
;
222 // Keep |pref_validation_delegate_| above |prefs_| so that the former outlives
224 scoped_ptr
<TrackedPreferenceValidationDelegate
> pref_validation_delegate_
;
226 // Keep |prefs_| on top for destruction order because |extension_prefs_|,
227 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
228 // shall be destructed first.
229 scoped_refptr
<user_prefs::PrefRegistrySyncable
> pref_registry_
;
230 scoped_ptr
<PrefServiceSyncable
> prefs_
;
231 scoped_ptr
<PrefServiceSyncable
> otr_prefs_
;
232 ProfileImplIOData::Handle io_data_
;
233 #if defined(ENABLE_EXTENSIONS)
234 scoped_refptr
<ExtensionSpecialStoragePolicy
>
235 extension_special_storage_policy_
;
237 scoped_ptr
<NetPrefObserver
> net_pref_observer_
;
238 scoped_ptr
<SSLConfigServiceManager
> ssl_config_service_manager_
;
239 scoped_refptr
<HostContentSettingsMap
> host_content_settings_map_
;
240 scoped_refptr
<ShortcutsBackend
> shortcuts_backend_
;
242 // Exit type the last time the profile was opened. This is set only once from
244 ExitType last_session_exit_type_
;
246 #if defined(ENABLE_SESSION_SERVICE)
247 base::OneShotTimer
<ProfileImpl
> create_session_service_timer_
;
250 scoped_ptr
<Profile
> off_the_record_profile_
;
252 // See GetStartTime for details.
253 base::Time start_time_
;
255 #if defined(OS_CHROMEOS)
256 scoped_ptr
<chromeos::Preferences
> chromeos_preferences_
;
258 scoped_ptr
<chromeos::LocaleChangeGuard
> locale_change_guard_
;
261 scoped_ptr
<PrefProxyConfigTracker
> pref_proxy_config_tracker_
;
263 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
265 // Instead, make your Service/Manager/whatever object you're hanging off the
266 // Profile use our new BrowserContextKeyedServiceFactory system instead.
267 // You can find the design document here:
269 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
271 // and you can read the raw headers here:
273 // components/keyed_service/content/browser_context_dependency_manager.*
274 // components/keyed_service/core/keyed_service.h
275 // components/keyed_service/content/browser_context_keyed_service_factory.*
277 Profile::Delegate
* delegate_
;
279 chrome_browser_net::Predictor
* predictor_
;
281 DISALLOW_COPY_AND_ASSIGN(ProfileImpl
);
284 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_