Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / profiles / profile_impl_io_data.h
blob27125b5d59433146ad5317e7a21900c6fddf0ece
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 {
18 class Predictor;
19 } // namespace chrome_browser_net
21 namespace content {
22 class CookieCryptoDelegate;
23 } // namespace content
25 namespace domain_reliability {
26 class DomainReliabilityMonitor;
27 } // namespace domain_reliability
29 namespace net {
30 class FtpTransactionFactory;
31 class HttpServerProperties;
32 class HttpServerPropertiesManager;
33 class HttpTransactionFactory;
34 class ProxyConfig;
35 class SDCHManager;
36 } // namespace net
38 namespace storage {
39 class SpecialStoragePolicy;
40 } // namespace storage
42 class ProfileImplIOData : public ProfileIOData {
43 public:
44 class Handle {
45 public:
46 explicit Handle(Profile* profile);
47 ~Handle();
49 // Init() must be called before ~Handle(). It records most of the
50 // parameters needed to construct a ChromeURLRequestContextGetter.
51 void Init(
52 const base::FilePath& cookie_path,
53 const base::FilePath& channel_id_path,
54 const base::FilePath& cache_path,
55 int cache_max_size,
56 const base::FilePath& media_cache_path,
57 int media_cache_max_size,
58 const base::FilePath& extensions_cookie_path,
59 const base::FilePath& profile_path,
60 const base::FilePath& infinite_cache_path,
61 chrome_browser_net::Predictor* predictor,
62 content::CookieStoreConfig::SessionCookieMode session_cookie_mode,
63 storage::SpecialStoragePolicy* special_storage_policy,
64 scoped_ptr<domain_reliability::DomainReliabilityMonitor>
65 domain_reliability_monitor,
66 const base::Callback<void(bool)>& data_reduction_proxy_unavailable,
67 scoped_ptr<DataReductionProxyChromeConfigurator>
68 data_reduction_proxy_chrome_configurator,
69 scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
70 data_reduction_proxy_params,
71 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>
72 data_reduction_proxy_statistics_prefs);
74 // These Create*ContextGetter() functions are only exposed because the
75 // circular relationship between Profile, ProfileIOData::Handle, and the
76 // ChromeURLRequestContextGetter factories requires Profile be able to call
77 // these functions.
78 scoped_refptr<ChromeURLRequestContextGetter> CreateMainRequestContextGetter(
79 content::ProtocolHandlerMap* protocol_handlers,
80 content::URLRequestInterceptorScopedVector request_interceptors,
81 PrefService* local_state,
82 IOThread* io_thread) const;
83 scoped_refptr<ChromeURLRequestContextGetter>
84 CreateIsolatedAppRequestContextGetter(
85 const base::FilePath& partition_path,
86 bool in_memory,
87 content::ProtocolHandlerMap* protocol_handlers,
88 content::URLRequestInterceptorScopedVector
89 request_interceptors) const;
91 content::ResourceContext* GetResourceContext() const;
92 // GetResourceContextNoInit() does not call LazyInitialize() so it can be
93 // safely be used during initialization.
94 content::ResourceContext* GetResourceContextNoInit() const;
95 scoped_refptr<ChromeURLRequestContextGetter>
96 GetMediaRequestContextGetter() const;
97 scoped_refptr<ChromeURLRequestContextGetter>
98 GetExtensionsRequestContextGetter() const;
99 scoped_refptr<ChromeURLRequestContextGetter>
100 GetIsolatedMediaRequestContextGetter(
101 const base::FilePath& partition_path,
102 bool in_memory) const;
104 // Returns the DevToolsNetworkController attached to ProfileIOData.
105 DevToolsNetworkController* GetDevToolsNetworkController() const;
107 // Deletes all network related data since |time|. It deletes transport
108 // security state since |time| and also deletes HttpServerProperties data.
109 // Works asynchronously, however if the |completion| callback is non-null,
110 // it will be posted on the UI thread once the removal process completes.
111 void ClearNetworkingHistorySince(base::Time time,
112 const base::Closure& completion);
114 private:
115 typedef std::map<StoragePartitionDescriptor,
116 scoped_refptr<ChromeURLRequestContextGetter>,
117 StoragePartitionDescriptorLess>
118 ChromeURLRequestContextGetterMap;
120 // Lazily initialize ProfileParams. We do this on the calls to
121 // Get*RequestContextGetter(), so we only initialize ProfileParams right
122 // before posting a task to the IO thread to start using them. This prevents
123 // objects that are supposed to be deleted on the IO thread, but are created
124 // on the UI thread from being unnecessarily initialized.
125 void LazyInitialize() const;
127 // Collect references to context getters in reverse order, i.e. last item
128 // will be main request getter. This list is passed to |io_data_|
129 // for invalidation on IO thread.
130 scoped_ptr<ChromeURLRequestContextGetterVector> GetAllContextGetters();
132 // The getters will be invalidated on the IO thread before
133 // ProfileIOData instance is deleted.
134 mutable scoped_refptr<ChromeURLRequestContextGetter>
135 main_request_context_getter_;
136 mutable scoped_refptr<ChromeURLRequestContextGetter>
137 media_request_context_getter_;
138 mutable scoped_refptr<ChromeURLRequestContextGetter>
139 extensions_request_context_getter_;
140 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_;
141 mutable ChromeURLRequestContextGetterMap
142 isolated_media_request_context_getter_map_;
143 ProfileImplIOData* const io_data_;
145 Profile* const profile_;
147 mutable bool initialized_;
149 DISALLOW_COPY_AND_ASSIGN(Handle);
152 virtual bool IsDataReductionProxyEnabled() const override;
154 BooleanPrefMember* data_reduction_proxy_enabled() const {
155 return &data_reduction_proxy_enabled_;
158 private:
159 friend class base::RefCountedThreadSafe<ProfileImplIOData>;
161 struct LazyParams {
162 LazyParams();
163 ~LazyParams();
165 // All of these parameters are intended to be read on the IO thread.
166 base::FilePath cookie_path;
167 base::FilePath channel_id_path;
168 base::FilePath cache_path;
169 int cache_max_size;
170 base::FilePath media_cache_path;
171 int media_cache_max_size;
172 base::FilePath extensions_cookie_path;
173 base::FilePath infinite_cache_path;
174 content::CookieStoreConfig::SessionCookieMode session_cookie_mode;
175 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy;
178 ProfileImplIOData();
179 virtual ~ProfileImplIOData();
181 virtual void InitializeInternal(
182 ProfileParams* profile_params,
183 content::ProtocolHandlerMap* protocol_handlers,
184 content::URLRequestInterceptorScopedVector request_interceptors)
185 const override;
186 virtual void InitializeExtensionsRequestContext(
187 ProfileParams* profile_params) const override;
188 virtual net::URLRequestContext* InitializeAppRequestContext(
189 net::URLRequestContext* main_context,
190 const StoragePartitionDescriptor& partition_descriptor,
191 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
192 protocol_handler_interceptor,
193 content::ProtocolHandlerMap* protocol_handlers,
194 content::URLRequestInterceptorScopedVector request_interceptors)
195 const override;
196 virtual net::URLRequestContext* InitializeMediaRequestContext(
197 net::URLRequestContext* original_context,
198 const StoragePartitionDescriptor& partition_descriptor) const override;
199 virtual net::URLRequestContext*
200 AcquireMediaRequestContext() const override;
201 virtual net::URLRequestContext* AcquireIsolatedAppRequestContext(
202 net::URLRequestContext* main_context,
203 const StoragePartitionDescriptor& partition_descriptor,
204 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
205 protocol_handler_interceptor,
206 content::ProtocolHandlerMap* protocol_handlers,
207 content::URLRequestInterceptorScopedVector request_interceptors)
208 const override;
209 virtual net::URLRequestContext*
210 AcquireIsolatedMediaRequestContext(
211 net::URLRequestContext* app_context,
212 const StoragePartitionDescriptor& partition_descriptor)
213 const override;
215 // Deletes all network related data since |time|. It deletes transport
216 // security state since |time| and also deletes HttpServerProperties data.
217 // Works asynchronously, however if the |completion| callback is non-null,
218 // it will be posted on the UI thread once the removal process completes.
219 void ClearNetworkingHistorySinceOnIOThread(base::Time time,
220 const base::Closure& completion);
222 // Lazy initialization params.
223 mutable scoped_ptr<LazyParams> lazy_params_;
225 mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
226 mutable scoped_ptr<net::FtpTransactionFactory> ftp_factory_;
228 // Same as |ProfileIOData::http_server_properties_|, owned there to maintain
229 // destruction ordering.
230 mutable net::HttpServerPropertiesManager* http_server_properties_manager_;
232 mutable scoped_ptr<chrome_browser_net::Predictor> predictor_;
234 mutable scoped_ptr<net::URLRequestContext> media_request_context_;
236 mutable scoped_ptr<net::URLRequestJobFactory> main_job_factory_;
237 mutable scoped_ptr<net::URLRequestJobFactory> extensions_job_factory_;
239 mutable scoped_ptr<domain_reliability::DomainReliabilityMonitor>
240 domain_reliability_monitor_;
242 mutable scoped_ptr<net::SdchManager> sdch_manager_;
244 mutable BooleanPrefMember data_reduction_proxy_enabled_;
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 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData);
254 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_