profile_impl_io_data.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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_PROFILE_IMPL_IO_DATA_H_ 6#define CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_ 7 8#include "base/basictypes.h" 9#include "base/callback.h" 10#include "base/containers/hash_tables.h" 11#include "base/memory/ref_counted.h" 12#include "chrome/browser/custom_handlers/protocol_handler_registry.h" 13#include "chrome/browser/net/chrome_url_request_context_getter.h" 14#include "chrome/browser/profiles/profile_io_data.h" 15#include "content/public/browser/cookie_store_factory.h" 16 17namespace chrome_browser_net { 18class Predictor; 19} // namespace chrome_browser_net 20 21namespace content { 22class CookieCryptoDelegate; 23} // namespace content 24 25#if defined(SPDY_PROXY_AUTH_ORIGIN) 26namespace data_reduction_proxy { 27class DataReductionProxyParams; 28class DataReductionProxyUsageStats; 29class DataReductionProxyAuthRequestHandler; 30} 31#endif 32 33namespace domain_reliability { 34class DomainReliabilityMonitor; 35} // namespace domain_reliability 36 37namespace net { 38class FtpTransactionFactory; 39class HttpServerProperties; 40class HttpServerPropertiesManager; 41class HttpTransactionFactory; 42class ProxyConfig; 43class SDCHManager; 44} // namespace net 45 46namespace storage { 47class SpecialStoragePolicy; 48} // namespace storage 49 50class DataReductionProxyChromeConfigurator; 51 52class ProfileImplIOData : public ProfileIOData { 53 public: 54 class Handle { 55 public: 56 explicit Handle(Profile* profile); 57 ~Handle(); 58 59 // Init() must be called before ~Handle(). It records most of the 60 // parameters needed to construct a ChromeURLRequestContextGetter. 61 void Init( 62 const base::FilePath& cookie_path, 63 const base::FilePath& channel_id_path, 64 const base::FilePath& cache_path, 65 int cache_max_size, 66 const base::FilePath& media_cache_path, 67 int media_cache_max_size, 68 const base::FilePath& extensions_cookie_path, 69 const base::FilePath& profile_path, 70 const base::FilePath& infinite_cache_path, 71 chrome_browser_net::Predictor* predictor, 72 content::CookieStoreConfig::SessionCookieMode session_cookie_mode, 73 storage::SpecialStoragePolicy* special_storage_policy, 74 scoped_ptr<domain_reliability::DomainReliabilityMonitor> 75 domain_reliability_monitor, 76 const base::Callback<void(bool)>& data_reduction_proxy_unavailable, 77 scoped_ptr<DataReductionProxyChromeConfigurator> 78 data_reduction_proxy_chrome_configurator, 79 scoped_ptr<data_reduction_proxy::DataReductionProxyParams> 80 data_reduction_proxy_params); 81 82 // These Create*ContextGetter() functions are only exposed because the 83 // circular relationship between Profile, ProfileIOData::Handle, and the 84 // ChromeURLRequestContextGetter factories requires Profile be able to call 85 // these functions. 86 scoped_refptr<ChromeURLRequestContextGetter> CreateMainRequestContextGetter( 87 content::ProtocolHandlerMap* protocol_handlers, 88 content::URLRequestInterceptorScopedVector request_interceptors, 89 PrefService* local_state, 90 IOThread* io_thread) const; 91 scoped_refptr<ChromeURLRequestContextGetter> 92 CreateIsolatedAppRequestContextGetter( 93 const base::FilePath& partition_path, 94 bool in_memory, 95 content::ProtocolHandlerMap* protocol_handlers, 96 content::URLRequestInterceptorScopedVector 97 request_interceptors) const; 98 99 content::ResourceContext* GetResourceContext() const; 100 // GetResourceContextNoInit() does not call LazyInitialize() so it can be 101 // safely be used during initialization. 102 content::ResourceContext* GetResourceContextNoInit() const; 103 scoped_refptr<ChromeURLRequestContextGetter> 104 GetMediaRequestContextGetter() const; 105 scoped_refptr<ChromeURLRequestContextGetter> 106 GetExtensionsRequestContextGetter() const; 107 scoped_refptr<ChromeURLRequestContextGetter> 108 GetIsolatedMediaRequestContextGetter( 109 const base::FilePath& partition_path, 110 bool in_memory) const; 111 112 // Returns the DevToolsNetworkController attached to ProfileIOData. 113 DevToolsNetworkController* GetDevToolsNetworkController() const; 114 115 // Deletes all network related data since |time|. It deletes transport 116 // security state since |time| and also deletes HttpServerProperties data. 117 // Works asynchronously, however if the |completion| callback is non-null, 118 // it will be posted on the UI thread once the removal process completes. 119 void ClearNetworkingHistorySince(base::Time time, 120 const base::Closure& completion); 121 122 private: 123 typedef std::map<StoragePartitionDescriptor, 124 scoped_refptr<ChromeURLRequestContextGetter>, 125 StoragePartitionDescriptorLess> 126 ChromeURLRequestContextGetterMap; 127 128 // Lazily initialize ProfileParams. We do this on the calls to 129 // Get*RequestContextGetter(), so we only initialize ProfileParams right 130 // before posting a task to the IO thread to start using them. This prevents 131 // objects that are supposed to be deleted on the IO thread, but are created 132 // on the UI thread from being unnecessarily initialized. 133 void LazyInitialize() const; 134 135 // Collect references to context getters in reverse order, i.e. last item 136 // will be main request getter. This list is passed to |io_data_| 137 // for invalidation on IO thread. 138 scoped_ptr<ChromeURLRequestContextGetterVector> GetAllContextGetters(); 139 140 // The getters will be invalidated on the IO thread before 141 // ProfileIOData instance is deleted. 142 mutable scoped_refptr<ChromeURLRequestContextGetter> 143 main_request_context_getter_; 144 mutable scoped_refptr<ChromeURLRequestContextGetter> 145 media_request_context_getter_; 146 mutable scoped_refptr<ChromeURLRequestContextGetter> 147 extensions_request_context_getter_; 148 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_; 149 mutable ChromeURLRequestContextGetterMap 150 isolated_media_request_context_getter_map_; 151 ProfileImplIOData* const io_data_; 152 153 Profile* const profile_; 154 155 mutable bool initialized_; 156 157 DISALLOW_COPY_AND_ASSIGN(Handle); 158 }; 159 160 private: 161 friend class base::RefCountedThreadSafe<ProfileImplIOData>; 162 163 struct LazyParams { 164 LazyParams(); 165 ~LazyParams(); 166 167 // All of these parameters are intended to be read on the IO thread. 168 base::FilePath cookie_path; 169 base::FilePath channel_id_path; 170 base::FilePath cache_path; 171 int cache_max_size; 172 base::FilePath media_cache_path; 173 int media_cache_max_size; 174 base::FilePath extensions_cookie_path; 175 base::FilePath infinite_cache_path; 176 content::CookieStoreConfig::SessionCookieMode session_cookie_mode; 177 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy; 178 }; 179 180 ProfileImplIOData(); 181 virtual ~ProfileImplIOData(); 182 183 virtual void InitializeInternal( 184 ProfileParams* profile_params, 185 content::ProtocolHandlerMap* protocol_handlers, 186 content::URLRequestInterceptorScopedVector request_interceptors) 187 const OVERRIDE; 188 virtual void InitializeExtensionsRequestContext( 189 ProfileParams* profile_params) const OVERRIDE; 190 virtual net::URLRequestContext* InitializeAppRequestContext( 191 net::URLRequestContext* main_context, 192 const StoragePartitionDescriptor& partition_descriptor, 193 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 194 protocol_handler_interceptor, 195 content::ProtocolHandlerMap* protocol_handlers, 196 content::URLRequestInterceptorScopedVector request_interceptors) 197 const OVERRIDE; 198 virtual net::URLRequestContext* InitializeMediaRequestContext( 199 net::URLRequestContext* original_context, 200 const StoragePartitionDescriptor& partition_descriptor) const OVERRIDE; 201 virtual net::URLRequestContext* 202 AcquireMediaRequestContext() const OVERRIDE; 203 virtual net::URLRequestContext* AcquireIsolatedAppRequestContext( 204 net::URLRequestContext* main_context, 205 const StoragePartitionDescriptor& partition_descriptor, 206 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 207 protocol_handler_interceptor, 208 content::ProtocolHandlerMap* protocol_handlers, 209 content::URLRequestInterceptorScopedVector request_interceptors) 210 const OVERRIDE; 211 virtual net::URLRequestContext* 212 AcquireIsolatedMediaRequestContext( 213 net::URLRequestContext* app_context, 214 const StoragePartitionDescriptor& partition_descriptor) 215 const OVERRIDE; 216 217 // Deletes all network related data since |time|. It deletes transport 218 // security state since |time| and also deletes HttpServerProperties data. 219 // Works asynchronously, however if the |completion| callback is non-null, 220 // it will be posted on the UI thread once the removal process completes. 221 void ClearNetworkingHistorySinceOnIOThread(base::Time time, 222 const base::Closure& completion); 223 224 // Lazy initialization params. 225 mutable scoped_ptr<LazyParams> lazy_params_; 226 227 mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_; 228 mutable scoped_ptr<net::FtpTransactionFactory> ftp_factory_; 229 230 // Same as |ProfileIOData::http_server_properties_|, owned there to maintain 231 // destruction ordering. 232 mutable net::HttpServerPropertiesManager* http_server_properties_manager_; 233 234 mutable scoped_ptr<chrome_browser_net::Predictor> predictor_; 235 236 mutable scoped_ptr<net::URLRequestContext> media_request_context_; 237 238 mutable scoped_ptr<net::URLRequestJobFactory> main_job_factory_; 239 mutable scoped_ptr<net::URLRequestJobFactory> extensions_job_factory_; 240 241 mutable scoped_ptr<domain_reliability::DomainReliabilityMonitor> 242 domain_reliability_monitor_; 243 244 mutable scoped_ptr<net::SdchManager> sdch_manager_; 245 246 // Parameters needed for isolated apps. 247 base::FilePath profile_path_; 248 int app_cache_max_size_; 249 int app_media_cache_max_size_; 250 251#if defined(SPDY_PROXY_AUTH_ORIGIN) 252 mutable scoped_ptr<data_reduction_proxy::DataReductionProxyParams> 253 data_reduction_proxy_params_; 254 mutable scoped_ptr<data_reduction_proxy::DataReductionProxyUsageStats> 255 data_reduction_proxy_usage_stats_; 256 mutable base::Callback<void(bool)> data_reduction_proxy_unavailable_callback_; 257 mutable scoped_ptr<DataReductionProxyChromeConfigurator> 258 data_reduction_proxy_chrome_configurator_; 259 mutable scoped_ptr<data_reduction_proxy::DataReductionProxyAuthRequestHandler> 260 data_reduction_proxy_auth_request_handler_; 261#endif // defined(SPDY_PROXY_AUTH_ORIGIN) 262 263 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData); 264}; 265 266#endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_ 267