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/profiles/profile_io_data.h"
14 #include "components/domain_reliability/clear_mode.h"
15 #include "content/public/browser/cookie_store_factory.h"
17 namespace chrome_browser_net
{
18 class HttpServerPropertiesManager
;
20 } // namespace chrome_browser_net
23 class CookieCryptoDelegate
;
24 } // namespace content
26 namespace domain_reliability
{
27 class DomainReliabilityMonitor
;
28 } // namespace domain_reliability
31 class FtpTransactionFactory
;
32 class HttpServerProperties
;
33 class HttpTransactionFactory
;
37 class SpecialStoragePolicy
;
40 class ProfileImplIOData
: public ProfileIOData
{
44 explicit Handle(Profile
* profile
);
47 // Init() must be called before ~Handle(). It records most of the
48 // parameters needed to construct a ChromeURLRequestContextGetter.
49 void Init(const base::FilePath
& cookie_path
,
50 const base::FilePath
& server_bound_cert_path
,
51 const base::FilePath
& cache_path
,
53 const base::FilePath
& media_cache_path
,
54 int media_cache_max_size
,
55 const base::FilePath
& extensions_cookie_path
,
56 const base::FilePath
& profile_path
,
57 const base::FilePath
& infinite_cache_path
,
58 chrome_browser_net::Predictor
* predictor
,
59 content::CookieStoreConfig::SessionCookieMode
61 quota::SpecialStoragePolicy
* special_storage_policy
);
63 // These Create*ContextGetter() functions are only exposed because the
64 // circular relationship between Profile, ProfileIOData::Handle, and the
65 // ChromeURLRequestContextGetter factories requires Profile be able to call
67 scoped_refptr
<ChromeURLRequestContextGetter
> CreateMainRequestContextGetter(
68 content::ProtocolHandlerMap
* protocol_handlers
,
69 content::URLRequestInterceptorScopedVector request_interceptors
,
70 PrefService
* local_state
,
71 IOThread
* io_thread
) const;
72 scoped_refptr
<ChromeURLRequestContextGetter
>
73 CreateIsolatedAppRequestContextGetter(
74 const base::FilePath
& partition_path
,
76 content::ProtocolHandlerMap
* protocol_handlers
,
77 content::URLRequestInterceptorScopedVector
78 request_interceptors
) const;
80 content::ResourceContext
* GetResourceContext() const;
81 // GetResourceContextNoInit() does not call LazyInitialize() so it can be
82 // safely be used during initialization.
83 content::ResourceContext
* GetResourceContextNoInit() const;
84 scoped_refptr
<ChromeURLRequestContextGetter
>
85 GetMediaRequestContextGetter() const;
86 scoped_refptr
<ChromeURLRequestContextGetter
>
87 GetExtensionsRequestContextGetter() const;
88 scoped_refptr
<ChromeURLRequestContextGetter
>
89 GetIsolatedMediaRequestContextGetter(
90 const base::FilePath
& partition_path
,
91 bool in_memory
) const;
93 // Returns the DevToolsNetworkController attached to ProfileIOData.
94 DevToolsNetworkController
* GetDevToolsNetworkController() const;
96 // Deletes all network related data since |time|. It deletes transport
97 // security state since |time| and also deletes HttpServerProperties data.
98 // Works asynchronously, however if the |completion| callback is non-null,
99 // it will be posted on the UI thread once the removal process completes.
100 void ClearNetworkingHistorySince(base::Time time
,
101 const base::Closure
& completion
);
103 // Clears part or all of the state of the Domain Reliability Monitor. If
104 // |clear_contexts| is true, clears the (site-provided) contexts, which are
105 // cookie-esque; if it is false, clears only the (logged) beacons within
106 // them, which are history-esque.
107 void ClearDomainReliabilityMonitor(
108 domain_reliability::DomainReliabilityClearMode mode
,
109 const base::Closure
& completion
);
112 typedef std::map
<StoragePartitionDescriptor
,
113 scoped_refptr
<ChromeURLRequestContextGetter
>,
114 StoragePartitionDescriptorLess
>
115 ChromeURLRequestContextGetterMap
;
117 // Lazily initialize ProfileParams. We do this on the calls to
118 // Get*RequestContextGetter(), so we only initialize ProfileParams right
119 // before posting a task to the IO thread to start using them. This prevents
120 // objects that are supposed to be deleted on the IO thread, but are created
121 // on the UI thread from being unnecessarily initialized.
122 void LazyInitialize() const;
124 // Ordering is important here. Do not reorder unless you know what you're
125 // doing. We need to release |io_data_| *before* the getters, because we
126 // want to make sure that the last reference for |io_data_| is on the IO
127 // thread. The getters will be deleted on the IO thread, so they will
128 // release their refs to their contexts, which will release the last refs to
129 // the ProfileIOData on the IO thread.
130 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
131 main_request_context_getter_
;
132 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
133 media_request_context_getter_
;
134 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
135 extensions_request_context_getter_
;
136 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_
;
137 mutable ChromeURLRequestContextGetterMap
138 isolated_media_request_context_getter_map_
;
139 ProfileImplIOData
* const io_data_
;
141 Profile
* const profile_
;
143 mutable bool initialized_
;
145 DISALLOW_COPY_AND_ASSIGN(Handle
);
149 friend class base::RefCountedThreadSafe
<ProfileImplIOData
>;
155 // All of these parameters are intended to be read on the IO thread.
156 base::FilePath cookie_path
;
157 base::FilePath server_bound_cert_path
;
158 base::FilePath cache_path
;
160 base::FilePath media_cache_path
;
161 int media_cache_max_size
;
162 base::FilePath extensions_cookie_path
;
163 base::FilePath infinite_cache_path
;
164 content::CookieStoreConfig::SessionCookieMode session_cookie_mode
;
165 scoped_refptr
<quota::SpecialStoragePolicy
> special_storage_policy
;
169 virtual ~ProfileImplIOData();
171 virtual void InitializeInternal(
172 ProfileParams
* profile_params
,
173 content::ProtocolHandlerMap
* protocol_handlers
,
174 content::URLRequestInterceptorScopedVector request_interceptors
)
176 virtual void InitializeExtensionsRequestContext(
177 ProfileParams
* profile_params
) const OVERRIDE
;
178 virtual ChromeURLRequestContext
* InitializeAppRequestContext(
179 ChromeURLRequestContext
* main_context
,
180 const StoragePartitionDescriptor
& partition_descriptor
,
181 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
182 protocol_handler_interceptor
,
183 content::ProtocolHandlerMap
* protocol_handlers
,
184 content::URLRequestInterceptorScopedVector request_interceptors
)
186 virtual ChromeURLRequestContext
* InitializeMediaRequestContext(
187 ChromeURLRequestContext
* original_context
,
188 const StoragePartitionDescriptor
& partition_descriptor
) const OVERRIDE
;
189 virtual ChromeURLRequestContext
*
190 AcquireMediaRequestContext() const OVERRIDE
;
191 virtual ChromeURLRequestContext
* AcquireIsolatedAppRequestContext(
192 ChromeURLRequestContext
* main_context
,
193 const StoragePartitionDescriptor
& partition_descriptor
,
194 scoped_ptr
<ProtocolHandlerRegistry::JobInterceptorFactory
>
195 protocol_handler_interceptor
,
196 content::ProtocolHandlerMap
* protocol_handlers
,
197 content::URLRequestInterceptorScopedVector request_interceptors
)
199 virtual ChromeURLRequestContext
*
200 AcquireIsolatedMediaRequestContext(
201 ChromeURLRequestContext
* app_context
,
202 const StoragePartitionDescriptor
& partition_descriptor
)
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 void ClearDomainReliabilityMonitorOnIOThread(
213 domain_reliability::DomainReliabilityClearMode mode
,
214 const base::Closure
& completion
);
216 // Lazy initialization params.
217 mutable scoped_ptr
<LazyParams
> lazy_params_
;
219 mutable scoped_ptr
<net::HttpTransactionFactory
> main_http_factory_
;
220 mutable scoped_ptr
<net::FtpTransactionFactory
> ftp_factory_
;
222 // Same as |ProfileIOData::http_server_properties_|, owned there to maintain
223 // destruction ordering.
224 mutable chrome_browser_net::HttpServerPropertiesManager
*
225 http_server_properties_manager_
;
227 mutable scoped_ptr
<chrome_browser_net::Predictor
> predictor_
;
229 mutable scoped_ptr
<ChromeURLRequestContext
> media_request_context_
;
231 mutable scoped_ptr
<net::URLRequestJobFactory
> main_job_factory_
;
232 mutable scoped_ptr
<net::URLRequestJobFactory
> extensions_job_factory_
;
234 mutable scoped_ptr
<domain_reliability::DomainReliabilityMonitor
>
235 domain_reliability_monitor_
;
237 // Parameters needed for isolated apps.
238 base::FilePath profile_path_
;
239 int app_cache_max_size_
;
240 int app_media_cache_max_size_
;
242 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData
);
245 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_