EME test page application.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_impl.h
blob5a79369119abfa09cc1900582543f72b0f363b71
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 "components/domain_reliability/clear_mode.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 ManagedUserTestBase;
36 class Preferences;
38 #endif
40 namespace base {
41 class SequencedTaskRunner;
44 namespace extensions {
45 class ExtensionSystem;
48 namespace policy {
49 class CloudPolicyManager;
50 class ProfilePolicyConnector;
51 class SchemaRegistryService;
54 namespace user_prefs {
55 class refRegistrySyncable;
58 // The default profile implementation.
59 class ProfileImpl : public Profile {
60 public:
61 // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
62 static const char* const kPrefExitTypeNormal;
64 virtual ~ProfileImpl();
66 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
68 // content::BrowserContext implementation:
69 virtual base::FilePath GetPath() const OVERRIDE;
70 virtual content::DownloadManagerDelegate*
71 GetDownloadManagerDelegate() OVERRIDE;
72 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
73 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
74 int renderer_child_id) OVERRIDE;
75 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
76 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
77 int renderer_child_id) OVERRIDE;
78 virtual net::URLRequestContextGetter*
79 GetMediaRequestContextForStoragePartition(
80 const base::FilePath& partition_path,
81 bool in_memory) OVERRIDE;
82 virtual void RequestMidiSysExPermission(
83 int render_process_id,
84 int render_view_id,
85 int bridge_id,
86 const GURL& requesting_frame,
87 bool user_gesture,
88 const MidiSysExPermissionCallback& callback) OVERRIDE;
89 virtual void CancelMidiSysExPermissionRequest(
90 int render_process_id,
91 int render_view_id,
92 int bridge_id,
93 const GURL& requesting_frame) OVERRIDE;
94 virtual void RequestProtectedMediaIdentifierPermission(
95 int render_process_id,
96 int render_view_id,
97 int bridge_id,
98 int group_id,
99 const GURL& requesting_frame,
100 const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE;
101 virtual void CancelProtectedMediaIdentifierPermissionRequests(
102 int group_id) OVERRIDE;
103 virtual content::ResourceContext* GetResourceContext() OVERRIDE;
104 virtual content::GeolocationPermissionContext*
105 GetGeolocationPermissionContext() OVERRIDE;
106 virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE;
107 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
109 // Profile implementation:
110 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE;
111 // Note that this implementation returns the Google-services username, if any,
112 // not the Chrome user's display name.
113 virtual std::string GetProfileName() OVERRIDE;
114 virtual ProfileType GetProfileType() const OVERRIDE;
115 virtual bool IsOffTheRecord() const OVERRIDE;
116 virtual Profile* GetOffTheRecordProfile() OVERRIDE;
117 virtual void DestroyOffTheRecordProfile() OVERRIDE;
118 virtual bool HasOffTheRecordProfile() OVERRIDE;
119 virtual Profile* GetOriginalProfile() OVERRIDE;
120 virtual bool IsManaged() OVERRIDE;
121 virtual history::TopSites* GetTopSites() OVERRIDE;
122 virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE;
123 virtual ExtensionService* GetExtensionService() OVERRIDE;
124 virtual ExtensionSpecialStoragePolicy*
125 GetExtensionSpecialStoragePolicy() OVERRIDE;
126 virtual PrefService* GetPrefs() OVERRIDE;
127 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
128 virtual net::URLRequestContextGetter*
129 GetRequestContextForExtensions() OVERRIDE;
130 virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE;
131 virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE;
132 virtual bool IsSameProfile(Profile* profile) OVERRIDE;
133 virtual base::Time GetStartTime() const OVERRIDE;
134 virtual net::URLRequestContextGetter* CreateRequestContext(
135 content::ProtocolHandlerMap* protocol_handlers,
136 content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE;
137 virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
138 const base::FilePath& partition_path,
139 bool in_memory,
140 content::ProtocolHandlerMap* protocol_handlers,
141 content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE;
142 virtual base::FilePath last_selected_directory() OVERRIDE;
143 virtual void set_last_selected_directory(const base::FilePath& path) OVERRIDE;
144 virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE;
145 virtual void ClearNetworkingHistorySince(
146 base::Time time,
147 const base::Closure& completion) OVERRIDE;
148 virtual void ClearDomainReliabilityMonitor(
149 domain_reliability::DomainReliabilityClearMode mode,
150 const base::Closure& completion) OVERRIDE;
151 virtual GURL GetHomePage() OVERRIDE;
152 virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
153 virtual void SetExitType(ExitType exit_type) OVERRIDE;
154 virtual ExitType GetLastSessionExitType() OVERRIDE;
156 #if defined(OS_CHROMEOS)
157 virtual void ChangeAppLocale(const std::string& locale,
158 AppLocaleChangedVia) OVERRIDE;
159 virtual void OnLogin() OVERRIDE;
160 virtual void InitChromeOSPreferences() OVERRIDE;
161 #endif // defined(OS_CHROMEOS)
163 virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE;
165 private:
166 #if defined(OS_CHROMEOS)
167 friend class chromeos::KioskTest;
168 friend class chromeos::ManagedUserTestBase;
169 #endif
170 friend class Profile;
171 friend class BetterSessionRestoreCrashTest;
172 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
173 ProfilesLaunchedAfterCrash);
174 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, ProfileReadmeCreated);
175 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest,
176 ProfileDeletedBeforeReadmeCreated);
178 // Delay, in milliseconds, before README file is created for a new profile.
179 // This is non-const for testing purposes.
180 static int create_readme_delay_ms;
182 ProfileImpl(const base::FilePath& path,
183 Delegate* delegate,
184 CreateMode create_mode,
185 base::SequencedTaskRunner* sequenced_task_runner);
187 // Does final initialization. Should be called after prefs were loaded.
188 void DoFinalInit();
190 void InitHostZoomMap();
192 void OnDefaultZoomLevelChanged();
193 void OnZoomLevelChanged(
194 const content::HostZoomMap::ZoomLevelChange& change);
196 // Does final prefs initialization and calls Init().
197 void OnPrefsLoaded(bool success);
199 #if defined(ENABLE_SESSION_SERVICE)
200 void StopCreateSessionServiceTimer();
202 void EnsureSessionServiceCreated();
203 #endif
206 void EnsureRequestContextCreated() {
207 GetRequestContext();
210 // Updates the ProfileInfoCache with data from this profile.
211 void UpdateProfileUserNameCache();
212 void UpdateProfileManagedUserIdCache();
213 void UpdateProfileNameCache();
214 void UpdateProfileAvatarCache();
215 void UpdateProfileIsEphemeralCache();
217 void GetCacheParameters(bool is_media_context,
218 base::FilePath* cache_path,
219 int* max_size);
221 PrefProxyConfigTracker* CreateProxyConfigTracker();
223 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
224 PrefChangeRegistrar pref_change_registrar_;
226 base::FilePath path_;
227 base::FilePath base_cache_path_;
229 // !!! BIG HONKING WARNING !!!
230 // The order of the members below is important. Do not change it unless
231 // you know what you're doing. Also, if adding a new member here make sure
232 // that the declaration occurs AFTER things it depends on as destruction
233 // happens in reverse order of declaration.
235 // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
236 // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
237 // This can be removed once |prefs_| becomes a KeyedService too.
238 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
239 // which depends on |schema_registry_service_|.
240 #if defined(ENABLE_CONFIGURATION_POLICY)
241 scoped_ptr<policy::SchemaRegistryService> schema_registry_service_;
242 scoped_ptr<policy::CloudPolicyManager> cloud_policy_manager_;
243 #endif
244 scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
246 // Keep |pref_validation_delegate_| above |prefs_| so that the former outlives
247 // the latter.
248 scoped_ptr<TrackedPreferenceValidationDelegate> pref_validation_delegate_;
250 // Keep |prefs_| on top for destruction order because |extension_prefs_|,
251 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
252 // shall be destructed first.
253 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
254 scoped_ptr<PrefServiceSyncable> prefs_;
255 scoped_ptr<PrefServiceSyncable> otr_prefs_;
256 ProfileImplIOData::Handle io_data_;
257 scoped_refptr<ExtensionSpecialStoragePolicy>
258 extension_special_storage_policy_;
259 scoped_ptr<NetPrefObserver> net_pref_observer_;
260 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
261 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
262 scoped_refptr<ShortcutsBackend> shortcuts_backend_;
264 // Exit type the last time the profile was opened. This is set only once from
265 // prefs.
266 ExitType last_session_exit_type_;
268 #if defined(ENABLE_SESSION_SERVICE)
269 base::OneShotTimer<ProfileImpl> create_session_service_timer_;
270 #endif
272 scoped_ptr<Profile> off_the_record_profile_;
274 // See GetStartTime for details.
275 base::Time start_time_;
277 scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails.
279 #if defined(OS_CHROMEOS)
280 scoped_ptr<chromeos::Preferences> chromeos_preferences_;
282 scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_;
284 bool is_login_profile_;
285 #endif
287 scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
289 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
291 // Instead, make your Service/Manager/whatever object you're hanging off the
292 // Profile use our new BrowserContextKeyedServiceFactory system instead.
293 // You can find the design document here:
295 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
297 // and you can read the raw headers here:
299 // components/keyed_service/content/browser_context_dependency_manager.*
300 // components/keyed_service/core/keyed_service.h
301 // components/keyed_service/content/browser_context_keyed_service_factory.*
303 Profile::Delegate* delegate_;
305 chrome_browser_net::Predictor* predictor_;
307 DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
310 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_