Chromium Code Reviews| 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/storage_partition_impl_map.h" | 5 #include "content/browser/storage_partition_impl_map.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "content/browser/appcache/chrome_appcache_service.h" | 16 #include "content/browser/appcache/chrome_appcache_service.h" |
| 17 #include "content/browser/fileapi/browser_file_system_helper.h" | 17 #include "content/browser/fileapi/browser_file_system_helper.h" |
| 18 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 18 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 19 #include "content/browser/histogram_internals_request_job.h" | 19 #include "content/browser/histogram_internals_request_job.h" |
| 20 #include "content/browser/loader/resource_request_info_impl.h" | 20 #include "content/browser/loader/resource_request_info_impl.h" |
| 21 #include "content/browser/net/view_blob_internals_job_factory.h" | 21 #include "content/browser/net/view_blob_internals_job_factory.h" |
| 22 #include "content/browser/net/view_http_cache_job_factory.h" | 22 #include "content/browser/net/view_http_cache_job_factory.h" |
| 23 #include "content/browser/resource_context_impl.h" | 23 #include "content/browser/resource_context_impl.h" |
| 24 #include "content/browser/storage_partition_impl.h" | 24 #include "content/browser/storage_partition_impl.h" |
| 25 #include "content/browser/streams/chrome_stream_context.h" | |
| 26 #include "content/browser/streams/chrome_stream_registry.h" | |
| 27 #include "content/browser/streams/stream_url_request_job.h" | |
| 25 #include "content/browser/webui/url_data_manager_backend.h" | 28 #include "content/browser/webui/url_data_manager_backend.h" |
| 26 #include "content/browser/tcmalloc_internals_request_job.h" | 29 #include "content/browser/tcmalloc_internals_request_job.h" |
| 27 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
| 28 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/content_browser_client.h" | 32 #include "content/public/browser/content_browser_client.h" |
| 30 #include "content/public/browser/storage_partition.h" | 33 #include "content/public/browser/storage_partition.h" |
| 31 #include "content/public/common/content_constants.h" | 34 #include "content/public/common/content_constants.h" |
| 32 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
| 33 #include "crypto/sha2.h" | 36 #include "crypto/sha2.h" |
| 34 #include "net/url_request/url_request_context_getter.h" | 37 #include "net/url_request/url_request_context_getter.h" |
| 35 #include "net/url_request/url_request_context.h" | 38 #include "net/url_request/url_request_context.h" |
| 36 #include "webkit/appcache/view_appcache_internals_job.h" | 39 #include "webkit/appcache/view_appcache_internals_job.h" |
| 37 #include "webkit/blob/blob_data.h" | 40 #include "webkit/blob/blob_data.h" |
| 38 #include "webkit/blob/blob_url_request_job_factory.h" | 41 #include "webkit/blob/blob_url_request_job_factory.h" |
| 39 #include "webkit/fileapi/file_system_url_request_job_factory.h" | 42 #include "webkit/fileapi/file_system_url_request_job_factory.h" |
| 40 | 43 |
| 41 using appcache::AppCacheService; | 44 using appcache::AppCacheService; |
| 42 using fileapi::FileSystemContext; | 45 using fileapi::FileSystemContext; |
| 43 using webkit_blob::BlobStorageController; | 46 using webkit_blob::BlobStorageController; |
| 44 | 47 |
| 45 namespace content { | 48 namespace content { |
| 46 | 49 |
| 47 namespace { | 50 namespace { |
| 48 | 51 |
| 49 class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { | 52 class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { |
| 50 public: | 53 public: |
| 51 BlobProtocolHandler(ChromeBlobStorageContext* blob_storage_context, | 54 BlobProtocolHandler(ChromeBlobStorageContext* blob_storage_context, |
| 55 ChromeStreamContext* stream_context, | |
| 52 fileapi::FileSystemContext* file_system_context) | 56 fileapi::FileSystemContext* file_system_context) |
| 53 : blob_storage_context_(blob_storage_context), | 57 : blob_storage_context_(blob_storage_context), |
| 58 stream_context_(stream_context), | |
| 54 file_system_context_(file_system_context) {} | 59 file_system_context_(file_system_context) {} |
| 55 | 60 |
| 56 virtual ~BlobProtocolHandler() {} | 61 virtual ~BlobProtocolHandler() {} |
| 57 | 62 |
| 58 virtual net::URLRequestJob* MaybeCreateJob( | 63 virtual net::URLRequestJob* MaybeCreateJob( |
| 59 net::URLRequest* request, | 64 net::URLRequest* request, |
| 60 net::NetworkDelegate* network_delegate) const OVERRIDE { | 65 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 62 if (!webkit_blob_protocol_handler_impl_) { | 67 if (!webkit_blob_protocol_handler_impl_) { |
| 63 webkit_blob_protocol_handler_impl_.reset( | 68 webkit_blob_protocol_handler_impl_.reset( |
| 64 new WebKitBlobProtocolHandlerImpl(blob_storage_context_->controller(), | 69 new WebKitBlobProtocolHandlerImpl(blob_storage_context_->controller(), |
| 70 stream_context_, | |
| 65 file_system_context_)); | 71 file_system_context_)); |
| 66 } | 72 } |
| 67 return webkit_blob_protocol_handler_impl_->MaybeCreateJob(request, | 73 return webkit_blob_protocol_handler_impl_->MaybeCreateJob(request, |
| 68 network_delegate); | 74 network_delegate); |
| 69 } | 75 } |
| 70 | 76 |
| 71 private: | 77 private: |
| 72 // An implementation of webkit_blob::BlobProtocolHandler that gets | 78 // An implementation of webkit_blob::BlobProtocolHandler that gets |
| 73 // the BlobData from ResourceRequestInfoImpl. | 79 // the BlobData from ResourceRequestInfoImpl. |
| 74 class WebKitBlobProtocolHandlerImpl | 80 class WebKitBlobProtocolHandlerImpl |
| 75 : public webkit_blob::BlobProtocolHandler { | 81 : public webkit_blob::BlobProtocolHandler { |
| 76 public: | 82 public: |
| 77 WebKitBlobProtocolHandlerImpl( | 83 WebKitBlobProtocolHandlerImpl( |
| 78 webkit_blob::BlobStorageController* blob_storage_controller, | 84 webkit_blob::BlobStorageController* blob_storage_controller, |
| 85 ChromeStreamContext* stream_context, | |
| 79 fileapi::FileSystemContext* file_system_context) | 86 fileapi::FileSystemContext* file_system_context) |
| 80 : webkit_blob::BlobProtocolHandler( | 87 : webkit_blob::BlobProtocolHandler( |
| 81 blob_storage_controller, file_system_context, | 88 blob_storage_controller, file_system_context, |
| 82 BrowserThread::GetMessageLoopProxyForThread( | 89 BrowserThread::GetMessageLoopProxyForThread( |
| 83 BrowserThread::FILE)) {} | 90 BrowserThread::FILE)), |
| 91 stream_context_(stream_context) {} | |
| 84 | 92 |
| 85 virtual ~WebKitBlobProtocolHandlerImpl() {} | 93 virtual ~WebKitBlobProtocolHandlerImpl() {} |
| 86 | 94 |
| 95 virtual net::URLRequestJob* MaybeCreateJob( | |
| 96 net::URLRequest* request, | |
| 97 net::NetworkDelegate* network_delegate) const { | |
| 98 scoped_refptr<ChromeStream> stream = | |
| 99 stream_context_->registry()->GetStream(request->url()); | |
| 100 if (stream) { | |
| 101 return new StreamURLRequestJob(request, network_delegate, stream); | |
| 102 } else { | |
|
darin (slow to review)
2013/02/13 09:18:12
nit: no need for else after return.
Zachary Kuznia
2013/02/13 16:37:14
Done.
| |
| 103 return webkit_blob::BlobProtocolHandler::MaybeCreateJob( | |
| 104 request, network_delegate); | |
| 105 } | |
| 106 } | |
| 107 | |
| 87 private: | 108 private: |
| 88 // webkit_blob::BlobProtocolHandler implementation. | 109 // webkit_blob::BlobProtocolHandler implementation. |
| 89 virtual scoped_refptr<webkit_blob::BlobData> | 110 virtual scoped_refptr<webkit_blob::BlobData> |
| 90 LookupBlobData(net::URLRequest* request) const OVERRIDE { | 111 LookupBlobData(net::URLRequest* request) const OVERRIDE { |
| 91 const ResourceRequestInfoImpl* info = | 112 const ResourceRequestInfoImpl* info = |
| 92 ResourceRequestInfoImpl::ForRequest(request); | 113 ResourceRequestInfoImpl::ForRequest(request); |
| 93 if (!info) | 114 if (!info) |
| 94 return NULL; | 115 return NULL; |
| 95 return info->requested_blob_data(); | 116 return info->requested_blob_data(); |
| 96 } | 117 } |
| 97 | 118 |
| 119 const scoped_refptr<ChromeStreamContext> stream_context_; | |
| 98 DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); | 120 DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); |
| 99 }; | 121 }; |
| 100 | 122 |
| 101 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 123 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 124 const scoped_refptr<ChromeStreamContext> stream_context_; | |
| 102 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 125 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 103 | 126 |
| 104 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> | 127 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> |
| 105 webkit_blob_protocol_handler_impl_; | 128 webkit_blob_protocol_handler_impl_; |
| 106 | 129 |
| 107 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); | 130 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); |
| 108 }; | 131 }; |
| 109 | 132 |
| 110 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol | 133 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol |
| 111 // handler because we want to reuse the chrome://scheme (everyone is familiar | 134 // handler because we want to reuse the chrome://scheme (everyone is familiar |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 base::FilePath partition_path = | 463 base::FilePath partition_path = |
| 441 browser_context_->GetPath().Append( | 464 browser_context_->GetPath().Append( |
| 442 GetStoragePartitionPath(partition_domain, partition_name)); | 465 GetStoragePartitionPath(partition_domain, partition_name)); |
| 443 StoragePartitionImpl* partition = | 466 StoragePartitionImpl* partition = |
| 444 StoragePartitionImpl::Create(browser_context_, in_memory, | 467 StoragePartitionImpl::Create(browser_context_, in_memory, |
| 445 partition_path); | 468 partition_path); |
| 446 partitions_[partition_config] = partition; | 469 partitions_[partition_config] = partition; |
| 447 | 470 |
| 448 ChromeBlobStorageContext* blob_storage_context = | 471 ChromeBlobStorageContext* blob_storage_context = |
| 449 ChromeBlobStorageContext::GetFor(browser_context_); | 472 ChromeBlobStorageContext::GetFor(browser_context_); |
| 473 ChromeStreamContext* stream_context = | |
| 474 ChromeStreamContext::GetFor(browser_context_); | |
| 450 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( | 475 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( |
| 451 new BlobProtocolHandler(blob_storage_context, | 476 new BlobProtocolHandler( |
| 452 partition->GetFileSystemContext())); | 477 blob_storage_context, |
| 478 stream_context, | |
| 479 partition->GetFileSystemContext())); | |
| 453 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 480 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 454 file_system_protocol_handler( | 481 file_system_protocol_handler( |
| 455 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); | 482 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); |
| 456 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 483 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 457 developer_protocol_handler( | 484 developer_protocol_handler( |
| 458 new DeveloperProtocolHandler(partition->GetAppCacheService(), | 485 new DeveloperProtocolHandler(partition->GetAppCacheService(), |
| 459 blob_storage_context)); | 486 blob_storage_context)); |
| 460 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 487 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 461 chrome_protocol_handler( | 488 chrome_protocol_handler( |
| 462 URLDataManagerBackend::CreateProtocolHandler( | 489 URLDataManagerBackend::CreateProtocolHandler( |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 | 629 |
| 603 // We do not call InitializeURLRequestContext() for media contexts because, | 630 // We do not call InitializeURLRequestContext() for media contexts because, |
| 604 // other than the HTTP cache, the media contexts share the same backing | 631 // other than the HTTP cache, the media contexts share the same backing |
| 605 // objects as their associated "normal" request context. Thus, the previous | 632 // objects as their associated "normal" request context. Thus, the previous |
| 606 // call serves to initialize the media request context for this storage | 633 // call serves to initialize the media request context for this storage |
| 607 // partition as well. | 634 // partition as well. |
| 608 } | 635 } |
| 609 } | 636 } |
| 610 | 637 |
| 611 } // namespace content | 638 } // namespace content |
| OLD | NEW |