profile_impl_io_data.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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/hash_tables.h" 11#include "base/memory/ref_counted.h" 12#include "chrome/browser/custom_handlers/protocol_handler_registry.h" 13#include "chrome/browser/profiles/profile_io_data.h" 14 15namespace chrome_browser_net { 16class HttpServerPropertiesManager; 17class Predictor; 18} // namespace chrome_browser_net 19 20namespace net { 21class HttpServerProperties; 22class HttpTransactionFactory; 23} // namespace net 24 25namespace quota { 26class SpecialStoragePolicy; 27} // namespace quota 28 29class ProfileImplIOData : public ProfileIOData { 30 public: 31 class Handle { 32 public: 33 explicit Handle(Profile* profile); 34 ~Handle(); 35 36 // Init() must be called before ~Handle(). It records most of the 37 // parameters needed to construct a ChromeURLRequestContextGetter. 38 void Init(const base::FilePath& cookie_path, 39 const base::FilePath& server_bound_cert_path, 40 const base::FilePath& cache_path, 41 int cache_max_size, 42 const base::FilePath& media_cache_path, 43 int media_cache_max_size, 44 const base::FilePath& extensions_cookie_path, 45 const base::FilePath& profile_path, 46 const base::FilePath& infinite_cache_path, 47 chrome_browser_net::Predictor* predictor, 48 bool restore_old_session_cookies, 49 quota::SpecialStoragePolicy* special_storage_policy); 50 51 // These Create*ContextGetter() functions are only exposed because the 52 // circular relationship between Profile, ProfileIOData::Handle, and the 53 // ChromeURLRequestContextGetter factories requires Profile be able to call 54 // these functions. 55 scoped_refptr<ChromeURLRequestContextGetter> 56 CreateMainRequestContextGetter( 57 content::ProtocolHandlerMap* protocol_handlers, 58 PrefService* local_state, 59 IOThread* io_thread) const; 60 scoped_refptr<ChromeURLRequestContextGetter> 61 CreateIsolatedAppRequestContextGetter( 62 const base::FilePath& partition_path, 63 bool in_memory, 64 content::ProtocolHandlerMap* protocol_handlers) const; 65 66 content::ResourceContext* GetResourceContext() const; 67 // GetResourceContextNoInit() does not call LazyInitialize() so it can be 68 // safely be used during initialization. 69 content::ResourceContext* GetResourceContextNoInit() const; 70 scoped_refptr<ChromeURLRequestContextGetter> 71 GetMediaRequestContextGetter() const; 72 scoped_refptr<ChromeURLRequestContextGetter> 73 GetExtensionsRequestContextGetter() const; 74 scoped_refptr<ChromeURLRequestContextGetter> 75 GetIsolatedMediaRequestContextGetter( 76 const base::FilePath& partition_path, 77 bool in_memory) const; 78 79 // Deletes all network related data since |time|. It deletes transport 80 // security state since |time| and also deletes HttpServerProperties data. 81 // Works asynchronously, however if the |completion| callback is non-null, 82 // it will be posted on the UI thread once the removal process completes. 83 void ClearNetworkingHistorySince(base::Time time, 84 const base::Closure& completion); 85 86 private: 87 typedef std::map<StoragePartitionDescriptor, 88 scoped_refptr<ChromeURLRequestContextGetter>, 89 StoragePartitionDescriptorLess> 90 ChromeURLRequestContextGetterMap; 91 92 // Lazily initialize ProfileParams. We do this on the calls to 93 // Get*RequestContextGetter(), so we only initialize ProfileParams right 94 // before posting a task to the IO thread to start using them. This prevents 95 // objects that are supposed to be deleted on the IO thread, but are created 96 // on the UI thread from being unnecessarily initialized. 97 void LazyInitialize() const; 98 99 // Ordering is important here. Do not reorder unless you know what you're 100 // doing. We need to release |io_data_| *before* the getters, because we 101 // want to make sure that the last reference for |io_data_| is on the IO 102 // thread. The getters will be deleted on the IO thread, so they will 103 // release their refs to their contexts, which will release the last refs to 104 // the ProfileIOData on the IO thread. 105 mutable scoped_refptr<ChromeURLRequestContextGetter> 106 main_request_context_getter_; 107 mutable scoped_refptr<ChromeURLRequestContextGetter> 108 media_request_context_getter_; 109 mutable scoped_refptr<ChromeURLRequestContextGetter> 110 extensions_request_context_getter_; 111 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_; 112 mutable ChromeURLRequestContextGetterMap 113 isolated_media_request_context_getter_map_; 114 ProfileImplIOData* const io_data_; 115 116 Profile* const profile_; 117 118 mutable bool initialized_; 119 120 DISALLOW_COPY_AND_ASSIGN(Handle); 121 }; 122 123 private: 124 friend class base::RefCountedThreadSafe<ProfileImplIOData>; 125 126 struct LazyParams { 127 LazyParams(); 128 ~LazyParams(); 129 130 // All of these parameters are intended to be read on the IO thread. 131 base::FilePath cookie_path; 132 base::FilePath server_bound_cert_path; 133 base::FilePath cache_path; 134 int cache_max_size; 135 base::FilePath media_cache_path; 136 int media_cache_max_size; 137 base::FilePath extensions_cookie_path; 138 base::FilePath infinite_cache_path; 139 bool restore_old_session_cookies; 140 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy; 141 }; 142 143 typedef base::hash_map<std::string, net::HttpTransactionFactory* > 144 HttpTransactionFactoryMap; 145 146 ProfileImplIOData(); 147 virtual ~ProfileImplIOData(); 148 149 virtual void InitializeInternal( 150 ProfileParams* profile_params, 151 content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; 152 virtual void InitializeExtensionsRequestContext( 153 ProfileParams* profile_params) const OVERRIDE; 154 virtual ChromeURLRequestContext* InitializeAppRequestContext( 155 ChromeURLRequestContext* main_context, 156 const StoragePartitionDescriptor& partition_descriptor, 157 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 158 protocol_handler_interceptor, 159 content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; 160 virtual ChromeURLRequestContext* InitializeMediaRequestContext( 161 ChromeURLRequestContext* original_context, 162 const StoragePartitionDescriptor& partition_descriptor) const OVERRIDE; 163 virtual ChromeURLRequestContext* 164 AcquireMediaRequestContext() const OVERRIDE; 165 virtual ChromeURLRequestContext* 166 AcquireIsolatedAppRequestContext( 167 ChromeURLRequestContext* main_context, 168 const StoragePartitionDescriptor& partition_descriptor, 169 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 170 protocol_handler_interceptor, 171 content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; 172 virtual ChromeURLRequestContext* 173 AcquireIsolatedMediaRequestContext( 174 ChromeURLRequestContext* app_context, 175 const StoragePartitionDescriptor& partition_descriptor) 176 const OVERRIDE; 177 virtual chrome_browser_net::LoadTimeStats* GetLoadTimeStats( 178 IOThread::Globals* io_thread_globals) const OVERRIDE; 179 180 // Deletes all network related data since |time|. It deletes transport 181 // security state since |time| and also deletes HttpServerProperties data. 182 // Works asynchronously, however if the |completion| callback is non-null, 183 // it will be posted on the UI thread once the removal process completes. 184 void ClearNetworkingHistorySinceOnIOThread(base::Time time, 185 const base::Closure& completion); 186 187 // Lazy initialization params. 188 mutable scoped_ptr<LazyParams> lazy_params_; 189 190 mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_; 191 mutable scoped_ptr<net::FtpTransactionFactory> ftp_factory_; 192 193 // Same as |ProfileIOData::http_server_properties_|, owned there to maintain 194 // destruction ordering. 195 mutable chrome_browser_net::HttpServerPropertiesManager* 196 http_server_properties_manager_; 197 198 mutable scoped_ptr<chrome_browser_net::Predictor> predictor_; 199 200 mutable scoped_ptr<ChromeURLRequestContext> media_request_context_; 201 202 mutable scoped_ptr<net::URLRequestJobFactory> main_job_factory_; 203 mutable scoped_ptr<net::URLRequestJobFactory> extensions_job_factory_; 204 205 // Parameters needed for isolated apps. 206 base::FilePath profile_path_; 207 int app_cache_max_size_; 208 int app_media_cache_max_size_; 209 210 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData); 211}; 212 213#endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_ 214