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.
5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_
6 #define CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_
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"
17 namespace chrome_browser_net {
19 } // namespace chrome_browser_net
22 class CookieCryptoDelegate;
23 } // namespace content
25 #if defined(SPDY_PROXY_AUTH_ORIGIN)
26 namespace data_reduction_proxy {
27 class DataReductionProxyParams;
28 class DataReductionProxyUsageStats;
29 class DataReductionProxyAuthRequestHandler;
33 namespace domain_reliability {
34 class DomainReliabilityMonitor;
35 } // namespace domain_reliability
38 class FtpTransactionFactory;
39 class HttpServerProperties;
40 class HttpServerPropertiesManager;
41 class HttpTransactionFactory;
47 class SpecialStoragePolicy;
50 class DataReductionProxyChromeConfigurator;
52 class ProfileImplIOData : public ProfileIOData {
56 explicit Handle(Profile* profile);
59 // Init() must be called before ~Handle(). It records most of the
60 // parameters needed to construct a ChromeURLRequestContextGetter.
61 void Init(const base::FilePath& cookie_path,
62 const base::FilePath& channel_id_path,
63 const base::FilePath& cache_path,
65 const base::FilePath& media_cache_path,
66 int media_cache_max_size,
67 const base::FilePath& extensions_cookie_path,
68 const base::FilePath& profile_path,
69 const base::FilePath& infinite_cache_path,
70 chrome_browser_net::Predictor* predictor,
71 content::CookieStoreConfig::SessionCookieMode
73 quota::SpecialStoragePolicy* special_storage_policy,
74 scoped_ptr<domain_reliability::DomainReliabilityMonitor>
75 domain_reliability_monitor,
76 const base::Callback<void(bool)>&
77 data_reduction_proxy_unavailable,
78 scoped_ptr<DataReductionProxyChromeConfigurator>
79 data_reduction_proxy_chrome_configurator,
80 scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
81 data_reduction_proxy_params);
83 // These Create*ContextGetter() functions are only exposed because the
84 // circular relationship between Profile, ProfileIOData::Handle, and the
85 // ChromeURLRequestContextGetter factories requires Profile be able to call
87 scoped_refptr<ChromeURLRequestContextGetter> CreateMainRequestContextGetter(
88 content::ProtocolHandlerMap* protocol_handlers,
89 content::URLRequestInterceptorScopedVector request_interceptors,
90 PrefService* local_state,
91 IOThread* io_thread) const;
92 scoped_refptr<ChromeURLRequestContextGetter>
93 CreateIsolatedAppRequestContextGetter(
94 const base::FilePath& partition_path,
96 content::ProtocolHandlerMap* protocol_handlers,
97 content::URLRequestInterceptorScopedVector
98 request_interceptors) const;
100 content::ResourceContext* GetResourceContext() const;
101 // GetResourceContextNoInit() does not call LazyInitialize() so it can be
102 // safely be used during initialization.
103 content::ResourceContext* GetResourceContextNoInit() const;
104 scoped_refptr<ChromeURLRequestContextGetter>
105 GetMediaRequestContextGetter() const;
106 scoped_refptr<ChromeURLRequestContextGetter>
107 GetExtensionsRequestContextGetter() const;
108 scoped_refptr<ChromeURLRequestContextGetter>
109 GetIsolatedMediaRequestContextGetter(
110 const base::FilePath& partition_path,
111 bool in_memory) const;
113 // Returns the DevToolsNetworkController attached to ProfileIOData.
114 DevToolsNetworkController* GetDevToolsNetworkController() const;
116 // Deletes all network related data since |time|. It deletes transport
117 // security state since |time| and also deletes HttpServerProperties data.
118 // Works asynchronously, however if the |completion| callback is non-null,
119 // it will be posted on the UI thread once the removal process completes.
120 void ClearNetworkingHistorySince(base::Time time,
121 const base::Closure& completion);
124 typedef std::map<StoragePartitionDescriptor,
125 scoped_refptr<ChromeURLRequestContextGetter>,
126 StoragePartitionDescriptorLess>
127 ChromeURLRequestContextGetterMap;
129 // Lazily initialize ProfileParams. We do this on the calls to
130 // Get*RequestContextGetter(), so we only initialize ProfileParams right
131 // before posting a task to the IO thread to start using them. This prevents
132 // objects that are supposed to be deleted on the IO thread, but are created
133 // on the UI thread from being unnecessarily initialized.
134 void LazyInitialize() const;
136 // Ordering is important here. Do not reorder unless you know what you're
137 // doing. We need to release |io_data_| *before* the getters, because we
138 // want to make sure that the last reference for |io_data_| is on the IO
139 // thread. The getters will be deleted on the IO thread, so they will
140 // release their refs to their contexts, which will release the last refs to
141 // the ProfileIOData on the IO thread.
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_;
153 Profile* const profile_;
155 mutable bool initialized_;
157 DISALLOW_COPY_AND_ASSIGN(Handle);
161 friend class base::RefCountedThreadSafe<ProfileImplIOData>;
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;
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<quota::SpecialStoragePolicy> special_storage_policy;
181 virtual ~ProfileImplIOData();
183 virtual void InitializeInternal(
184 ProfileParams* profile_params,
185 content::ProtocolHandlerMap* protocol_handlers,
186 content::URLRequestInterceptorScopedVector request_interceptors)
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)
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)
211 virtual net::URLRequestContext*
212 AcquireIsolatedMediaRequestContext(
213 net::URLRequestContext* app_context,
214 const StoragePartitionDescriptor& partition_descriptor)
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);
224 // Lazy initialization params.
225 mutable scoped_ptr<LazyParams> lazy_params_;
227 mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
228 mutable scoped_ptr<net::FtpTransactionFactory> ftp_factory_;
230 // Same as |ProfileIOData::http_server_properties_|, owned there to maintain
231 // destruction ordering.
232 mutable net::HttpServerPropertiesManager* http_server_properties_manager_;
234 mutable scoped_ptr<chrome_browser_net::Predictor> predictor_;
236 mutable scoped_ptr<net::URLRequestContext> media_request_context_;
238 mutable scoped_ptr<net::URLRequestJobFactory> main_job_factory_;
239 mutable scoped_ptr<net::URLRequestJobFactory> extensions_job_factory_;
241 mutable scoped_ptr<domain_reliability::DomainReliabilityMonitor>
242 domain_reliability_monitor_;
244 mutable scoped_ptr<net::SdchManager> sdch_manager_;
246 // Parameters needed for isolated apps.
247 base::FilePath profile_path_;
248 int app_cache_max_size_;
249 int app_media_cache_max_size_;
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)
263 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData);
266 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_