Home | History | Annotate | Download | only in profiles
      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 "components/domain_reliability/clear_mode.h"
     21 #include "content/public/browser/content_browser_client.h"
     22 #include "content/public/browser/host_zoom_map.h"
     23 
     24 class NetPrefObserver;
     25 class PrefService;
     26 class PrefServiceSyncable;
     27 class ShortcutsBackend;
     28 class SSLConfigServiceManager;
     29 class TrackedPreferenceValidationDelegate;
     30 
     31 #if defined(OS_CHROMEOS)
     32 namespace chromeos {
     33 class KioskTest;
     34 class LocaleChangeGuard;
     35 class ManagedUserTestBase;
     36 class Preferences;
     37 }
     38 #endif
     39 
     40 namespace base {
     41 class SequencedTaskRunner;
     42 }
     43 
     44 namespace extensions {
     45 class ExtensionSystem;
     46 }
     47 
     48 namespace policy {
     49 class CloudPolicyManager;
     50 class ProfilePolicyConnector;
     51 class SchemaRegistryService;
     52 }
     53 
     54 namespace user_prefs {
     55 class refRegistrySyncable;
     56 }
     57 
     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;
     63 
     64   virtual ~ProfileImpl();
     65 
     66   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
     67 
     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 content::ResourceContext* GetResourceContext() OVERRIDE;
     83   virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE;
     84   virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
     85   virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE;
     86 
     87   // Profile implementation:
     88   virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE;
     89   // Note that this implementation returns the Google-services username, if any,
     90   // not the Chrome user's display name.
     91   virtual std::string GetProfileName() OVERRIDE;
     92   virtual ProfileType GetProfileType() const OVERRIDE;
     93   virtual bool IsOffTheRecord() const OVERRIDE;
     94   virtual Profile* GetOffTheRecordProfile() OVERRIDE;
     95   virtual void DestroyOffTheRecordProfile() OVERRIDE;
     96   virtual bool HasOffTheRecordProfile() OVERRIDE;
     97   virtual Profile* GetOriginalProfile() OVERRIDE;
     98   virtual bool IsSupervised() OVERRIDE;
     99   virtual history::TopSites* GetTopSites() OVERRIDE;
    100   virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE;
    101   virtual ExtensionService* GetExtensionService() OVERRIDE;
    102   virtual ExtensionSpecialStoragePolicy*
    103       GetExtensionSpecialStoragePolicy() OVERRIDE;
    104   virtual PrefService* GetPrefs() OVERRIDE;
    105   virtual PrefService* GetOffTheRecordPrefs() OVERRIDE;
    106   virtual net::URLRequestContextGetter*
    107       GetRequestContextForExtensions() OVERRIDE;
    108   virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE;
    109   virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE;
    110   virtual bool IsSameProfile(Profile* profile) OVERRIDE;
    111   virtual base::Time GetStartTime() const OVERRIDE;
    112   virtual net::URLRequestContextGetter* CreateRequestContext(
    113       content::ProtocolHandlerMap* protocol_handlers,
    114       content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE;
    115   virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
    116       const base::FilePath& partition_path,
    117       bool in_memory,
    118       content::ProtocolHandlerMap* protocol_handlers,
    119       content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE;
    120   virtual base::FilePath last_selected_directory() OVERRIDE;
    121   virtual void set_last_selected_directory(const base::FilePath& path) OVERRIDE;
    122   virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE;
    123   virtual DevToolsNetworkController* GetDevToolsNetworkController() OVERRIDE;
    124   virtual void ClearNetworkingHistorySince(
    125       base::Time time,
    126       const base::Closure& completion) OVERRIDE;
    127   virtual void ClearDomainReliabilityMonitor(
    128       domain_reliability::DomainReliabilityClearMode mode,
    129       const base::Closure& completion) OVERRIDE;
    130   virtual GURL GetHomePage() OVERRIDE;
    131   virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE;
    132   virtual void SetExitType(ExitType exit_type) OVERRIDE;
    133   virtual ExitType GetLastSessionExitType() OVERRIDE;
    134 
    135 #if defined(OS_CHROMEOS)
    136   virtual void ChangeAppLocale(const std::string& locale,
    137                                AppLocaleChangedVia) OVERRIDE;
    138   virtual void OnLogin() OVERRIDE;
    139   virtual void InitChromeOSPreferences() OVERRIDE;
    140 #endif  // defined(OS_CHROMEOS)
    141 
    142   virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE;
    143 
    144  private:
    145 #if defined(OS_CHROMEOS)
    146   friend class chromeos::KioskTest;
    147   friend class chromeos::ManagedUserTestBase;
    148 #endif
    149   friend class Profile;
    150   friend class BetterSessionRestoreCrashTest;
    151   FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
    152                            ProfilesLaunchedAfterCrash);
    153   FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest, ProfileReadmeCreated);
    154   FRIEND_TEST_ALL_PREFIXES(ProfileBrowserTest,
    155                            ProfileDeletedBeforeReadmeCreated);
    156 
    157   // Delay, in milliseconds, before README file is created for a new profile.
    158   // This is non-const for testing purposes.
    159   static int create_readme_delay_ms;
    160 
    161   ProfileImpl(const base::FilePath& path,
    162               Delegate* delegate,
    163               CreateMode create_mode,
    164               base::SequencedTaskRunner* sequenced_task_runner);
    165 
    166   // Does final initialization. Should be called after prefs were loaded.
    167   void DoFinalInit();
    168 
    169   void InitHostZoomMap();
    170 
    171   void OnDefaultZoomLevelChanged();
    172   void OnZoomLevelChanged(
    173       const content::HostZoomMap::ZoomLevelChange& change);
    174 
    175   // Does final prefs initialization and calls Init().
    176   void OnPrefsLoaded(bool success);
    177 
    178 #if defined(ENABLE_SESSION_SERVICE)
    179   void StopCreateSessionServiceTimer();
    180 
    181   void EnsureSessionServiceCreated();
    182 #endif
    183 
    184 
    185   void EnsureRequestContextCreated() {
    186     GetRequestContext();
    187   }
    188 
    189   // Updates the ProfileInfoCache with data from this profile.
    190   void UpdateProfileUserNameCache();
    191   void UpdateProfileSupervisedUserIdCache();
    192   void UpdateProfileNameCache();
    193   void UpdateProfileAvatarCache();
    194   void UpdateProfileIsEphemeralCache();
    195 
    196   void GetCacheParameters(bool is_media_context,
    197                           base::FilePath* cache_path,
    198                           int* max_size);
    199 
    200   PrefProxyConfigTracker* CreateProxyConfigTracker();
    201 
    202   scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
    203   PrefChangeRegistrar pref_change_registrar_;
    204 
    205   base::FilePath path_;
    206   base::FilePath base_cache_path_;
    207 
    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.
    213 
    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 KeyedService too.
    217 // |profile_policy_connector_| in turn depends on |cloud_policy_manager_|,
    218 // which depends on |schema_registry_service_|.
    219 #if defined(ENABLE_CONFIGURATION_POLICY)
    220   scoped_ptr<policy::SchemaRegistryService> schema_registry_service_;
    221   scoped_ptr<policy::CloudPolicyManager> cloud_policy_manager_;
    222 #endif
    223   scoped_ptr<policy::ProfilePolicyConnector> profile_policy_connector_;
    224 
    225   // Keep |pref_validation_delegate_| above |prefs_| so that the former outlives
    226   // the latter.
    227   scoped_ptr<TrackedPreferenceValidationDelegate> pref_validation_delegate_;
    228 
    229   // Keep |prefs_| on top for destruction order because |extension_prefs_|,
    230   // |net_pref_observer_|, |io_data_| and others store pointers to |prefs_| and
    231   // shall be destructed first.
    232   scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
    233   scoped_ptr<PrefServiceSyncable> prefs_;
    234   scoped_ptr<PrefServiceSyncable> otr_prefs_;
    235   ProfileImplIOData::Handle io_data_;
    236   scoped_refptr<ExtensionSpecialStoragePolicy>
    237       extension_special_storage_policy_;
    238   scoped_ptr<NetPrefObserver> net_pref_observer_;
    239   scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
    240   scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
    241   scoped_refptr<ShortcutsBackend> shortcuts_backend_;
    242 
    243   // Exit type the last time the profile was opened. This is set only once from
    244   // prefs.
    245   ExitType last_session_exit_type_;
    246 
    247 #if defined(ENABLE_SESSION_SERVICE)
    248   base::OneShotTimer<ProfileImpl> create_session_service_timer_;
    249 #endif
    250 
    251   scoped_ptr<Profile> off_the_record_profile_;
    252 
    253   // See GetStartTime for details.
    254   base::Time start_time_;
    255 
    256   scoped_refptr<history::TopSites> top_sites_;  // For history and thumbnails.
    257 
    258 #if defined(OS_CHROMEOS)
    259   scoped_ptr<chromeos::Preferences> chromeos_preferences_;
    260 
    261   scoped_ptr<chromeos::LocaleChangeGuard> locale_change_guard_;
    262 
    263   bool is_login_profile_;
    264 #endif
    265 
    266   scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
    267 
    268   // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!!
    269   //
    270   // Instead, make your Service/Manager/whatever object you're hanging off the
    271   // Profile use our new BrowserContextKeyedServiceFactory system instead.
    272   // You can find the design document here:
    273   //
    274   //   https://sites.google.com/a/chromium.org/dev/developers/design-documents/profile-architecture
    275   //
    276   // and you can read the raw headers here:
    277   //
    278   // components/keyed_service/content/browser_context_dependency_manager.*
    279   // components/keyed_service/core/keyed_service.h
    280   // components/keyed_service/content/browser_context_keyed_service_factory.*
    281 
    282   Profile::Delegate* delegate_;
    283 
    284   chrome_browser_net::Predictor* predictor_;
    285 
    286   DISALLOW_COPY_AND_ASSIGN(ProfileImpl);
    287 };
    288 
    289 #endif  // CHROME_BROWSER_PROFILES_PROFILE_IMPL_H_
    290