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/hash_tables.h"
11 #include "base/memory/ref_counted.h"
12 #include "chrome/browser/profiles/profile_io_data.h"
14 namespace chrome_browser_net
{
16 } // namespace chrome_browser_net
19 class HttpServerProperties
;
20 class HttpTransactionFactory
;
24 class SpecialStoragePolicy
;
27 class ProfileImplIOData
: public ProfileIOData
{
31 explicit Handle(Profile
* profile
);
34 bool HasMainRequestContext() const {
35 return main_request_context_getter_
!= NULL
;
38 // Init() must be called before ~Handle(). It records all the necessary
39 // parameters needed to construct a ChromeURLRequestContextGetter.
40 void Init(const FilePath
& cookie_path
,
41 const FilePath
& server_bound_cert_path
,
42 const FilePath
& cache_path
,
44 const FilePath
& media_cache_path
,
45 int media_cache_max_size
,
46 const FilePath
& extensions_cookie_path
,
47 const FilePath
& profile_path
,
48 const FilePath
& infinite_cache_path
,
49 chrome_browser_net::Predictor
* predictor
,
50 PrefService
* local_state
,
52 bool restore_old_session_cookies
,
53 quota::SpecialStoragePolicy
* special_storage_policy
);
55 base::Callback
<ChromeURLDataManagerBackend
*(void)>
56 GetChromeURLDataManagerBackendGetter() const;
57 content::ResourceContext
* GetResourceContext() const;
58 // GetResourceContextNoInit() does not call LazyInitialize() so it can be
59 // safely be used during initialization.
60 content::ResourceContext
* GetResourceContextNoInit() const;
61 scoped_refptr
<ChromeURLRequestContextGetter
>
62 GetMainRequestContextGetter() const;
63 scoped_refptr
<ChromeURLRequestContextGetter
>
64 GetMediaRequestContextGetter() const;
65 scoped_refptr
<ChromeURLRequestContextGetter
>
66 GetExtensionsRequestContextGetter() const;
67 scoped_refptr
<ChromeURLRequestContextGetter
>
68 GetIsolatedAppRequestContextGetter(
69 const FilePath
& partition_path
,
70 bool in_memory
) const;
71 scoped_refptr
<ChromeURLRequestContextGetter
>
72 GetIsolatedMediaRequestContextGetter(
73 const FilePath
& partition_path
,
74 bool in_memory
) const;
76 // Deletes all network related data since |time|. It deletes transport
77 // security state since |time| and also deletes HttpServerProperties data.
78 // Works asynchronously, however if the |completion| callback is non-null,
79 // it will be posted on the UI thread once the removal process completes.
80 void ClearNetworkingHistorySince(base::Time time
,
81 const base::Closure
& completion
);
84 typedef std::map
<StoragePartitionDescriptor
,
85 scoped_refptr
<ChromeURLRequestContextGetter
>,
86 StoragePartitionDescriptorLess
>
87 ChromeURLRequestContextGetterMap
;
89 // Lazily initialize ProfileParams. We do this on the calls to
90 // Get*RequestContextGetter(), so we only initialize ProfileParams right
91 // before posting a task to the IO thread to start using them. This prevents
92 // objects that are supposed to be deleted on the IO thread, but are created
93 // on the UI thread from being unnecessarily initialized.
94 void LazyInitialize() const;
96 // Ordering is important here. Do not reorder unless you know what you're
97 // doing. We need to release |io_data_| *before* the getters, because we
98 // want to make sure that the last reference for |io_data_| is on the IO
99 // thread. The getters will be deleted on the IO thread, so they will
100 // release their refs to their contexts, which will release the last refs to
101 // the ProfileIOData on the IO thread.
102 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
103 main_request_context_getter_
;
104 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
105 media_request_context_getter_
;
106 mutable scoped_refptr
<ChromeURLRequestContextGetter
>
107 extensions_request_context_getter_
;
108 mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_
;
109 mutable ChromeURLRequestContextGetterMap
110 isolated_media_request_context_getter_map_
;
111 ProfileImplIOData
* const io_data_
;
113 Profile
* const profile_
;
115 mutable bool initialized_
;
117 DISALLOW_COPY_AND_ASSIGN(Handle
);
121 friend class base::RefCountedThreadSafe
<ProfileImplIOData
>;
127 // All of these parameters are intended to be read on the IO thread.
128 FilePath cookie_path
;
129 FilePath server_bound_cert_path
;
132 FilePath media_cache_path
;
133 int media_cache_max_size
;
134 FilePath extensions_cookie_path
;
135 FilePath infinite_cache_path
;
136 bool restore_old_session_cookies
;
137 scoped_refptr
<quota::SpecialStoragePolicy
> special_storage_policy
;
140 typedef base::hash_map
<std::string
, net::HttpTransactionFactory
* >
141 HttpTransactionFactoryMap
;
144 virtual ~ProfileImplIOData();
146 virtual void LazyInitializeInternal(
147 ProfileParams
* profile_params
) const OVERRIDE
;
148 virtual void InitializeExtensionsRequestContext(
149 ProfileParams
* profile_params
) const OVERRIDE
;
150 virtual ChromeURLRequestContext
* InitializeAppRequestContext(
151 ChromeURLRequestContext
* main_context
,
152 const StoragePartitionDescriptor
& partition_descriptor
,
153 scoped_ptr
<net::URLRequestJobFactory::Interceptor
>
154 protocol_handler_interceptor
) const OVERRIDE
;
155 virtual ChromeURLRequestContext
* InitializeMediaRequestContext(
156 ChromeURLRequestContext
* original_context
,
157 const StoragePartitionDescriptor
& partition_descriptor
) const OVERRIDE
;
158 virtual ChromeURLRequestContext
*
159 AcquireMediaRequestContext() const OVERRIDE
;
160 virtual ChromeURLRequestContext
*
161 AcquireIsolatedAppRequestContext(
162 ChromeURLRequestContext
* main_context
,
163 const StoragePartitionDescriptor
& partition_descriptor
,
164 scoped_ptr
<net::URLRequestJobFactory::Interceptor
>
165 protocol_handler_interceptor
) const OVERRIDE
;
166 virtual ChromeURLRequestContext
*
167 AcquireIsolatedMediaRequestContext(
168 ChromeURLRequestContext
* app_context
,
169 const StoragePartitionDescriptor
& partition_descriptor
)
171 virtual chrome_browser_net::LoadTimeStats
* GetLoadTimeStats(
172 IOThread::Globals
* io_thread_globals
) const OVERRIDE
;
174 void SetUpJobFactory(net::URLRequestJobFactoryImpl
* job_factory
,
175 scoped_ptr
<net::URLRequestJobFactory::Interceptor
>
176 protocol_handler_interceptor
,
177 net::NetworkDelegate
* network_delegate
,
178 net::FtpTransactionFactory
* ftp_transaction_factory
,
179 net::FtpAuthCache
* ftp_auth_cache
) const;
181 // Deletes all network related data since |time|. It deletes transport
182 // security state since |time| and also deletes HttpServerProperties data.
183 // Works asynchronously, however if the |completion| callback is non-null,
184 // it will be posted on the UI thread once the removal process completes.
185 void ClearNetworkingHistorySinceOnIOThread(base::Time time
,
186 const base::Closure
& completion
);
188 // Lazy initialization params.
189 mutable scoped_ptr
<LazyParams
> lazy_params_
;
191 mutable scoped_ptr
<net::HttpTransactionFactory
> main_http_factory_
;
192 mutable scoped_ptr
<net::FtpTransactionFactory
> ftp_factory_
;
194 mutable scoped_ptr
<chrome_browser_net::Predictor
> predictor_
;
196 mutable scoped_ptr
<ChromeURLRequestContext
> media_request_context_
;
198 mutable scoped_ptr
<net::URLRequestJobFactory
> main_job_factory_
;
199 mutable scoped_ptr
<net::URLRequestJobFactory
> extensions_job_factory_
;
201 // Parameters needed for isolated apps.
202 FilePath profile_path_
;
203 int app_cache_max_size_
;
204 int app_media_cache_max_size_
;
206 DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData
);
209 #endif // CHROME_BROWSER_PROFILES_PROFILE_IMPL_IO_DATA_H_