profile_impl.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file. 4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// This class gathers state related to a single user profile. 6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 75f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#ifndef CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_ 8a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#define CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_ 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <string> 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/files/file_path.h" 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/gtest_prod_util.h" 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/ref_counted.h" 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/prefs/pref_change_registrar.h" 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/timer/timer.h" 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/profiles/profile_impl_io_data.h" 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/public/browser/content_browser_client.h" 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/public/browser/host_zoom_map.h" 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class NetPrefObserver; 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class PrefService; 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class PrefServiceSyncable; 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SSLConfigServiceManager; 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(OS_CHROMEOS) 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace chromeos { 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class LocaleChangeGuard; 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class Preferences; 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace base { 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SequencedTaskRunner; 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace extensions { 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ExtensionSystem; 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace policy { 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class CloudPolicyManager; 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ProfilePolicyConnector; 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace user_prefs { 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class refRegistrySyncable; 50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// The default profile implementation. 53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ProfileImpl : public Profile { 54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public: 555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests. 565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) static const char* const kPrefExitTypeNormal; 575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual ~ProfileImpl(); 595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // content::BrowserContext implementation: 635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual base::FilePath GetPath() const OVERRIDE; 645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual content::DownloadManagerDelegate* 655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) GetDownloadManagerDelegate() OVERRIDE; 665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; 675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( 685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int renderer_child_id) OVERRIDE; 695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; 705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( 715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int renderer_child_id) OVERRIDE; 725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual net::URLRequestContextGetter* 735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) GetMediaRequestContextForStoragePartition( 745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const base::FilePath& partition_path, 755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool in_memory) OVERRIDE; 765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void RequestMIDISysExPermission( 775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int render_process_id, 785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int render_view_id, 79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const GURL& requesting_frame, 80a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const MIDISysExPermissionCallback& callback) OVERRIDE; 81a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual content::ResourceContext* GetResourceContext() OVERRIDE; 82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual content::GeolocationPermissionContext* 83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetGeolocationPermissionContext() OVERRIDE; 84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; 85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Profile implementation: 87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE; 88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Note that this implementation returns the Google-services username, if any, 89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // not the Chrome user's display name. 90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual std::string GetProfileName() OVERRIDE; 91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual bool IsOffTheRecord() const OVERRIDE; 92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual Profile* GetOffTheRecordProfile() OVERRIDE; 93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void DestroyOffTheRecordProfile() OVERRIDE; 94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual bool HasOffTheRecordProfile() OVERRIDE; 950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual Profile* GetOriginalProfile() OVERRIDE; 96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual bool IsManaged() OVERRIDE; 97a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual history::TopSites* GetTopSites() OVERRIDE; 98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE; 99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual ExtensionService* GetExtensionService() OVERRIDE; 100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual ExtensionSpecialStoragePolicy* 101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetExtensionSpecialStoragePolicy() OVERRIDE; 102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual PrefService* GetPrefs() OVERRIDE; 103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual net::URLRequestContextGetter* 105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetRequestContextForExtensions() OVERRIDE; 106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; 107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; 108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual bool IsSameProfile(Profile* profile) OVERRIDE; 109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual base::Time GetStartTime() const OVERRIDE; 110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual net::URLRequestContextGetter* CreateRequestContext( 111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; 112 virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( 113 const base::FilePath& partition_path, 114 bool in_memory, 115 content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; 116 virtual base::FilePath last_selected_directory() OVERRIDE; 117 virtual void set_last_selected_directory(const base::FilePath& path) OVERRIDE; 118 virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE; 119 virtual void ClearNetworkingHistorySince( 120 base::Time time, 121 const base::Closure& completion) OVERRIDE; 122 virtual GURL GetHomePage() OVERRIDE; 123 virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE; 124 virtual void SetExitType(ExitType exit_type) OVERRIDE; 125 virtual ExitType GetLastSessionExitType() OVERRIDE; 126 127#if defined(OS_CHROMEOS) 128 virtual void ChangeAppLocale(const std::string& locale, 129 AppLocaleChangedVia) OVERRIDE; 130 virtual void OnLogin() OVERRIDE; 131 virtual void InitChromeOSPreferences() OVERRIDE; 132 virtual bool IsLoginProfile() OVERRIDE; 133#endif // defined(OS_CHROMEOS) 134 135 virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE; 136 137 private: 138 friend class Profile; 139 friend class BetterSessionRestoreCrashTest; 140 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, 141 ProfilesLaunchedAfterCrash); 142 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, ProfileReadmeCreated); 143 FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, 144 ProfileDeletedBeforeReadmeCreated); 145 146 // Delay, in milliseconds, before README file is created for a new profile. 147 // This is non-const for testing purposes. 148 static int create_readme_delay_ms; 149 150 ProfileImpl(const base::FilePath& path, 151 Delegate* delegate, 152 CreateMode create_mode, 153 base::SequencedTaskRunner* sequenced_task_runner); 154 155 // Does final initialization. Should be called after prefs were loaded. 156 void DoFinalInit(); 157 158 void InitHostZoomMap(); 159 160 void OnDefaultZoomLevelChanged(); 161 void OnZoomLevelChanged( 162 const content::HostZoomMap::ZoomLevelChange& change); 163 164 void OnInitializationCompleted(PrefService* pref_service, 165 bool succeeded); 166 167 // Does final prefs initialization and calls Init(). 168 void OnPrefsLoaded(bool success); 169 170 base::FilePath GetPrefFilePath(); 171 172#if defined(ENABLE_SESSION_SERVICE) 173 void StopCreateSessionServiceTimer(); 174 175 void EnsureSessionServiceCreated(); 176#endif 177 178 179 void EnsureRequestContextCreated() { 180 GetRequestContext(); 181 } 182 183 void UpdateProfileUserNameCache(); 184 185 // Updates the ProfileInfoCache with data from this profile. 186 void UpdateProfileNameCache(); 187 void UpdateProfileAvatarCache(); 188 189 void GetCacheParameters(bool is_media_context, 190 base::FilePath* cache_path, 191 int* max_size); 192 193 PrefProxyConfigTracker* CreateProxyConfigTracker(); 194 195 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; 196 PrefChangeRegistrar pref_change_registrar_; 197 198 base::FilePath path_; 199 base::FilePath base_cache_path_; 200 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. 206 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 BrowserContextKeyedService too. 210 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|. 211#if defined(ENABLE_CONFIGURATION_POLICY) 212 scoped_ptr<policy::CloudPolicyManager> cloud_policy_manager_; 213#endif 214 scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_; 215 216 // Keep |prefs_| on top for destruction order because |extension_prefs_|, 217 // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and 218 // shall be destructed first. 219 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; 220 scoped_ptr<PrefServiceSyncable> prefs_; 221 scoped_ptr<PrefServiceSyncable> otr_prefs_; 222 ProfileImplIOData::Handle io_data_; 223 scoped_refptr<ExtensionSpecialStoragePolicy> 224 extension_special_storage_policy_; 225 scoped_ptr<NetPrefObserver> net_pref_observer_; 226 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_; 227 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; 228 scoped_refptr<history::ShortcutsBackend> shortcuts_backend_; 229 230 // Exit type the last time the profile was opened. This is set only once from 231 // prefs. 232 ExitType last_session_exit_type_; 233 234#if defined(ENABLE_SESSION_SERVICE) 235 base::OneShotTimer<ProfileImpl> create_session_service_timer_; 236#endif 237 238 scoped_ptr<Profile> off_the_record_profile_; 239 240 // See GetStartTime for details. 241 base::Time start_time_; 242 243 scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails. 244 245#if defined(OS_CHROMEOS) 246 scoped_ptr<chromeos::Preferences> chromeos_preferences_; 247 248 scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_; 249 250 bool is_login_profile_; 251#endif 252 253 scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; 254 255 // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!! 256 // 257 // Instead, make your Service/Manager/whatever object you're hanging off the 258 // Profile use our new BrowserContextKeyedServiceFactory system instead. 259 // You can find the design document here: 260 // 261 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture 262 // 263 // and you can read the raw headers here: 264 // 265 // components/browser_context_keyed_service/browser_context_dependency_manager.{h,cc} 266 // components/browser_context_keyed_service/browser_context_keyed_service.h 267 // components/browser_context_keyed_service/browser_context_keyed_service_factory.{h,cc} 268 269 Profile::Delegate* delegate_; 270 271 chrome_browser_net::Predictor* predictor_; 272 273 DISALLOW_COPY_AND_ASSIGN(ProfileImpl); 274}; 275 276#endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_ 277