| 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_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "content/browser/appcache/chrome_appcache_service.h" | 17 #include "content/browser/appcache/chrome_appcache_service.h" |
| 18 #include "content/browser/fileapi/browser_file_system_helper.h" | 18 #include "content/browser/fileapi/browser_file_system_helper.h" |
| 19 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 19 #include "content/browser/fileapi/chrome_blob_storage_context.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/resource_context_impl.h" | 21 #include "content/browser/resource_context_impl.h" |
| 22 #include "content/browser/storage_partition_impl.h" | 22 #include "content/browser/storage_partition_impl.h" |
| 23 #include "content/browser/streams/stream.h" | 23 #include "content/browser/streams/stream.h" |
| 24 #include "content/browser/streams/stream_context.h" | |
| 25 #include "content/browser/streams/stream_registry.h" | 24 #include "content/browser/streams/stream_registry.h" |
| 26 #include "content/browser/streams/stream_url_request_job.h" | 25 #include "content/browser/streams/stream_url_request_job.h" |
| 27 #include "content/browser/webui/url_data_manager_backend.h" | 26 #include "content/browser/webui/url_data_manager_backend.h" |
| 28 #include "content/public/browser/browser_context.h" | 27 #include "content/public/browser/browser_context.h" |
| 29 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
| 32 #include "content/public/common/content_constants.h" | 31 #include "content/public/common/content_constants.h" |
| 33 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
| 34 #include "crypto/sha2.h" | 33 #include "crypto/sha2.h" |
| 35 #include "net/url_request/url_request_context.h" | 34 #include "net/url_request/url_request_context.h" |
| 36 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
| 37 #include "webkit/browser/blob/blob_url_request_job_factory.h" | 36 #include "webkit/browser/blob/blob_url_request_job_factory.h" |
| 38 #include "webkit/browser/fileapi/file_system_url_request_job_factory.h" | 37 #include "webkit/browser/fileapi/file_system_url_request_job_factory.h" |
| 39 #include "webkit/common/blob/blob_data.h" | 38 #include "webkit/common/blob/blob_data.h" |
| 40 | 39 |
| 41 using appcache::AppCacheService; | 40 using appcache::AppCacheService; |
| 42 using fileapi::FileSystemContext; | 41 using fileapi::FileSystemContext; |
| 43 using webkit_blob::BlobStorageController; | 42 using webkit_blob::BlobStorageController; |
| 44 | 43 |
| 45 namespace content { | 44 namespace content { |
| 46 | 45 |
| 47 namespace { | 46 namespace { |
| 48 | 47 |
| 49 class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { | 48 class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { |
| 50 public: | 49 public: |
| 51 BlobProtocolHandler(ChromeBlobStorageContext* blob_storage_context, | 50 BlobProtocolHandler(ChromeBlobStorageContext* blob_storage_context, |
| 52 StreamContext* stream_context, | |
| 53 fileapi::FileSystemContext* file_system_context) | 51 fileapi::FileSystemContext* file_system_context) |
| 54 : blob_storage_context_(blob_storage_context), | 52 : blob_storage_context_(blob_storage_context), |
| 55 stream_context_(stream_context), | |
| 56 file_system_context_(file_system_context) {} | 53 file_system_context_(file_system_context) {} |
| 57 | 54 |
| 58 virtual ~BlobProtocolHandler() {} | 55 virtual ~BlobProtocolHandler() {} |
| 59 | 56 |
| 60 virtual net::URLRequestJob* MaybeCreateJob( | 57 virtual net::URLRequestJob* MaybeCreateJob( |
| 61 net::URLRequest* request, | 58 net::URLRequest* request, |
| 62 net::NetworkDelegate* network_delegate) const OVERRIDE { | 59 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 64 if (!webkit_blob_protocol_handler_impl_) { | 61 if (!webkit_blob_protocol_handler_impl_) { |
| 65 webkit_blob_protocol_handler_impl_.reset( | 62 webkit_blob_protocol_handler_impl_.reset( |
| 66 new WebKitBlobProtocolHandlerImpl(blob_storage_context_->controller(), | 63 new WebKitBlobProtocolHandlerImpl( |
| 67 stream_context_.get(), | 64 blob_storage_context_->controller(), |
| 68 file_system_context_.get())); | 65 blob_storage_context_->stream_registry(), |
| 66 file_system_context_.get())); |
| 69 } | 67 } |
| 70 return webkit_blob_protocol_handler_impl_->MaybeCreateJob(request, | 68 return webkit_blob_protocol_handler_impl_->MaybeCreateJob(request, |
| 71 network_delegate); | 69 network_delegate); |
| 72 } | 70 } |
| 73 | 71 |
| 74 private: | 72 private: |
| 75 // An implementation of webkit_blob::BlobProtocolHandler that gets | 73 // An implementation of webkit_blob::BlobProtocolHandler that gets |
| 76 // the BlobData from ResourceRequestInfoImpl. | 74 // the BlobData from ResourceRequestInfoImpl. |
| 77 class WebKitBlobProtocolHandlerImpl | 75 class WebKitBlobProtocolHandlerImpl |
| 78 : public webkit_blob::BlobProtocolHandler { | 76 : public webkit_blob::BlobProtocolHandler { |
| 79 public: | 77 public: |
| 80 WebKitBlobProtocolHandlerImpl( | 78 WebKitBlobProtocolHandlerImpl( |
| 81 webkit_blob::BlobStorageController* blob_storage_controller, | 79 webkit_blob::BlobStorageController* blob_storage_controller, |
| 82 StreamContext* stream_context, | 80 StreamRegistry* stream_registry, |
| 83 fileapi::FileSystemContext* file_system_context) | 81 fileapi::FileSystemContext* file_system_context) |
| 84 : webkit_blob::BlobProtocolHandler( | 82 : webkit_blob::BlobProtocolHandler( |
| 85 blob_storage_controller, | 83 blob_storage_controller, |
| 86 file_system_context, | 84 file_system_context, |
| 87 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) | 85 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) |
| 88 .get()), | 86 .get()), |
| 89 stream_context_(stream_context) {} | 87 stream_registry_(stream_registry) { |
| 88 DCHECK(stream_registry); |
| 89 } |
| 90 | 90 |
| 91 virtual ~WebKitBlobProtocolHandlerImpl() {} | 91 virtual ~WebKitBlobProtocolHandlerImpl() {} |
| 92 | 92 |
| 93 virtual net::URLRequestJob* MaybeCreateJob( | 93 virtual net::URLRequestJob* MaybeCreateJob( |
| 94 net::URLRequest* request, | 94 net::URLRequest* request, |
| 95 net::NetworkDelegate* network_delegate) const OVERRIDE { | 95 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 96 scoped_refptr<Stream> stream = | 96 scoped_refptr<Stream> stream = |
| 97 stream_context_->registry()->GetStream(request->url()); | 97 stream_registry_->GetStream(request->url()); |
| 98 if (stream.get()) | 98 if (stream.get()) |
| 99 return new StreamURLRequestJob(request, network_delegate, stream); | 99 return new StreamURLRequestJob(request, network_delegate, stream); |
| 100 | 100 |
| 101 return webkit_blob::BlobProtocolHandler::MaybeCreateJob( | 101 return webkit_blob::BlobProtocolHandler::MaybeCreateJob( |
| 102 request, network_delegate); | 102 request, network_delegate); |
| 103 } | 103 } |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 // webkit_blob::BlobProtocolHandler implementation. | 106 // webkit_blob::BlobProtocolHandler implementation. |
| 107 virtual scoped_refptr<webkit_blob::BlobData> | 107 virtual scoped_refptr<webkit_blob::BlobData> |
| 108 LookupBlobData(net::URLRequest* request) const OVERRIDE { | 108 LookupBlobData(net::URLRequest* request) const OVERRIDE { |
| 109 const ResourceRequestInfoImpl* info = | 109 const ResourceRequestInfoImpl* info = |
| 110 ResourceRequestInfoImpl::ForRequest(request); | 110 ResourceRequestInfoImpl::ForRequest(request); |
| 111 if (!info) | 111 if (!info) |
| 112 return NULL; | 112 return NULL; |
| 113 return info->requested_blob_data(); | 113 return info->requested_blob_data(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 const scoped_refptr<StreamContext> stream_context_; | 116 StreamRegistry* const stream_registry_; |
| 117 |
| 117 DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); | 118 DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); |
| 118 }; | 119 }; |
| 119 | 120 |
| 120 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 121 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 121 const scoped_refptr<StreamContext> stream_context_; | |
| 122 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 122 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 123 | 123 |
| 124 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> | 124 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> |
| 125 webkit_blob_protocol_handler_impl_; | 125 webkit_blob_protocol_handler_impl_; |
| 126 | 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); | 127 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 // These constants are used to create the directory structure under the profile | 130 // These constants are used to create the directory structure under the profile |
| 131 // where renderers with a non-default storage partition keep their persistent | 131 // where renderers with a non-default storage partition keep their persistent |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 base::FilePath partition_path = | 404 base::FilePath partition_path = |
| 405 browser_context_->GetPath().Append( | 405 browser_context_->GetPath().Append( |
| 406 GetStoragePartitionPath(partition_domain, partition_name)); | 406 GetStoragePartitionPath(partition_domain, partition_name)); |
| 407 StoragePartitionImpl* partition = | 407 StoragePartitionImpl* partition = |
| 408 StoragePartitionImpl::Create(browser_context_, in_memory, | 408 StoragePartitionImpl::Create(browser_context_, in_memory, |
| 409 partition_path); | 409 partition_path); |
| 410 partitions_[partition_config] = partition; | 410 partitions_[partition_config] = partition; |
| 411 | 411 |
| 412 ChromeBlobStorageContext* blob_storage_context = | 412 ChromeBlobStorageContext* blob_storage_context = |
| 413 ChromeBlobStorageContext::GetFor(browser_context_); | 413 ChromeBlobStorageContext::GetFor(browser_context_); |
| 414 StreamContext* stream_context = StreamContext::GetFor(browser_context_); | |
| 415 ProtocolHandlerMap protocol_handlers; | 414 ProtocolHandlerMap protocol_handlers; |
| 416 protocol_handlers[chrome::kBlobScheme] = | 415 protocol_handlers[chrome::kBlobScheme] = |
| 417 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 416 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 418 new BlobProtocolHandler(blob_storage_context, | 417 new BlobProtocolHandler(blob_storage_context, |
| 419 stream_context, | |
| 420 partition->GetFileSystemContext())); | 418 partition->GetFileSystemContext())); |
| 421 protocol_handlers[chrome::kFileSystemScheme] = | 419 protocol_handlers[chrome::kFileSystemScheme] = |
| 422 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 420 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 423 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); | 421 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); |
| 424 protocol_handlers[chrome::kChromeUIScheme] = | 422 protocol_handlers[chrome::kChromeUIScheme] = |
| 425 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 423 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| 426 URLDataManagerBackend::CreateProtocolHandler( | 424 URLDataManagerBackend::CreateProtocolHandler( |
| 427 browser_context_->GetResourceContext(), | 425 browser_context_->GetResourceContext(), |
| 428 browser_context_->IsOffTheRecord(), | 426 browser_context_->IsOffTheRecord(), |
| 429 partition->GetAppCacheService(), | 427 partition->GetAppCacheService(), |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 578 |
| 581 // We do not call InitializeURLRequestContext() for media contexts because, | 579 // We do not call InitializeURLRequestContext() for media contexts because, |
| 582 // other than the HTTP cache, the media contexts share the same backing | 580 // other than the HTTP cache, the media contexts share the same backing |
| 583 // objects as their associated "normal" request context. Thus, the previous | 581 // objects as their associated "normal" request context. Thus, the previous |
| 584 // call serves to initialize the media request context for this storage | 582 // call serves to initialize the media request context for this storage |
| 585 // partition as well. | 583 // partition as well. |
| 586 } | 584 } |
| 587 } | 585 } |
| 588 | 586 |
| 589 } // namespace content | 587 } // namespace content |
| OLD | NEW |