| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "content/browser/webui/url_data_manager_backend.h" | 27 #include "content/browser/webui/url_data_manager_backend.h" |
| 28 #include "content/public/browser/browser_context.h" | 28 #include "content/public/browser/browser_context.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/storage_partition.h" | 31 #include "content/public/browser/storage_partition.h" |
| 32 #include "content/public/common/content_constants.h" | 32 #include "content/public/common/content_constants.h" |
| 33 #include "content/public/common/url_constants.h" | 33 #include "content/public/common/url_constants.h" |
| 34 #include "crypto/sha2.h" | 34 #include "crypto/sha2.h" |
| 35 #include "net/url_request/url_request_context.h" | 35 #include "net/url_request/url_request_context.h" |
| 36 #include "net/url_request/url_request_context_getter.h" | 36 #include "net/url_request/url_request_context_getter.h" |
| 37 #include "webkit/browser/blob/blob_storage_context.h" |
| 37 #include "webkit/browser/blob/blob_url_request_job_factory.h" | 38 #include "webkit/browser/blob/blob_url_request_job_factory.h" |
| 38 #include "webkit/browser/fileapi/file_system_url_request_job_factory.h" | 39 #include "webkit/browser/fileapi/file_system_url_request_job_factory.h" |
| 39 #include "webkit/common/blob/blob_data.h" | 40 #include "webkit/common/blob/blob_data.h" |
| 40 | 41 |
| 41 using appcache::AppCacheService; | 42 using appcache::AppCacheService; |
| 42 using fileapi::FileSystemContext; | 43 using fileapi::FileSystemContext; |
| 43 using webkit_blob::BlobStorageController; | 44 using webkit_blob::BlobStorageContext; |
| 44 | 45 |
| 45 namespace content { | 46 namespace content { |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 | 49 |
| 49 class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { | 50 // A derivative that knows about Streams too. |
| 51 class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler { |
| 50 public: | 52 public: |
| 51 BlobProtocolHandler(ChromeBlobStorageContext* blob_storage_context, | 53 BlobProtocolHandler(ChromeBlobStorageContext* blob_storage_context, |
| 52 StreamContext* stream_context, | 54 StreamContext* stream_context, |
| 53 fileapi::FileSystemContext* file_system_context) | 55 fileapi::FileSystemContext* file_system_context) |
| 54 : blob_storage_context_(blob_storage_context), | 56 : webkit_blob::BlobProtocolHandler( |
| 57 file_system_context, |
| 58 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) |
| 59 .get()), |
| 60 blob_storage_context_(blob_storage_context), |
| 55 stream_context_(stream_context), | 61 stream_context_(stream_context), |
| 56 file_system_context_(file_system_context) {} | 62 file_system_context_(file_system_context) { |
| 63 } |
| 57 | 64 |
| 58 virtual ~BlobProtocolHandler() {} | 65 virtual ~BlobProtocolHandler() { |
| 66 } |
| 59 | 67 |
| 60 virtual net::URLRequestJob* MaybeCreateJob( | 68 virtual net::URLRequestJob* MaybeCreateJob( |
| 61 net::URLRequest* request, | 69 net::URLRequest* request, |
| 62 net::NetworkDelegate* network_delegate) const OVERRIDE { | 70 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 71 scoped_refptr<Stream> stream = |
| 64 if (!webkit_blob_protocol_handler_impl_) { | 72 stream_context_->registry()->GetStream(request->url()); |
| 65 webkit_blob_protocol_handler_impl_.reset( | 73 if (stream.get()) |
| 66 new WebKitBlobProtocolHandlerImpl(blob_storage_context_->controller(), | 74 return new StreamURLRequestJob(request, network_delegate, stream); |
| 67 stream_context_.get(), | 75 return webkit_blob::BlobProtocolHandler::MaybeCreateJob( |
| 68 file_system_context_.get())); | 76 request, network_delegate); |
| 69 } | |
| 70 return webkit_blob_protocol_handler_impl_->MaybeCreateJob(request, | |
| 71 network_delegate); | |
| 72 } | 77 } |
| 73 | 78 |
| 74 private: | 79 private: |
| 75 // An implementation of webkit_blob::BlobProtocolHandler that gets | |
| 76 // the BlobData from ResourceRequestInfoImpl. | |
| 77 class WebKitBlobProtocolHandlerImpl | |
| 78 : public webkit_blob::BlobProtocolHandler { | |
| 79 public: | |
| 80 WebKitBlobProtocolHandlerImpl( | |
| 81 webkit_blob::BlobStorageController* blob_storage_controller, | |
| 82 StreamContext* stream_context, | |
| 83 fileapi::FileSystemContext* file_system_context) | |
| 84 : webkit_blob::BlobProtocolHandler( | |
| 85 blob_storage_controller, | |
| 86 file_system_context, | |
| 87 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) | |
| 88 .get()), | |
| 89 stream_context_(stream_context) {} | |
| 90 | |
| 91 virtual ~WebKitBlobProtocolHandlerImpl() {} | |
| 92 | |
| 93 virtual net::URLRequestJob* MaybeCreateJob( | |
| 94 net::URLRequest* request, | |
| 95 net::NetworkDelegate* network_delegate) const OVERRIDE { | |
| 96 scoped_refptr<Stream> stream = | |
| 97 stream_context_->registry()->GetStream(request->url()); | |
| 98 if (stream.get()) | |
| 99 return new StreamURLRequestJob(request, network_delegate, stream); | |
| 100 | |
| 101 return webkit_blob::BlobProtocolHandler::MaybeCreateJob( | |
| 102 request, network_delegate); | |
| 103 } | |
| 104 | |
| 105 private: | |
| 106 // webkit_blob::BlobProtocolHandler implementation. | |
| 107 virtual scoped_refptr<webkit_blob::BlobData> | |
| 108 LookupBlobData(net::URLRequest* request) const OVERRIDE { | |
| 109 const ResourceRequestInfoImpl* info = | |
| 110 ResourceRequestInfoImpl::ForRequest(request); | |
| 111 if (!info) | |
| 112 return NULL; | |
| 113 return info->requested_blob_data(); | |
| 114 } | |
| 115 | |
| 116 const scoped_refptr<StreamContext> stream_context_; | |
| 117 DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); | |
| 118 }; | |
| 119 | |
| 120 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 80 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 121 const scoped_refptr<StreamContext> stream_context_; | 81 const scoped_refptr<StreamContext> stream_context_; |
| 122 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 82 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 123 | |
| 124 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> | |
| 125 webkit_blob_protocol_handler_impl_; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); | 83 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); |
| 128 }; | 84 }; |
| 129 | 85 |
| 130 // These constants are used to create the directory structure under the profile | 86 // These constants are used to create the directory structure under the profile |
| 131 // where renderers with a non-default storage partition keep their persistent | 87 // where renderers with a non-default storage partition keep their persistent |
| 132 // state. This will contain a set of directories that partially mirror the | 88 // state. This will contain a set of directories that partially mirror the |
| 133 // directory structure of BrowserContext::GetPath(). | 89 // directory structure of BrowserContext::GetPath(). |
| 134 // | 90 // |
| 135 // The kStoragePartitionDirname contains an extensions directory which is | 91 // The kStoragePartitionDirname contains an extensions directory which is |
| 136 // further partitioned by extension id, followed by another level of directories | 92 // further partitioned by extension id, followed by another level of directories |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 | 539 |
| 584 // We do not call InitializeURLRequestContext() for media contexts because, | 540 // We do not call InitializeURLRequestContext() for media contexts because, |
| 585 // other than the HTTP cache, the media contexts share the same backing | 541 // other than the HTTP cache, the media contexts share the same backing |
| 586 // objects as their associated "normal" request context. Thus, the previous | 542 // objects as their associated "normal" request context. Thus, the previous |
| 587 // call serves to initialize the media request context for this storage | 543 // call serves to initialize the media request context for this storage |
| 588 // partition as well. | 544 // partition as well. |
| 589 } | 545 } |
| 590 } | 546 } |
| 591 | 547 |
| 592 } // namespace content | 548 } // namespace content |
| OLD | NEW |