Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_impl.h
blobc66f14006ac99cdd6d19a6226b785ff92d3df577
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;
92 // Profile implementation:
93 scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override;
94 // Note that this implementation returns the Google-services username, if any,
95 // not the Chrome user's display name.
96 std::string GetProfileUserName() const override;
97 ProfileType GetProfileType() const override;
98 bool IsOffTheRecord() const override;
99 Profile* GetOffTheRecordProfile() override;
100 void DestroyOffTheRecordProfile() override;
101 bool HasOffTheRecordProfile() override;
102 Profile* GetOriginalProfile() override;
103 bool IsSupervised() override;
104 bool IsChild() override;
105 bool IsLegacySupervised() override;
106 ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() override;
107 PrefService* GetPrefs() override;
108 const PrefService* GetPrefs() const override;
109 chrome::ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
110 PrefService* GetOffTheRecordPrefs() override;
111 net::URLRequestContextGetter* GetRequestContextForExtensions() override;
112 net::SSLConfigService* GetSSLConfigService() override;
113 HostContentSettingsMap* GetHostContentSettingsMap() override;
114 bool IsSameProfile(Profile* profile) override;
115 base::Time GetStartTime() const override;
116 net::URLRequestContextGetter* CreateRequestContext(
117 content::ProtocolHandlerMap* protocol_handlers,
118 content::URLRequestInterceptorScopedVector request_interceptors) override;
119 net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
120 const base::FilePath& partition_path,
121 bool in_memory,
122 content::ProtocolHandlerMap* protocol_handlers,
123 content::URLRequestInterceptorScopedVector request_interceptors) override;
124 base::FilePath last_selected_directory() override;
125 void set_last_selected_directory(const base::FilePath& path) override;
126 chrome_browser_net::Predictor* GetNetworkPredictor() override;
127 DevToolsNetworkController* GetDevToolsNetworkController() override;
128 void ClearNetworkingHistorySince(base::Time time,
129 const base::Closure& completion) override;
130 GURL GetHomePage() override;
131 bool WasCreatedByVersionOrLater(const std::string& version) override;
132 void SetExitType(ExitType exit_type) override;
133 ExitType GetLastSessionExitType() override;
135 #if defined(OS_CHROMEOS)
136 void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override;
137 void OnLogin() override;
138 void InitChromeOSPreferences() override;
139 #endif // defined(OS_CHROMEOS)
141 PrefProxyConfigTracker* GetProxyConfigTracker() override;
143 private:
144 #if defined(OS_CHROMEOS)
145 friend class chromeos::KioskTest;
146 friend class chromeos::SupervisedUserTestBase;
147 #endif
148 friend class Profile;
149 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
150 ProfilesLaunchedAfterCrash);
151 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, DISABLED_ProfileReadmeCreated);
152 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest,
153 ProfileDeletedBeforeReadmeCreated);
155 // Delay, in milliseconds, before README file is created for a new profile.
156 // This is non-const for testing purposes.
157 static int create_readme_delay_ms;
159 ProfileImpl(const base::FilePath& path,
160 Delegate* delegate,
161 CreateMode create_mode,
162 base::SequencedTaskRunner* sequenced_task_runner);
164 // Does final initialization. Should be called after prefs were loaded.
165 void DoFinalInit();
167 // Does final prefs initialization and calls Init().
168 void OnPrefsLoaded(bool success);
170 #if defined(ENABLE_SESSION_SERVICE)
171 void StopCreateSessionServiceTimer();
173 void EnsureSessionServiceCreated();
174 #endif
177 void EnsureRequestContextCreated() {
178 GetRequestContext();
181 // Updates the ProfileInfoCache with data from this profile.
182 void UpdateProfileSupervisedUserIdCache();
183 void UpdateProfileNameCache();
184 void UpdateProfileAvatarCache();
185 void UpdateProfileIsEphemeralCache();
187 void GetCacheParameters(bool is_media_context,
188 base::FilePath* cache_path,
189 int* max_size);
191 PrefProxyConfigTracker* CreateProxyConfigTracker();
193 scoped_ptr<domain_reliability::DomainReliabilityMonitor>
194 CreateDomainReliabilityMonitor(PrefService* local_state);
196 PrefChangeRegistrar pref_change_registrar_;
198 base::FilePath path_;
199 base::FilePath base_cache_path_;
201 // !!! BIG HONKING WARNING !!!
202 // The order of the members below is important. Do not change it unless
203 // you know what you're doing. Also, if adding a new member here make sure
204 // that the declaration occurs AFTER things it depends on as destruction
205 // happens in reverse order of declaration.
207 // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
208 // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
209 // This can be removed once |prefs_| becomes a KeyedService too.
210 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
211 // which depends on |schema_registry_service_|.
212 #if defined(ENABLE_CONFIGURATION_POLICY)
213 scoped_ptr<policy::SchemaRegistryService> schema_registry_service_;
214 scoped_ptr<policy::CloudPolicyManager> cloud_policy_manager_;
215 #endif
216 scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
218 // Keep |pref_validation_delegate_| above |prefs_| so that the former outlives
219 // the latter.
220 scoped_ptr<TrackedPreferenceValidationDelegate> pref_validation_delegate_;
222 // Keep |prefs_| on top for destruction order because |extension_prefs_|,
223 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
224 // shall be destructed first.
225 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
226 scoped_ptr<PrefServiceSyncable> prefs_;
227 scoped_ptr<PrefServiceSyncable> otr_prefs_;
228 ProfileImplIOData::Handle io_data_;
229 #if defined(ENABLE_EXTENSIONS)
230 scoped_refptr<ExtensionSpecialStoragePolicy>
231 extension_special_storage_policy_;
232 #endif
233 scoped_ptr<NetPrefObserver> net_pref_observer_;
234 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
235 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
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_;
256 bool is_login_profile_;
257 #endif
259 scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
261 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
263 // Instead, make your Service/Manager/whatever object you're hanging off the
264 // Profile use our new BrowserContextKeyedServiceFactory system instead.
265 // You can find the design document here:
267 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
269 // and you can read the raw headers here:
271 // components/keyed_service/content/browser_context_dependency_manager.*
272 // components/keyed_service/core/keyed_service.h
273 // components/keyed_service/content/browser_context_keyed_service_factory.*
275 Profile::Delegate* delegate_;
277 chrome_browser_net::Predictor* predictor_;
279 DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
282 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_