Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_impl_io_data.h
blobc88435989963f336a941126cf3a49972d948223a
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 "content/public/browser/cookie_store_factory.h"
16 namespace chrome_browser_net {
17 class HttpServerPropertiesManager;
18 class Predictor;
19 } // namespace chrome_browser_net
21 namespace content {
22 class CookieCryptoDelegate;
23 } // namespace content
25 namespace net {
26 class FtpTransactionFactory;
27 class HttpServerProperties;
28 class HttpTransactionFactory;
29 } // namespace net
31 namespace quota {
32 class SpecialStoragePolicy;
33 } // namespace quota
35 class ProfileImplIOData : public ProfileIOData {
36 public:
37 class Handle {
38 public:
39 explicit Handle(Profile* profile);
40 ~Handle();
42 // Init() must be called before ~Handle(). It records most of the
43 // parameters needed to construct a ChromeURLRequestContextGetter.
44 void Init(const base::FilePath& cookie_path,
45 const base::FilePath& server_bound_cert_path,
46 const base::FilePath& cache_path,
47 int cache_max_size,
48 const base::FilePath& media_cache_path,
49 int media_cache_max_size,
50 const base::FilePath& extensions_cookie_path,
51 const base::FilePath& profile_path,
52 const base::FilePath& infinite_cache_path,
53 chrome_browser_net::Predictor* predictor,
54 content::CookieStoreConfig::SessionCookieMode
55 session_cookie_mode,
56 quota::SpecialStoragePolicy* special_storage_policy);
58 // These Create*ContextGetter() functions are only exposed because the
59 // circular relationship between Profile, ProfileIOData::Handle, and the
60 // ChromeURLRequestContextGetter factories requires Profile be able to call
61 // these functions.
62 scoped_refptr<ChromeURLRequestContextGetter>
63 CreateMainRequestContextGetter(
64 content::ProtocolHandlerMap* protocol_handlers,
65 PrefService* local_state,
66 IOThread* io_thread) const;
67 scoped_refptr<ChromeURLRequestContextGetter>
68 CreateIsolatedAppRequestContextGetter(
69 const base::FilePath& partition_path,
70 bool in_memory,
71 content::ProtocolHandlerMap* protocol_handlers) const;
73 content::ResourceContext* GetResourceContext() const;
74 // GetResourceContextNoInit() does not call LazyInitialize() so it can be
75 // safely be used during initialization.
76 content::ResourceContext* GetResourceContextNoInit() const;
77 scoped_refptr<ChromeURLRequestContextGetter>
78 GetMediaRequestContextGetter() const;
79 scoped_refptr<ChromeURLRequestContextGetter>
80 GetExtensionsRequestContextGetter() const;
81 scoped_refptr<ChromeURLRequestContextGetter>
82 GetIsolatedMediaRequestContextGetter(
83 const base::FilePath& partition_path,
84 bool in_memory) const;
86 // Deletes all network related data since |time|. It deletes transport
87 // security state since |time| and also deletes HttpServerProperties data.
88 // Works asynchronously, however if the |completion| callback is non-null,
89 // it will be posted on the UI thread once the removal process completes.
90 void ClearNetworkingHistorySince(base::Time time,
91 const base::Closure& completion);
93 private:
94 typedef std::map<StoragePartitionDescriptor,
95 scoped_refptr<ChromeURLRequestContextGetter>,
96 StoragePartitionDescriptorLess>
97 ChromeURLRequestContextGetterMap;
99 // Lazily initialize ProfileParams. We do this on the calls to
100 // Get*RequestContextGetter(), so we only initialize ProfileParams right
101 // before posting a task to the IO thread to start using them. This prevents
102 // objects that are supposed to be deleted on the IO thread, but are created
103 // on the UI thread from being unnecessarily initialized.
104 void LazyInitialize() const;
106 // Ordering is important here. Do not reorder unless you know what you're
107 // doing. We need to release |io_data_| *before* the getters, because we
108 // want to make sure that the last reference for |io_data_| is on the IO
109 // thread. The getters will be deleted on the IO thread, so they will
110 // release their refs to their contexts, which will release the last refs to
111 // the ProfileIOData on the IO thread.
112 mutable scoped_refptr<ChromeURLRequestContextGetter>
113 main_request_context_getter_;
114 mutable scoped_refptr<ChromeURLRequestContextGetter>
115 media_request_context_getter_;
116 mutable scoped_refptr<ChromeURLRequestContextGetter>
117 extensions_request_context_getter_;
118 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_;
119 mutable ChromeURLRequestContextGetterMap
120 isolated_media_request_context_getter_map_;
121 ProfileImplIOData* const io_data_;
123 Profile* const profile_;
125 mutable bool initialized_;
127 DISALLOW_COPY_AND_ASSIGN(Handle);
130 private:
131 friend class base::RefCountedThreadSafe<ProfileImplIOData>;
133 struct LazyParams {
134 LazyParams();
135 ~LazyParams();
137 // All of these parameters are intended to be read on the IO thread.
138 base::FilePath cookie_path;
139 base::FilePath server_bound_cert_path;
140 base::FilePath cache_path;
141 int cache_max_size;
142 base::FilePath media_cache_path;
143 int media_cache_max_size;
144 base::FilePath extensions_cookie_path;
145 base::FilePath infinite_cache_path;
146 content::CookieStoreConfig::SessionCookieMode session_cookie_mode;
147 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy;
150 ProfileImplIOData();
151 virtual ~ProfileImplIOData();
153 virtual void InitializeInternal(
154 ProfileParams* profile_params,
155 content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE;
156 virtual void InitializeExtensionsRequestContext(
157 ProfileParams* profile_params) const OVERRIDE;
158 virtual ChromeURLRequestContext* InitializeAppRequestContext(
159 ChromeURLRequestContext* main_context,
160 const StoragePartitionDescriptor& partition_descriptor,
161 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
162 protocol_handler_interceptor,
163 content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE;
164 virtual ChromeURLRequestContext* InitializeMediaRequestContext(
165 ChromeURLRequestContext* original_context,
166 const StoragePartitionDescriptor& partition_descriptor) const OVERRIDE;
167 virtual ChromeURLRequestContext*
168 AcquireMediaRequestContext() const OVERRIDE;
169 virtual ChromeURLRequestContext*
170 AcquireIsolatedAppRequestContext(
171 ChromeURLRequestContext* main_context,
172 const StoragePartitionDescriptor& partition_descriptor,
173 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
174 protocol_handler_interceptor,
175 content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE;
176 virtual ChromeURLRequestContext*
177 AcquireIsolatedMediaRequestContext(
178 ChromeURLRequestContext* app_context,
179 const StoragePartitionDescriptor& partition_descriptor)
180 const OVERRIDE;
182 // Deletes all network related data since |time|. It deletes transport
183 // security state since |time| and also deletes HttpServerProperties data.
184 // Works asynchronously, however if the |completion| callback is non-null,
185 // it will be posted on the UI thread once the removal process completes.
186 void ClearNetworkingHistorySinceOnIOThread(base::Time time,
187 const base::Closure& completion);
189 // Lazy initialization params.
190 mutable scoped_ptr<LazyParams> lazy_params_;
192 mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
193 mutable scoped_ptr<net::FtpTransactionFactory> ftp_factory_;
195 // Same as |ProfileIOData::http_server_properties_|, owned there to maintain
196 // destruction ordering.
197 mutable chrome_browser_net::HttpServerPropertiesManager*
198 http_server_properties_manager_;
200 mutable scoped_ptr<chrome_browser_net::Predictor> predictor_;
202 mutable scoped_ptr<ChromeURLRequestContext> media_request_context_;
204 mutable scoped_ptr<net::URLRequestJobFactory> main_job_factory_;
205 mutable scoped_ptr<net::URLRequestJobFactory> extensions_job_factory_;
207 // Parameters needed for isolated apps.
208 base::FilePath profile_path_;
209 int app_cache_max_size_;
210 int app_media_cache_max_size_;
212 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData);
215 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_