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#ifndef CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IMPL_H_ 6#define CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IMPL_H_ 7 8#include <string> 9 10#include "base/gtest_prod_util.h" 11#include "chrome/browser/profiles/off_the_record_profile_io_data.h" 12#include "chrome/browser/profiles/profile.h" 13#include "chrome/browser/ui/browser_list.h" 14#include "components/domain_reliability/clear_mode.h" 15#include "content/public/browser/content_browser_client.h" 16#include "content/public/browser/host_zoom_map.h" 17 18using base::Time; 19using base::TimeDelta; 20 21class PrefServiceSyncable; 22 23//////////////////////////////////////////////////////////////////////////////// 24// 25// OffTheRecordProfileImpl is a profile subclass that wraps an existing profile 26// to make it suitable for the incognito mode. 27// 28// Note: This class is a leaf class and is not intended for subclassing. 29// Providing this header file is for unit testing. 30// 31//////////////////////////////////////////////////////////////////////////////// 32class OffTheRecordProfileImpl : public Profile { 33 public: 34 explicit OffTheRecordProfileImpl(Profile* real_profile); 35 virtual ~OffTheRecordProfileImpl(); 36 void Init(); 37 38 // Profile implementation. 39 virtual std::string GetProfileName() OVERRIDE; 40 virtual ProfileType GetProfileType() const OVERRIDE; 41 virtual Profile* GetOffTheRecordProfile() OVERRIDE; 42 virtual void DestroyOffTheRecordProfile() OVERRIDE; 43 virtual bool HasOffTheRecordProfile() OVERRIDE; 44 virtual Profile* GetOriginalProfile() OVERRIDE; 45 virtual bool IsSupervised() OVERRIDE; 46 virtual ExtensionSpecialStoragePolicy* 47 GetExtensionSpecialStoragePolicy() OVERRIDE; 48 virtual PrefService* GetPrefs() OVERRIDE; 49 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; 50 virtual net::URLRequestContextGetter* 51 GetRequestContextForExtensions() OVERRIDE; 52 virtual net::URLRequestContextGetter* CreateRequestContext( 53 content::ProtocolHandlerMap* protocol_handlers, 54 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE; 55 virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( 56 const base::FilePath& partition_path, 57 bool in_memory, 58 content::ProtocolHandlerMap* protocol_handlers, 59 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE; 60 virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; 61 virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; 62 virtual bool IsSameProfile(Profile* profile) OVERRIDE; 63 virtual Time GetStartTime() const OVERRIDE; 64 virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE; 65 virtual history::TopSites* GetTopSites() OVERRIDE; 66 virtual base::FilePath last_selected_directory() OVERRIDE; 67 virtual void set_last_selected_directory(const base::FilePath& path) OVERRIDE; 68 virtual bool WasCreatedByVersionOrLater(const std::string& version) OVERRIDE; 69 virtual void SetExitType(ExitType exit_type) OVERRIDE; 70 virtual ExitType GetLastSessionExitType() OVERRIDE; 71 72#if defined(OS_CHROMEOS) 73 virtual void ChangeAppLocale(const std::string& locale, 74 AppLocaleChangedVia) OVERRIDE; 75 virtual void OnLogin() OVERRIDE; 76 virtual void InitChromeOSPreferences() OVERRIDE; 77#endif // defined(OS_CHROMEOS) 78 79 virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE; 80 81 virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE; 82 virtual DevToolsNetworkController* GetDevToolsNetworkController() OVERRIDE; 83 virtual void ClearNetworkingHistorySince( 84 base::Time time, 85 const base::Closure& completion) OVERRIDE; 86 virtual GURL GetHomePage() OVERRIDE; 87 88 // content::BrowserContext implementation: 89 virtual base::FilePath GetPath() const OVERRIDE; 90 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE; 91 virtual bool IsOffTheRecord() const OVERRIDE; 92 virtual content::DownloadManagerDelegate* 93 GetDownloadManagerDelegate() OVERRIDE; 94 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; 95 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( 96 int renderer_child_id) OVERRIDE; 97 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; 98 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( 99 int renderer_child_id) OVERRIDE; 100 virtual net::URLRequestContextGetter* 101 GetMediaRequestContextForStoragePartition( 102 const base::FilePath& partition_path, 103 bool in_memory) OVERRIDE; 104 virtual content::ResourceContext* GetResourceContext() OVERRIDE; 105 virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE; 106 virtual storage::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; 107 virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE; 108 virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() OVERRIDE; 109 110 private: 111 FRIEND_TEST_ALL_PREFIXES(OffTheRecordProfileImplTest, GetHostZoomMap); 112 void InitIoData(); 113 void InitHostZoomMap(); 114 115#if defined(OS_ANDROID) || defined(OS_IOS) 116 void UseSystemProxy(); 117#endif // defined(OS_ANDROID) || defined(OS_IOS) 118 119 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); 120 PrefProxyConfigTracker* CreateProxyConfigTracker(); 121 122 // The real underlying profile. 123 Profile* profile_; 124 125 // Weak pointer owned by |profile_|. 126 PrefServiceSyncable* prefs_; 127 128 scoped_ptr<OffTheRecordProfileIOData::Handle> io_data_; 129 130 // We use a non-persistent content settings map for OTR. 131 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; 132 133 // Time we were started. 134 Time start_time_; 135 136 base::FilePath last_selected_directory_; 137 138 scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; 139 140 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; 141 142 DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); 143}; 144 145#endif // CHROME_BROWSER_PROFILES_OFF_THE_RECORD_PROFILE_IMPL_H_ 146