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
;
30 class DataReductionProxyStatisticsPrefs
;
31 } // namespace data_reduction_proxy
34 namespace domain_reliability
{
35 class DomainReliabilityMonitor
;
36 } // namespace domain_reliability
39 class FtpTransactionFactory
;
40 class HttpServerProperties
;
41 class HttpServerPropertiesManager
;
42 class HttpTransactionFactory
;
48 class SpecialStoragePolicy
;
49 } // namespace storage
51 class DataReductionProxyChromeConfigurator
;
53 class ProfileImplIOData
: public ProfileIOData
{
57 explicit Handle(Profile
* profile
);
60 // Init() must be called before ~Handle(). It records most of the
61 // parameters needed to construct a ChromeURLRequestContextGetter.
63 const base::FilePath
& cookie_path
,
64 const base::FilePath
& channel_id_path
,
65 const base::FilePath
& cache_path
,
67 const base::FilePath
& media_cache_path
,
68 int media_cache_max_size
,
69 const base::FilePath
& extensions_cookie_path
,
70 const base::FilePath
& profile_path
,
71 const base::FilePath
& infinite_cache_path
,
72 chrome_browser_net::Predictor
* predictor
,
73 content::CookieStoreConfig::SessionCookieMode session_cookie_mode
,
74 storage::SpecialStoragePolicy
* special_storage_policy
,
75 scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
76 domain_reliability_monitor
,
77 const base::Callback
<void(bool)>& 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
,
82 scoped_ptr
<data_reduction_proxy::DataReductionProxyStatisticsPrefs
>
83 data_reduction_proxy_statistics_prefs
);
85 // These Create*ContextGetter() functions are only exposed because the
86 // circular relationship between Profile, ProfileIOData::Handle, and the
87 // ChromeURLRequestContextGetter factories requires Profile be able to call
89 scoped_refptr
<ChromeURLRequestContextGetter
> CreateMainRequestContextGetter(
90 content::ProtocolHandlerMap
* protocol_handlers
,
91 content::URLRequestInterceptorScopedVector request_interceptors
,
92 PrefService
* local_state
,
93 IOThread
* io_thread
) const;
94 scoped_refptr
<ChromeURLRequestContextGetter
>
95 CreateIsolatedAppRequestContextGetter(
96 const base::FilePath
& partition_path
,
98 content::ProtocolHandlerMap
* protocol_handlers
,
99 content::URLRequestInterceptorScopedVector
100 request_interceptors
) const;
102 content::ResourceContext
* GetResourceContext() const;
103 // GetResourceContextNoInit() does not call LazyInitialize() so it can be
104 // safely be used during initialization.
105 content::ResourceContext
* GetResourceContextNoInit() const;
106 scoped_refptr
<ChromeURLRequestContextGetter
>
107 GetMediaRequestContextGetter() const;
108 scoped_refptr
<ChromeURLRequestContextGetter
>
109 GetExtensionsRequestContextGetter() const;
110 scoped_refptr
<ChromeURLRequestContextGetter
>
111 GetIsolatedMediaRequestContextGetter(
112 const base::FilePath
& partition_path
,
113 bool in_memory
) const;
115 // Returns the DevToolsNetworkController attached to ProfileIOData.
116 DevToolsNetworkController
* GetDevToolsNetworkController() const;
118 // Deletes all network related data since |time|. It deletes transport
119 // security state since |time| and also deletes HttpServerProperties data.
120 // Works asynchronously, however if the |completion| callback is non-null,
121 // it will be posted on the UI thread once the removal process completes.
122 void ClearNetworkingHistorySince(base::Time time
,
123 const base::Closure
& completion
);
126 typedef std::map
<StoragePartitionDescriptor
,
127 scoped_refptr
<ChromeURLRequestContextGetter
>,
128 StoragePartitionDescriptorLess
>
129 ChromeURLRequestContextGetterMap
;
131 // Lazily initialize ProfileParams. We do this on the calls to
132 // Get*RequestContextGetter(), so we only initialize ProfileParams right
133 // before posting a task to the IO thread to start using them. This prevents
134 // objects that are supposed to be deleted on the IO thread, but are created
135 // on the UI thread from being unnecessarily initialized.
136 void LazyInitialize() const;
138 // Collect references to context getters in reverse order, i.e. last item
139 // will be main request getter. This list is passed to |io_data_|
140 // for invalidation on IO thread.
141 scoped_ptr
<ChromeURLRequestContextGetterVector
> GetAllContextGetters();
143 // The getters will be invalidated on the IO thread before
144 // ProfileIOData instance is deleted.
145 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
146 main_request_context_getter_
;
147 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
148 media_request_context_getter_
;
149 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
150 extensions_request_context_getter_
;
151 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_
;
152 mutable ChromeURLRequestContextGetterMap
153 isolated_media_request_context_getter_map_
;
154 ProfileImplIOData
* const io_data_
;
156 Profile
* const profile_
;
158 mutable bool initialized_
;
160 DISALLOW_COPY_AND_ASSIGN(Handle
);
164 friend class base::RefCountedThreadSafe
<ProfileImplIOData
>;
170 // All of these parameters are intended to be read on the IO thread.
171 base::FilePath cookie_path
;
172 base::FilePath channel_id_path
;
173 base::FilePath cache_path
;
175 base::FilePath media_cache_path
;
176 int media_cache_max_size
;
177 base::FilePath extensions_cookie_path
;
178 base::FilePath infinite_cache_path
;
179 content::CookieStoreConfig::SessionCookieMode session_cookie_mode
;
180 scoped_refptr
<storage::SpecialStoragePolicy
> special_storage_policy
;
184 virtual ~ProfileImplIOData();
186 virtual void InitializeInternal(
187 ProfileParams
* profile_params
,
188 content::ProtocolHandlerMap
* protocol_handlers
,
189 content::URLRequestInterceptorScopedVector request_interceptors
)
191 virtual void InitializeExtensionsRequestContext(
192 ProfileParams
* profile_params
) const OVERRIDE
;
193 virtual net::URLRequestContext
* InitializeAppRequestContext(
194 net::URLRequestContext
* main_context
,
195 const StoragePartitionDescriptor
& partition_descriptor
,
196 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
197 protocol_handler_interceptor
,
198 content::ProtocolHandlerMap
* protocol_handlers
,
199 content::URLRequestInterceptorScopedVector request_interceptors
)
201 virtual net::URLRequestContext
* InitializeMediaRequestContext(
202 net::URLRequestContext
* original_context
,
203 const StoragePartitionDescriptor
& partition_descriptor
) const OVERRIDE
;
204 virtual net::URLRequestContext
*
205 AcquireMediaRequestContext() const OVERRIDE
;
206 virtual net::URLRequestContext
* AcquireIsolatedAppRequestContext(
207 net::URLRequestContext
* main_context
,
208 const StoragePartitionDescriptor
& partition_descriptor
,
209 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
210 protocol_handler_interceptor
,
211 content::ProtocolHandlerMap
* protocol_handlers
,
212 content::URLRequestInterceptorScopedVector request_interceptors
)
214 virtual net::URLRequestContext
*
215 AcquireIsolatedMediaRequestContext(
216 net::URLRequestContext
* app_context
,
217 const StoragePartitionDescriptor
& partition_descriptor
)
220 // Deletes all network related data since |time|. It deletes transport
221 // security state since |time| and also deletes HttpServerProperties data.
222 // Works asynchronously, however if the |completion| callback is non-null,
223 // it will be posted on the UI thread once the removal process completes.
224 void ClearNetworkingHistorySinceOnIOThread(base::Time time
,
225 const base::Closure
& completion
);
227 // Lazy initialization params.
228 mutable scoped_ptr
<LazyParams
> lazy_params_
;
230 mutable scoped_ptr
<net::HttpTransactionFactory
> main_http_factory_
;
231 mutable scoped_ptr
<net::FtpTransactionFactory
> ftp_factory_
;
233 // Same as |ProfileIOData::http_server_properties_|, owned there to maintain
234 // destruction ordering.
235 mutable net::HttpServerPropertiesManager
* http_server_properties_manager_
;
237 mutable scoped_ptr
<chrome_browser_net::Predictor
> predictor_
;
239 mutable scoped_ptr
<net::URLRequestContext
> media_request_context_
;
241 mutable scoped_ptr
<net::URLRequestJobFactory
> main_job_factory_
;
242 mutable scoped_ptr
<net::URLRequestJobFactory
> extensions_job_factory_
;
244 mutable scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
245 domain_reliability_monitor_
;
247 mutable scoped_ptr
<net::SdchManager
> sdch_manager_
;
249 // Parameters needed for isolated apps.
250 base::FilePath profile_path_
;
251 int app_cache_max_size_
;
252 int app_media_cache_max_size_
;
254 #if defined(SPDY_PROXY_AUTH_ORIGIN)
255 mutable scoped_ptr
<data_reduction_proxy::DataReductionProxyParams
>
256 data_reduction_proxy_params_
;
257 mutable scoped_ptr
<data_reduction_proxy::DataReductionProxyUsageStats
>
258 data_reduction_proxy_usage_stats_
;
259 mutable base::Callback
<void(bool)> data_reduction_proxy_unavailable_callback_
;
260 mutable scoped_ptr
<DataReductionProxyChromeConfigurator
>
261 data_reduction_proxy_chrome_configurator_
;
262 mutable scoped_ptr
<data_reduction_proxy::DataReductionProxyAuthRequestHandler
>
263 data_reduction_proxy_auth_request_handler_
;
264 mutable scoped_ptr
<data_reduction_proxy::DataReductionProxyStatisticsPrefs
>
265 data_reduction_proxy_statistics_prefs_
;
266 #endif // defined(SPDY_PROXY_AUTH_ORIGIN)
268 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData
);
271 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_