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 "content/public/browser/content_browser_client.h"
21 #include "content/public/browser/host_zoom_map.h"
23 class NetPrefObserver;
25 class PrefServiceSyncable;
26 class SSLConfigServiceManager;
28 #if defined(OS_CHROMEOS)
30 class LocaleChangeGuard;
36 class SequencedTaskRunner;
39 namespace extensions {
40 class ExtensionSystem;
44 class CloudPolicyManager;
45 class ProfilePolicyConnector;
48 namespace user_prefs {
49 class refRegistrySyncable;
52 // The default profile implementation.
53 class ProfileImpl : public Profile {
55 // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests.
56 static const char* const kPrefExitTypeNormal;
58 virtual ~ProfileImpl();
60 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
62 // content::BrowserContext implementation:
63 virtual base::FilePath GetPath() const OVERRIDE;
64 virtual content::DownloadManagerDelegate*
65 GetDownloadManagerDelegate() OVERRIDE;
66 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
67 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
68 int renderer_child_id) OVERRIDE;
69 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
70 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
71 int renderer_child_id) OVERRIDE;
72 virtual net::URLRequestContextGetter*
73 GetMediaRequestContextForStoragePartition(
74 const base::FilePath& partition_path,
75 bool in_memory) OVERRIDE;
76 virtual void RequestMIDISysExPermission(
77 int render_process_id,
80 const GURL& requesting_frame,
81 const MIDISysExPermissionCallback& callback) OVERRIDE;
82 virtual void CancelMIDISysExPermissionRequest(
83 int render_process_id,
86 const GURL& requesting_frame) OVERRIDE;
87 virtual content::ResourceContext* GetResourceContext() OVERRIDE;
88 virtual content::GeolocationPermissionContext*
89 GetGeolocationPermissionContext() OVERRIDE;
90 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
92 // Profile implementation:
93 virtual 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 virtual std::string GetProfileName() OVERRIDE;
97 virtual bool IsOffTheRecord() const OVERRIDE;
98 virtual Profile* GetOffTheRecordProfile() OVERRIDE;
99 virtual void DestroyOffTheRecordProfile() OVERRIDE;
100 virtual bool HasOffTheRecordProfile() OVERRIDE;
101 virtual Profile* GetOriginalProfile() OVERRIDE;
102 virtual bool IsManaged() OVERRIDE;
103 virtual history::TopSites* GetTopSites() OVERRIDE;
104 virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE;
105 virtual ExtensionService* GetExtensionService() OVERRIDE;
106 virtual ExtensionSpecialStoragePolicy*
107 GetExtensionSpecialStoragePolicy() OVERRIDE;
108 virtual PrefService* GetPrefs() OVERRIDE;
109 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
110 virtual net::URLRequestContextGetter*
111 GetRequestContextForExtensions() OVERRIDE;
112 virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE;
113 virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE;
114 virtual bool IsSameProfile(Profile* profile) OVERRIDE;
115 virtual base::Time GetStartTime() const OVERRIDE;
116 virtual net::URLRequestContextGetter* CreateRequestContext(
117 content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
118 virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
119 const base::FilePath& partition_path,
121 content::ProtocolHandlerMap* protocol_handlers) OVERRIDE;
122 virtual base::FilePath last_selected_directory() OVERRIDE;
123 virtual void set_last_selected_directory(const base::FilePath& path) OVERRIDE;
124 virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE;
125 virtual void ClearNetworkingHistorySince(
127 const base::Closure& completion) OVERRIDE;
128 virtual GURL GetHomePage() OVERRIDE;
129 virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
130 virtual void SetExitType(ExitType exit_type) OVERRIDE;
131 virtual ExitType GetLastSessionExitType() OVERRIDE;
133 #if defined(OS_CHROMEOS)
134 virtual void ChangeAppLocale(const std::string& locale,
135 AppLocaleChangedVia) OVERRIDE;
136 virtual void OnLogin() OVERRIDE;
137 virtual void InitChromeOSPreferences() OVERRIDE;
138 virtual bool IsLoginProfile() OVERRIDE;
139 #endif // defined(OS_CHROMEOS)
141 virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE;
144 friend class Profile;
145 friend class BetterSessionRestoreCrashTest;
146 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
147 ProfilesLaunchedAfterCrash);
148 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, ProfileReadmeCreated);
149 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest,
150 ProfileDeletedBeforeReadmeCreated);
152 // Delay, in milliseconds, before README file is created for a new profile.
153 // This is non-const for testing purposes.
154 static int create_readme_delay_ms;
156 ProfileImpl(const base::FilePath& path,
158 CreateMode create_mode,
159 base::SequencedTaskRunner* sequenced_task_runner);
161 // Does final initialization. Should be called after prefs were loaded.
164 void InitHostZoomMap();
166 void OnDefaultZoomLevelChanged();
167 void OnZoomLevelChanged(
168 const content::HostZoomMap::ZoomLevelChange& change);
170 void OnInitializationCompleted(PrefService* pref_service,
173 // Does final prefs initialization and calls Init().
174 void OnPrefsLoaded(bool success);
176 base::FilePath GetPrefFilePath();
178 #if defined(ENABLE_SESSION_SERVICE)
179 void StopCreateSessionServiceTimer();
181 void EnsureSessionServiceCreated();
185 void EnsureRequestContextCreated() {
189 void UpdateProfileUserNameCache();
191 // Updates the ProfileInfoCache with data from this profile.
192 void UpdateProfileNameCache();
193 void UpdateProfileAvatarCache();
194 void UpdateProfileIsEphemeralCache();
196 void GetCacheParameters(bool is_media_context,
197 base::FilePath* cache_path,
200 PrefProxyConfigTracker* CreateProxyConfigTracker();
202 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
203 PrefChangeRegistrar pref_change_registrar_;
205 base::FilePath path_;
206 base::FilePath base_cache_path_;
208 // !!! BIG HONKING WARNING !!!
209 // The order of the members below is important. Do not change it unless
210 // you know what you're doing. Also, if adding a new member here make sure
211 // that the declaration occurs AFTER things it depends on as destruction
212 // happens in reverse order of declaration.
214 // TODO(mnissler, joaodasilva): The |profile_policy_connector_| provides the
215 // PolicyService that the |prefs_| depend on, and must outlive |prefs_|.
216 // This can be removed once |prefs_| becomes a BrowserContextKeyedService too.
217 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|.
218 #if defined(ENABLE_CONFIGURATION_POLICY)
219 scoped_ptr<policy::CloudPolicyManager> cloud_policy_manager_;
221 scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
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 scoped_refptr<ExtensionSpecialStoragePolicy>
231 extension_special_storage_policy_;
232 scoped_ptr<NetPrefObserver> net_pref_observer_;
233 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
234 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
235 scoped_refptr<history::ShortcutsBackend> shortcuts_backend_;
237 // Exit type the last time the profile was opened. This is set only once from
239 ExitType last_session_exit_type_;
241 #if defined(ENABLE_SESSION_SERVICE)
242 base::OneShotTimer<ProfileImpl> create_session_service_timer_;
245 scoped_ptr<Profile> off_the_record_profile_;
247 // See GetStartTime for details.
248 base::Time start_time_;
250 scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails.
252 #if defined(OS_CHROMEOS)
253 scoped_ptr<chromeos::Preferences> chromeos_preferences_;
255 scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_;
257 bool is_login_profile_;
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/browser_context_keyed_service/browser_context_dependency_manager.{h,cc}
273 // components/browser_context_keyed_service/browser_context_keyed_service.h
274 // components/browser_context_keyed_service/browser_context_keyed_service_factory.{h,cc}
276 Profile::Delegate* delegate_;
278 chrome_browser_net::Predictor* predictor_;
280 DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
283 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_