Update V8 to version 4.7.21.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_impl_io_data.h
blob214ec74b479d0c31a67beefaacc509b216613864
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 "base/prefs/pref_store.h"
13 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
14 #include "chrome/browser/net/chrome_url_request_context_getter.h"
15 #include "chrome/browser/profiles/profile_io_data.h"
16 #include "content/public/browser/cookie_store_factory.h"
18 class JsonPrefStore;
20 namespace chrome_browser_net {
21 class Predictor;
22 } // namespace chrome_browser_net
24 namespace data_reduction_proxy {
25 class DataReductionProxyNetworkDelegate;
26 } // namespace data_reduction_proxy
28 namespace domain_reliability {
29 class DomainReliabilityMonitor;
30 } // namespace domain_reliability
32 namespace net {
33 class CookieCryptoDelegate;
34 class FtpTransactionFactory;
35 class HttpServerProperties;
36 class HttpServerPropertiesManager;
37 class HttpTransactionFactory;
38 class ProxyConfig;
39 class SdchManager;
40 class SdchOwner;
41 } // namespace net
43 namespace storage {
44 class SpecialStoragePolicy;
45 } // namespace storage
47 class ProfileImplIOData : public ProfileIOData {
48 public:
49 class Handle {
50 public:
51 explicit Handle(Profile* profile);
52 ~Handle();
54 // Init() must be called before ~Handle(). It records most of the
55 // parameters needed to construct a ChromeURLRequestContextGetter.
56 void Init(
57 const base::FilePath& cookie_path,
58 const base::FilePath& channel_id_path,
59 const base::FilePath& cache_path,
60 int cache_max_size,
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 chrome_browser_net::Predictor* predictor,
66 content::CookieStoreConfig::SessionCookieMode session_cookie_mode,
67 storage::SpecialStoragePolicy* special_storage_policy,
68 scoped_ptr<domain_reliability::DomainReliabilityMonitor>
69 domain_reliability_monitor);
71 // These Create*ContextGetter() functions are only exposed because the
72 // circular relationship between Profile, ProfileIOData::Handle, and the
73 // ChromeURLRequestContextGetter factories requires Profile be able to call
74 // these functions.
75 scoped_refptr<ChromeURLRequestContextGetter> CreateMainRequestContextGetter(
76 content::ProtocolHandlerMap* protocol_handlers,
77 content::URLRequestInterceptorScopedVector request_interceptors,
78 PrefService* local_state,
79 IOThread* io_thread) const;
80 scoped_refptr<ChromeURLRequestContextGetter>
81 CreateIsolatedAppRequestContextGetter(
82 const base::FilePath& partition_path,
83 bool in_memory,
84 content::ProtocolHandlerMap* protocol_handlers,
85 content::URLRequestInterceptorScopedVector
86 request_interceptors) const;
88 content::ResourceContext* GetResourceContext() const;
89 // GetResourceContextNoInit() does not call LazyInitialize() so it can be
90 // safely be used during initialization.
91 content::ResourceContext* GetResourceContextNoInit() const;
92 scoped_refptr<ChromeURLRequestContextGetter>
93 GetMediaRequestContextGetter() const;
94 scoped_refptr<ChromeURLRequestContextGetter>
95 GetExtensionsRequestContextGetter() const;
96 scoped_refptr<ChromeURLRequestContextGetter>
97 GetIsolatedMediaRequestContextGetter(
98 const base::FilePath& partition_path,
99 bool in_memory) const;
101 // Returns the DevToolsNetworkControllerHandle attached to ProfileIOData.
102 DevToolsNetworkControllerHandle* GetDevToolsNetworkControllerHandle() const;
104 // Deletes all network related data since |time|. It deletes transport
105 // security state since |time| and also deletes HttpServerProperties data.
106 // Works asynchronously, however if the |completion| callback is non-null,
107 // it will be posted on the UI thread once the removal process completes.
108 void ClearNetworkingHistorySince(base::Time time,
109 const base::Closure& completion);
111 private:
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 // Collect references to context getters in reverse order, i.e. last item
125 // will be main request getter. This list is passed to |io_data_|
126 // for invalidation on IO thread.
127 scoped_ptr<ChromeURLRequestContextGetterVector> GetAllContextGetters();
129 // The getters will be invalidated on the IO thread before
130 // ProfileIOData instance is deleted.
131 mutable scoped_refptr<ChromeURLRequestContextGetter>
132 main_request_context_getter_;
133 mutable scoped_refptr<ChromeURLRequestContextGetter>
134 media_request_context_getter_;
135 mutable scoped_refptr<ChromeURLRequestContextGetter>
136 extensions_request_context_getter_;
137 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_;
138 mutable ChromeURLRequestContextGetterMap
139 isolated_media_request_context_getter_map_;
140 ProfileImplIOData* const io_data_;
142 Profile* const profile_;
144 mutable bool initialized_;
146 DISALLOW_COPY_AND_ASSIGN(Handle);
149 private:
150 friend class base::RefCountedThreadSafe<ProfileImplIOData>;
152 struct LazyParams {
153 LazyParams();
154 ~LazyParams();
156 // All of these parameters are intended to be read on the IO thread.
157 base::FilePath cookie_path;
158 base::FilePath channel_id_path;
159 base::FilePath cache_path;
160 int cache_max_size;
161 base::FilePath media_cache_path;
162 int media_cache_max_size;
163 base::FilePath extensions_cookie_path;
164 content::CookieStoreConfig::SessionCookieMode session_cookie_mode;
165 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy;
168 ProfileImplIOData();
169 ~ProfileImplIOData() override;
171 void InitializeInternal(
172 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate,
173 ProfileParams* profile_params,
174 content::ProtocolHandlerMap* protocol_handlers,
175 content::URLRequestInterceptorScopedVector
176 request_interceptors) const override;
177 void InitializeExtensionsRequestContext(
178 ProfileParams* profile_params) const override;
179 net::URLRequestContext* InitializeAppRequestContext(
180 net::URLRequestContext* main_context,
181 const StoragePartitionDescriptor& partition_descriptor,
182 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
183 protocol_handler_interceptor,
184 content::ProtocolHandlerMap* protocol_handlers,
185 content::URLRequestInterceptorScopedVector request_interceptors)
186 const override;
187 net::URLRequestContext* InitializeMediaRequestContext(
188 net::URLRequestContext* original_context,
189 const StoragePartitionDescriptor& partition_descriptor) const override;
190 net::URLRequestContext* AcquireMediaRequestContext() const override;
191 net::URLRequestContext* AcquireIsolatedAppRequestContext(
192 net::URLRequestContext* 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)
198 const override;
199 net::URLRequestContext* AcquireIsolatedMediaRequestContext(
200 net::URLRequestContext* app_context,
201 const StoragePartitionDescriptor& partition_descriptor) const override;
203 // Deletes all network related data since |time|. It deletes transport
204 // security state since |time| and also deletes HttpServerProperties data.
205 // Works asynchronously, however if the |completion| callback is non-null,
206 // it will be posted on the UI thread once the removal process completes.
207 void ClearNetworkingHistorySinceOnIOThread(base::Time time,
208 const base::Closure& completion);
210 mutable scoped_ptr<data_reduction_proxy::DataReductionProxyNetworkDelegate>
211 network_delegate_;
213 // Lazy initialization params.
214 mutable scoped_ptr<LazyParams> lazy_params_;
216 mutable scoped_refptr<JsonPrefStore> network_json_store_;
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_