OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/resource_context_impl.h" | 5 #include "content/browser/resource_context_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/browser/appcache/chrome_appcache_service.h" | 8 #include "content/browser/appcache/chrome_appcache_service.h" |
9 #include "content/browser/fileapi/browser_file_system_helper.h" | 9 #include "content/browser/fileapi/browser_file_system_helper.h" |
10 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
25 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
26 #include "webkit/appcache/appcache_service.h" | 26 #include "webkit/appcache/appcache_service.h" |
27 #include "webkit/appcache/view_appcache_internals_job.h" | 27 #include "webkit/appcache/view_appcache_internals_job.h" |
28 #include "webkit/blob/blob_data.h" | 28 #include "webkit/blob/blob_data.h" |
29 #include "webkit/blob/blob_url_request_job_factory.h" | 29 #include "webkit/blob/blob_url_request_job_factory.h" |
30 #include "webkit/database/database_tracker.h" | 30 #include "webkit/database/database_tracker.h" |
31 #include "webkit/fileapi/file_system_url_request_job_factory.h" | 31 #include "webkit/fileapi/file_system_url_request_job_factory.h" |
32 | 32 |
33 // Key names on ResourceContext. | 33 // Key names on ResourceContext. |
34 static const char* kAppCacheServiceKeyName = "content_appcache_service_tracker"; | |
35 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; | 34 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; |
36 static const char* kHostZoomMapKeyName = "content_host_zoom_map"; | 35 static const char* kHostZoomMapKeyName = "content_host_zoom_map"; |
37 | 36 |
38 using appcache::AppCacheService; | 37 using appcache::AppCacheService; |
39 using base::UserDataAdapter; | 38 using base::UserDataAdapter; |
40 using content::BrowserThread; | 39 using content::BrowserThread; |
41 using fileapi::FileSystemContext; | 40 using fileapi::FileSystemContext; |
42 using webkit_blob::BlobStorageController; | 41 using webkit_blob::BlobStorageController; |
43 using webkit_database::DatabaseTracker; | 42 using webkit_database::DatabaseTracker; |
44 | 43 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 177 |
179 job_factory->AddInterceptor( | 178 job_factory->AddInterceptor( |
180 new DeveloperProtocolHandler(appcache_service, | 179 new DeveloperProtocolHandler(appcache_service, |
181 blob_storage_context->controller())); | 180 blob_storage_context->controller())); |
182 | 181 |
183 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! | 182 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! |
184 } | 183 } |
185 | 184 |
186 } // namespace | 185 } // namespace |
187 | 186 |
188 AppCacheService* ResourceContext::GetAppCacheService(ResourceContext* context) { | |
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
190 return UserDataAdapter<ChromeAppCacheService>::Get( | |
191 context, kAppCacheServiceKeyName); | |
192 } | |
193 | 187 |
194 ResourceContext::ResourceContext() { | 188 ResourceContext::ResourceContext() { |
195 if (ResourceDispatcherHostImpl::Get()) | 189 if (ResourceDispatcherHostImpl::Get()) |
196 ResourceDispatcherHostImpl::Get()->AddResourceContext(this); | 190 ResourceDispatcherHostImpl::Get()->AddResourceContext(this); |
197 } | 191 } |
198 | 192 |
199 ResourceContext::~ResourceContext() { | 193 ResourceContext::~ResourceContext() { |
200 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); | 194 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); |
201 if (rdhi) { | 195 if (rdhi) { |
202 rdhi->CancelRequestsForContext(this); | 196 rdhi->CancelRequestsForContext(this); |
203 rdhi->RemoveResourceContext(this); | 197 rdhi->RemoveResourceContext(this); |
204 } | 198 } |
205 } | 199 } |
206 | 200 |
207 BlobStorageController* GetBlobStorageControllerForResourceContext( | |
208 ResourceContext* resource_context) { | |
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
210 return GetChromeBlobStorageContextForResourceContext(resource_context)-> | |
211 controller(); | |
212 } | |
213 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( | 201 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( |
214 ResourceContext* resource_context) { | 202 ResourceContext* resource_context) { |
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
216 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 204 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
217 resource_context, kBlobStorageContextKeyName); | 205 resource_context, kBlobStorageContextKeyName); |
218 } | 206 } |
219 | 207 |
220 HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) { | 208 HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) { |
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
222 return static_cast<NonOwningZoomData*>( | 210 return static_cast<NonOwningZoomData*>( |
223 context->GetUserData(kHostZoomMapKeyName))->host_zoom_map(); | 211 context->GetUserData(kHostZoomMapKeyName))->host_zoom_map(); |
224 } | 212 } |
225 | 213 |
226 void InitializeResourceContext(BrowserContext* browser_context) { | 214 void InitializeResourceContext(BrowserContext* browser_context) { |
227 ResourceContext* resource_context = browser_context->GetResourceContext(); | 215 ResourceContext* resource_context = browser_context->GetResourceContext(); |
228 DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName)); | 216 DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName)); |
229 | 217 |
230 resource_context->SetUserData( | 218 resource_context->SetUserData( |
231 kAppCacheServiceKeyName, | |
232 new UserDataAdapter<ChromeAppCacheService>( | |
233 static_cast<ChromeAppCacheService*>( | |
234 BrowserContext::GetAppCacheService(browser_context)))); | |
235 resource_context->SetUserData( | |
236 kBlobStorageContextKeyName, | 219 kBlobStorageContextKeyName, |
237 new UserDataAdapter<ChromeBlobStorageContext>( | 220 new UserDataAdapter<ChromeBlobStorageContext>( |
238 ChromeBlobStorageContext::GetFor(browser_context))); | 221 ChromeBlobStorageContext::GetFor(browser_context))); |
239 | 222 |
240 // This object is owned by the BrowserContext and not ResourceContext, so | 223 // This object is owned by the BrowserContext and not ResourceContext, so |
241 // store a non-owning pointer here. | 224 // store a non-owning pointer here. |
242 resource_context->SetUserData( | 225 resource_context->SetUserData( |
243 kHostZoomMapKeyName, | 226 kHostZoomMapKeyName, |
244 new NonOwningZoomData( | 227 new NonOwningZoomData( |
245 HostZoomMap::GetForBrowserContext(browser_context))); | 228 HostZoomMap::GetForBrowserContext(browser_context))); |
246 resource_context->DetachUserDataThread(); | 229 resource_context->DetachUserDataThread(); |
247 | 230 |
| 231 StoragePartition* storage_partition = |
| 232 BrowserContext::GetDefaultStoragePartition(browser_context); |
| 233 |
248 // Add content's URLRequestContext's hooks. | 234 // Add content's URLRequestContext's hooks. |
249 // Check first to avoid memory leak in unittests. | 235 // Check first to avoid memory leak in unittests. |
250 // TODO(creis): Do equivalent initializations for isolated app and isolated | 236 // TODO(creis): Do equivalent initializations for isolated app and isolated |
251 // media request contexts. | 237 // media request contexts. |
252 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 238 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
253 // TODO(ajwong): Move this whole block into | 239 // TODO(ajwong): Move this whole block into |
254 // StoragePartitionImplMap::PostCreateInitialization after we're certain | 240 // StoragePartitionImplMap::PostCreateInitialization after we're certain |
255 // this is safe to happen before InitializeResourceContext, and after we've | 241 // this is safe to happen before InitializeResourceContext, and after we've |
256 // found the right URLRequestContext for a storage partition. Otherwise, | 242 // found the right URLRequestContext for a storage partition. Otherwise, |
257 // our isolated URLRequestContext getters will do the wrong thing for blobs, | 243 // our isolated URLRequestContext getters will do the wrong thing for blobs, |
258 // and FileSystemContext. | 244 // and FileSystemContext. |
259 // | 245 // |
260 // http://crbug.com/85121 | 246 // http://crbug.com/85121 |
261 | 247 |
262 BrowserThread::PostTask( | 248 BrowserThread::PostTask( |
263 BrowserThread::IO, FROM_HERE, | 249 BrowserThread::IO, FROM_HERE, |
264 base::Bind( | 250 base::Bind( |
265 &InitializeRequestContext, | 251 &InitializeRequestContext, |
266 make_scoped_refptr(browser_context->GetRequestContext()), | 252 make_scoped_refptr(browser_context->GetRequestContext()), |
267 BrowserContext::GetAppCacheService(browser_context), | 253 storage_partition->GetAppCacheService(), |
268 make_scoped_refptr( | 254 make_scoped_refptr( |
269 BrowserContext::GetFileSystemContext(browser_context)), | 255 storage_partition->GetFileSystemContext()), |
270 make_scoped_refptr( | 256 make_scoped_refptr( |
271 ChromeBlobStorageContext::GetFor(browser_context)))); | 257 ChromeBlobStorageContext::GetFor(browser_context)))); |
272 BrowserThread::PostTask( | 258 BrowserThread::PostTask( |
273 BrowserThread::IO, FROM_HERE, | 259 BrowserThread::IO, FROM_HERE, |
274 base::Bind( | 260 base::Bind( |
275 &InitializeRequestContext, | 261 &InitializeRequestContext, |
276 make_scoped_refptr(browser_context->GetMediaRequestContext()), | 262 make_scoped_refptr(browser_context->GetMediaRequestContext()), |
277 BrowserContext::GetAppCacheService(browser_context), | 263 storage_partition->GetAppCacheService(), |
278 make_scoped_refptr( | 264 make_scoped_refptr( |
279 BrowserContext::GetFileSystemContext(browser_context)), | 265 storage_partition->GetFileSystemContext()), |
280 make_scoped_refptr( | 266 make_scoped_refptr( |
281 ChromeBlobStorageContext::GetFor(browser_context)))); | 267 ChromeBlobStorageContext::GetFor(browser_context)))); |
282 } | 268 } |
283 } | 269 } |
284 | 270 |
285 } // namespace content | 271 } // namespace content |
OLD | NEW |