Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / browser / profiles / profile_impl.h
blob8bbf7e1c65c7a5856b66f6cc73a7133e40336516
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_
10 #include <string>
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;
25 class PrefService;
27 class ShortcutsBackend;
28 class SSLConfigServiceManager;
29 class TrackedPreferenceValidationDelegate;
31 #if defined(OS_CHROMEOS)
32 namespace chromeos {
33 class KioskTest;
34 class LocaleChangeGuard;
35 class Preferences;
36 class SupervisedUserTestBase;
38 #endif
40 namespace base {
41 class SequencedTaskRunner;
44 namespace domain_reliability {
45 class DomainReliabilityMonitor;
48 namespace extensions {
49 class ExtensionSystem;
52 namespace policy {
53 class CloudPolicyManager;
54 class ProfilePolicyConnector;
55 class SchemaRegistryService;
58 namespace syncable_prefs {
59 class PrefServiceSyncable;
62 namespace user_prefs {
63 class refRegistrySyncable;
66 // The default profile implementation.
67 class ProfileImpl : public Profile {
68 public:
69 // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
70 static const char* const kPrefExitTypeNormal;
72 ~ProfileImpl() override;
74 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
76 // content::BrowserContext implementation:
77 scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
78 const base::FilePath& partition_path) override;
79 base::FilePath GetPath() const override;
80 content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
81 net::URLRequestContextGetter* GetRequestContext() override;
82 net::URLRequestContextGetter* GetRequestContextForRenderProcess(
83 int renderer_child_id) override;
84 net::URLRequestContextGetter* GetMediaRequestContext() override;
85 net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
86 int renderer_child_id) override;
87 net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition(
88 const base::FilePath& partition_path,
89 bool in_memory) override;
90 content::ResourceContext* GetResourceContext() override;
91 content::BrowserPluginGuestManager* GetGuestManager() override;
92 storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
93 content::PushMessagingService* GetPushMessagingService() override;
94 content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
95 content::PermissionManager* GetPermissionManager() override;
97 // Profile implementation:
98 scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override;
99 // Note that this implementation returns the Google-services username, if any,
100 // not the Chrome user's display name.
101 std::string GetProfileUserName() const override;
102 ProfileType GetProfileType() const override;
103 bool IsOffTheRecord() const override;
104 Profile* GetOffTheRecordProfile() override;
105 void DestroyOffTheRecordProfile() override;
106 bool HasOffTheRecordProfile() override;
107 Profile* GetOriginalProfile() override;
108 bool IsSupervised() const override;
109 bool IsChild() const override;
110 bool IsLegacySupervised() const override;
111 ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() override;
112 PrefService* GetPrefs() override;
113 const PrefService* GetPrefs() const override;
114 ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
115 PrefService* GetOffTheRecordPrefs() override;
116 net::URLRequestContextGetter* GetRequestContextForExtensions() override;
117 net::SSLConfigService* GetSSLConfigService() override;
118 bool IsSameProfile(Profile* profile) override;
119 base::Time GetStartTime() const override;
120 net::URLRequestContextGetter* CreateRequestContext(
121 content::ProtocolHandlerMap* protocol_handlers,
122 content::URLRequestInterceptorScopedVector request_interceptors) override;
123 net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
124 const base::FilePath& partition_path,
125 bool in_memory,
126 content::ProtocolHandlerMap* protocol_handlers,
127 content::URLRequestInterceptorScopedVector request_interceptors) override;
128 base::FilePath last_selected_directory() override;
129 void set_last_selected_directory(const base::FilePath& path) override;
130 chrome_browser_net::Predictor* GetNetworkPredictor() override;
131 DevToolsNetworkControllerHandle* GetDevToolsNetworkControllerHandle()
132 override;
133 void ClearNetworkingHistorySince(base::Time time,
134 const base::Closure& completion) override;
135 GURL GetHomePage() override;
136 bool WasCreatedByVersionOrLater(const std::string& version) override;
137 void SetExitType(ExitType exit_type) override;
138 ExitType GetLastSessionExitType() override;
140 #if defined(OS_CHROMEOS)
141 void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override;
142 void OnLogin() override;
143 void InitChromeOSPreferences() override;
144 #endif // defined(OS_CHROMEOS)
146 PrefProxyConfigTracker* GetProxyConfigTracker() override;
148 private:
149 #if defined(OS_CHROMEOS)
150 friend class chromeos::KioskTest;
151 friend class chromeos::SupervisedUserTestBase;
152 #endif
153 friend class Profile;
154 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
155 ProfilesLaunchedAfterCrash);
156 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, DISABLED_ProfileReadmeCreated);
157 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest,
158 ProfileDeletedBeforeReadmeCreated);
160 ProfileImpl(const base::FilePath& path,
161 Delegate* delegate,
162 CreateMode create_mode,
163 base::SequencedTaskRunner* sequenced_task_runner);
165 // Does final initialization. Should be called after prefs were loaded.
166 void DoFinalInit();
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();
178 #endif
181 void EnsureRequestContextCreated() {
182 GetRequestContext();
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,
193 int* max_size);
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_;
219 #endif
220 scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
222 // Keep |pref_validation_delegate_| above |prefs_| so that the former outlives
223 // the latter.
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<syncable_prefs::PrefServiceSyncable> prefs_;
231 scoped_ptr<syncable_prefs::PrefServiceSyncable> otr_prefs_;
232 ProfileImplIOData::Handle io_data_;
233 #if defined(ENABLE_EXTENSIONS)
234 scoped_refptr<ExtensionSpecialStoragePolicy>
235 extension_special_storage_policy_;
236 #endif
237 scoped_ptr<NetPrefObserver> net_pref_observer_;
238 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
239 scoped_refptr<ShortcutsBackend> shortcuts_backend_;
241 // Exit type the last time the profile was opened. This is set only once from
242 // prefs.
243 ExitType last_session_exit_type_;
245 #if defined(ENABLE_SESSION_SERVICE)
246 base::OneShotTimer<ProfileImpl> create_session_service_timer_;
247 #endif
249 scoped_ptr<Profile> off_the_record_profile_;
251 // See GetStartTime for details.
252 base::Time start_time_;
254 #if defined(OS_CHROMEOS)
255 scoped_ptr<chromeos::Preferences> chromeos_preferences_;
257 scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_;
258 #endif
260 scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
262 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
264 // Instead, make your Service/Manager/whatever object you're hanging off the
265 // Profile use our new BrowserContextKeyedServiceFactory system instead.
266 // You can find the design document here:
268 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
270 // and you can read the raw headers here:
272 // components/keyed_service/content/browser_context_dependency_manager.*
273 // components/keyed_service/core/keyed_service.h
274 // components/keyed_service/content/browser_context_keyed_service_factory.*
276 Profile::Delegate* delegate_;
278 chrome_browser_net::Predictor* predictor_;
280 DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
283 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_