Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / profiles / profile_impl.h
blobec4cedc9ae89aab260044dc5b44b386aaa2fd78c
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;
26 class PrefServiceSyncable;
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 user_prefs {
59 class refRegistrySyncable;
62 // The default profile implementation.
63 class ProfileImpl : public Profile {
64 public:
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() const override;
105 bool IsChild() const override;
106 bool IsLegacySupervised() const override;
107 ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() override;
108 PrefService* GetPrefs() override;
109 const PrefService* GetPrefs() const override;
110 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,
122 bool in_memory,
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 DevToolsNetworkControllerHandle* GetDevToolsNetworkControllerHandle()
129 override;
130 void ClearNetworkingHistorySince(base::Time time,
131 const base::Closure& completion) override;
132 GURL GetHomePage() override;
133 bool WasCreatedByVersionOrLater(const std::string& version) override;
134 void SetExitType(ExitType exit_type) override;
135 ExitType GetLastSessionExitType() override;
137 #if defined(OS_CHROMEOS)
138 void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override;
139 void OnLogin() override;
140 void InitChromeOSPreferences() override;
141 #endif // defined(OS_CHROMEOS)
143 PrefProxyConfigTracker* GetProxyConfigTracker() override;
145 private:
146 #if defined(OS_CHROMEOS)
147 friend class chromeos::KioskTest;
148 friend class chromeos::SupervisedUserTestBase;
149 #endif
150 friend class Profile;
151 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
152 ProfilesLaunchedAfterCrash);
153 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, DISABLED_ProfileReadmeCreated);
154 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest,
155 ProfileDeletedBeforeReadmeCreated);
157 ProfileImpl(const base::FilePath& path,
158 Delegate* delegate,
159 CreateMode create_mode,
160 base::SequencedTaskRunner* sequenced_task_runner);
162 // Does final initialization. Should be called after prefs were loaded.
163 void DoFinalInit();
165 // Switch locale (when possible) and proceed to OnLocaleReady().
166 void OnPrefsLoaded(CreateMode create_mode, bool success);
168 // Does final prefs initialization and calls Init().
169 void OnLocaleReady();
171 #if defined(ENABLE_SESSION_SERVICE)
172 void StopCreateSessionServiceTimer();
174 void EnsureSessionServiceCreated();
175 #endif
178 void EnsureRequestContextCreated() {
179 GetRequestContext();
182 // Updates the ProfileInfoCache with data from this profile.
183 void UpdateProfileSupervisedUserIdCache();
184 void UpdateProfileNameCache();
185 void UpdateProfileAvatarCache();
186 void UpdateProfileIsEphemeralCache();
188 void GetCacheParameters(bool is_media_context,
189 base::FilePath* cache_path,
190 int* max_size);
192 PrefProxyConfigTracker* CreateProxyConfigTracker();
194 scoped_ptr<domain_reliability::DomainReliabilityMonitor>
195 CreateDomainReliabilityMonitor(PrefService* local_state);
197 PrefChangeRegistrar pref_change_registrar_;
199 base::FilePath path_;
200 base::FilePath base_cache_path_;
202 // !!! BIG HONKING WARNING !!!
203 // The order of the members below is important. Do not change it unless
204 // you know what you're doing. Also, if adding a new member here make sure
205 // that the declaration occurs AFTER things it depends on as destruction
206 // happens in reverse order of declaration.
208 // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
209 // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
210 // This can be removed once |prefs_| becomes a KeyedService too.
211 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
212 // which depends on |schema_registry_service_|.
213 #if defined(ENABLE_CONFIGURATION_POLICY)
214 scoped_ptr<policy::SchemaRegistryService> schema_registry_service_;
215 scoped_ptr<policy::CloudPolicyManager> cloud_policy_manager_;
216 #endif
217 scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
219 // Keep |pref_validation_delegate_| above |prefs_| so that the former outlives
220 // the latter.
221 scoped_ptr<TrackedPreferenceValidationDelegate> pref_validation_delegate_;
223 // Keep |prefs_| on top for destruction order because |extension_prefs_|,
224 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
225 // shall be destructed first.
226 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
227 scoped_ptr<PrefServiceSyncable> prefs_;
228 scoped_ptr<PrefServiceSyncable> otr_prefs_;
229 ProfileImplIOData::Handle io_data_;
230 #if defined(ENABLE_EXTENSIONS)
231 scoped_refptr<ExtensionSpecialStoragePolicy>
232 extension_special_storage_policy_;
233 #endif
234 scoped_ptr<NetPrefObserver> net_pref_observer_;
235 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
236 scoped_refptr<ShortcutsBackend> shortcuts_backend_;
238 // Exit type the last time the profile was opened. This is set only once from
239 // prefs.
240 ExitType last_session_exit_type_;
242 #if defined(ENABLE_SESSION_SERVICE)
243 base::OneShotTimer<ProfileImpl> create_session_service_timer_;
244 #endif
246 scoped_ptr<Profile> off_the_record_profile_;
248 // See GetStartTime for details.
249 base::Time start_time_;
251 #if defined(OS_CHROMEOS)
252 scoped_ptr<chromeos::Preferences> chromeos_preferences_;
254 scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_;
255 #endif
257 scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
259 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
261 // Instead, make your Service/Manager/whatever object you're hanging off the
262 // Profile use our new BrowserContextKeyedServiceFactory system instead.
263 // You can find the design document here:
265 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
267 // and you can read the raw headers here:
269 // components/keyed_service/content/browser_context_dependency_manager.*
270 // components/keyed_service/core/keyed_service.h
271 // components/keyed_service/content/browser_context_keyed_service_factory.*
273 Profile::Delegate* delegate_;
275 chrome_browser_net::Predictor* predictor_;
277 DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
280 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_