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/stream_context.h" |
| 26 #include "content/browser/streams/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 StreamContext* 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 StreamContext* 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<Stream> stream = |
| 99 stream_context_->registry()->GetStream(request->url()); |
| 100 if (stream) |
| 101 return new StreamURLRequestJob(request, network_delegate, stream); |
| 102 |
| 103 return webkit_blob::BlobProtocolHandler::MaybeCreateJob( |
| 104 request, network_delegate); |
| 105 } |
| 106 |
87 private: | 107 private: |
88 // webkit_blob::BlobProtocolHandler implementation. | 108 // webkit_blob::BlobProtocolHandler implementation. |
89 virtual scoped_refptr<webkit_blob::BlobData> | 109 virtual scoped_refptr<webkit_blob::BlobData> |
90 LookupBlobData(net::URLRequest* request) const OVERRIDE { | 110 LookupBlobData(net::URLRequest* request) const OVERRIDE { |
91 const ResourceRequestInfoImpl* info = | 111 const ResourceRequestInfoImpl* info = |
92 ResourceRequestInfoImpl::ForRequest(request); | 112 ResourceRequestInfoImpl::ForRequest(request); |
93 if (!info) | 113 if (!info) |
94 return NULL; | 114 return NULL; |
95 return info->requested_blob_data(); | 115 return info->requested_blob_data(); |
96 } | 116 } |
97 | 117 |
| 118 const scoped_refptr<StreamContext> stream_context_; |
98 DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); | 119 DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); |
99 }; | 120 }; |
100 | 121 |
101 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 122 const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 123 const scoped_refptr<StreamContext> stream_context_; |
102 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 124 const scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
103 | 125 |
104 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> | 126 mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> |
105 webkit_blob_protocol_handler_impl_; | 127 webkit_blob_protocol_handler_impl_; |
106 | 128 |
107 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); | 129 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); |
108 }; | 130 }; |
109 | 131 |
110 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol | 132 // 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 | 133 // 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 = | 462 base::FilePath partition_path = |
441 browser_context_->GetPath().Append( | 463 browser_context_->GetPath().Append( |
442 GetStoragePartitionPath(partition_domain, partition_name)); | 464 GetStoragePartitionPath(partition_domain, partition_name)); |
443 StoragePartitionImpl* partition = | 465 StoragePartitionImpl* partition = |
444 StoragePartitionImpl::Create(browser_context_, in_memory, | 466 StoragePartitionImpl::Create(browser_context_, in_memory, |
445 partition_path); | 467 partition_path); |
446 partitions_[partition_config] = partition; | 468 partitions_[partition_config] = partition; |
447 | 469 |
448 ChromeBlobStorageContext* blob_storage_context = | 470 ChromeBlobStorageContext* blob_storage_context = |
449 ChromeBlobStorageContext::GetFor(browser_context_); | 471 ChromeBlobStorageContext::GetFor(browser_context_); |
| 472 StreamContext* stream_context = StreamContext::GetFor(browser_context_); |
450 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( | 473 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( |
451 new BlobProtocolHandler(blob_storage_context, | 474 new BlobProtocolHandler( |
452 partition->GetFileSystemContext())); | 475 blob_storage_context, |
| 476 stream_context, |
| 477 partition->GetFileSystemContext())); |
453 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 478 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
454 file_system_protocol_handler( | 479 file_system_protocol_handler( |
455 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); | 480 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); |
456 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 481 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
457 developer_protocol_handler( | 482 developer_protocol_handler( |
458 new DeveloperProtocolHandler(partition->GetAppCacheService(), | 483 new DeveloperProtocolHandler(partition->GetAppCacheService(), |
459 blob_storage_context)); | 484 blob_storage_context)); |
460 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 485 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
461 chrome_protocol_handler( | 486 chrome_protocol_handler( |
462 URLDataManagerBackend::CreateProtocolHandler( | 487 URLDataManagerBackend::CreateProtocolHandler( |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 627 |
603 // We do not call InitializeURLRequestContext() for media contexts because, | 628 // We do not call InitializeURLRequestContext() for media contexts because, |
604 // other than the HTTP cache, the media contexts share the same backing | 629 // other than the HTTP cache, the media contexts share the same backing |
605 // objects as their associated "normal" request context. Thus, the previous | 630 // objects as their associated "normal" request context. Thus, the previous |
606 // call serves to initialize the media request context for this storage | 631 // call serves to initialize the media request context for this storage |
607 // partition as well. | 632 // partition as well. |
608 } | 633 } |
609 } | 634 } |
610 | 635 |
611 } // namespace content | 636 } // namespace content |
OLD | NEW |