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 namespace data_reduction_proxy
{
26 class DataReductionProxyNetworkDelegate
;
27 } // namespace data_reduction_proxy
29 namespace domain_reliability
{
30 class DomainReliabilityMonitor
;
31 } // namespace domain_reliability
34 class FtpTransactionFactory
;
35 class HttpServerProperties
;
36 class HttpServerPropertiesManager
;
37 class HttpTransactionFactory
;
44 class SpecialStoragePolicy
;
45 } // namespace storage
47 class ProfileImplIOData
: public ProfileIOData
{
51 explicit Handle(Profile
* profile
);
54 // Init() must be called before ~Handle(). It records most of the
55 // parameters needed to construct a ChromeURLRequestContextGetter.
57 const base::FilePath
& cookie_path
,
58 const base::FilePath
& channel_id_path
,
59 const base::FilePath
& cache_path
,
61 const base::FilePath
& media_cache_path
,
62 int media_cache_max_size
,
63 const base::FilePath
& extensions_cookie_path
,
64 const base::FilePath
& profile_path
,
65 const base::FilePath
& infinite_cache_path
,
66 chrome_browser_net::Predictor
* predictor
,
67 content::CookieStoreConfig::SessionCookieMode session_cookie_mode
,
68 storage::SpecialStoragePolicy
* special_storage_policy
,
69 scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
70 domain_reliability_monitor
);
72 // These Create*ContextGetter() functions are only exposed because the
73 // circular relationship between Profile, ProfileIOData::Handle, and the
74 // ChromeURLRequestContextGetter factories requires Profile be able to call
76 scoped_refptr
<ChromeURLRequestContextGetter
> CreateMainRequestContextGetter(
77 content::ProtocolHandlerMap
* protocol_handlers
,
78 content::URLRequestInterceptorScopedVector request_interceptors
,
79 PrefService
* local_state
,
80 IOThread
* io_thread
) const;
81 scoped_refptr
<ChromeURLRequestContextGetter
>
82 CreateIsolatedAppRequestContextGetter(
83 const base::FilePath
& partition_path
,
85 content::ProtocolHandlerMap
* protocol_handlers
,
86 content::URLRequestInterceptorScopedVector
87 request_interceptors
) const;
89 content::ResourceContext
* GetResourceContext() const;
90 // GetResourceContextNoInit() does not call LazyInitialize() so it can be
91 // safely be used during initialization.
92 content::ResourceContext
* GetResourceContextNoInit() const;
93 scoped_refptr
<ChromeURLRequestContextGetter
>
94 GetMediaRequestContextGetter() const;
95 scoped_refptr
<ChromeURLRequestContextGetter
>
96 GetExtensionsRequestContextGetter() const;
97 scoped_refptr
<ChromeURLRequestContextGetter
>
98 GetIsolatedMediaRequestContextGetter(
99 const base::FilePath
& partition_path
,
100 bool in_memory
) const;
102 // Returns the DevToolsNetworkController attached to ProfileIOData.
103 DevToolsNetworkController
* GetDevToolsNetworkController() const;
105 // Deletes all network related data since |time|. It deletes transport
106 // security state since |time| and also deletes HttpServerProperties data.
107 // Works asynchronously, however if the |completion| callback is non-null,
108 // it will be posted on the UI thread once the removal process completes.
109 void ClearNetworkingHistorySince(base::Time time
,
110 const base::Closure
& completion
);
113 typedef std::map
<StoragePartitionDescriptor
,
114 scoped_refptr
<ChromeURLRequestContextGetter
>,
115 StoragePartitionDescriptorLess
>
116 ChromeURLRequestContextGetterMap
;
118 // Lazily initialize ProfileParams. We do this on the calls to
119 // Get*RequestContextGetter(), so we only initialize ProfileParams right
120 // before posting a task to the IO thread to start using them. This prevents
121 // objects that are supposed to be deleted on the IO thread, but are created
122 // on the UI thread from being unnecessarily initialized.
123 void LazyInitialize() const;
125 // Collect references to context getters in reverse order, i.e. last item
126 // will be main request getter. This list is passed to |io_data_|
127 // for invalidation on IO thread.
128 scoped_ptr
<ChromeURLRequestContextGetterVector
> GetAllContextGetters();
130 // The getters will be invalidated on the IO thread before
131 // ProfileIOData instance is deleted.
132 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
133 main_request_context_getter_
;
134 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
135 media_request_context_getter_
;
136 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
137 extensions_request_context_getter_
;
138 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_
;
139 mutable ChromeURLRequestContextGetterMap
140 isolated_media_request_context_getter_map_
;
141 ProfileImplIOData
* const io_data_
;
143 Profile
* const profile_
;
145 mutable bool initialized_
;
147 DISALLOW_COPY_AND_ASSIGN(Handle
);
151 friend class base::RefCountedThreadSafe
<ProfileImplIOData
>;
157 // All of these parameters are intended to be read on the IO thread.
158 base::FilePath cookie_path
;
159 base::FilePath channel_id_path
;
160 base::FilePath cache_path
;
162 base::FilePath media_cache_path
;
163 int media_cache_max_size
;
164 base::FilePath extensions_cookie_path
;
165 base::FilePath infinite_cache_path
;
166 content::CookieStoreConfig::SessionCookieMode session_cookie_mode
;
167 scoped_refptr
<storage::SpecialStoragePolicy
> special_storage_policy
;
171 ~ProfileImplIOData() override
;
173 void InitializeInternal(
174 scoped_ptr
<ChromeNetworkDelegate
> chrome_network_delegate
,
175 ProfileParams
* profile_params
,
176 content::ProtocolHandlerMap
* protocol_handlers
,
177 content::URLRequestInterceptorScopedVector
178 request_interceptors
) const override
;
179 void InitializeExtensionsRequestContext(
180 ProfileParams
* profile_params
) const override
;
181 net::URLRequestContext
* InitializeAppRequestContext(
182 net::URLRequestContext
* main_context
,
183 const StoragePartitionDescriptor
& partition_descriptor
,
184 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
185 protocol_handler_interceptor
,
186 content::ProtocolHandlerMap
* protocol_handlers
,
187 content::URLRequestInterceptorScopedVector request_interceptors
)
189 net::URLRequestContext
* InitializeMediaRequestContext(
190 net::URLRequestContext
* original_context
,
191 const StoragePartitionDescriptor
& partition_descriptor
) const override
;
192 net::URLRequestContext
* AcquireMediaRequestContext() const override
;
193 net::URLRequestContext
* AcquireIsolatedAppRequestContext(
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 net::URLRequestContext
* AcquireIsolatedMediaRequestContext(
202 net::URLRequestContext
* app_context
,
203 const StoragePartitionDescriptor
& partition_descriptor
) const override
;
205 // Deletes all network related data since |time|. It deletes transport
206 // security state since |time| and also deletes HttpServerProperties data.
207 // Works asynchronously, however if the |completion| callback is non-null,
208 // it will be posted on the UI thread once the removal process completes.
209 void ClearNetworkingHistorySinceOnIOThread(base::Time time
,
210 const base::Closure
& completion
);
212 mutable scoped_ptr
<data_reduction_proxy::DataReductionProxyNetworkDelegate
>
215 // Lazy initialization params.
216 mutable scoped_ptr
<LazyParams
> lazy_params_
;
218 mutable scoped_ptr
<net::HttpTransactionFactory
> main_http_factory_
;
219 mutable scoped_ptr
<net::FtpTransactionFactory
> ftp_factory_
;
221 // Same as |ProfileIOData::http_server_properties_|, owned there to maintain
222 // destruction ordering.
223 mutable net::HttpServerPropertiesManager
* http_server_properties_manager_
;
225 mutable scoped_ptr
<chrome_browser_net::Predictor
> predictor_
;
227 mutable scoped_ptr
<net::URLRequestContext
> media_request_context_
;
229 mutable scoped_ptr
<net::URLRequestJobFactory
> main_job_factory_
;
230 mutable scoped_ptr
<net::URLRequestJobFactory
> extensions_job_factory_
;
232 mutable scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
233 domain_reliability_monitor_
;
235 mutable scoped_ptr
<net::SdchManager
> sdch_manager_
;
236 mutable scoped_ptr
<net::SdchOwner
> sdch_policy_
;
238 // Parameters needed for isolated apps.
239 base::FilePath profile_path_
;
240 int app_cache_max_size_
;
241 int app_media_cache_max_size_
;
243 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData
);
246 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_