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