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" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 #include "webkit/fileapi/file_system_url_request_job_factory.h" | 38 #include "webkit/fileapi/file_system_url_request_job_factory.h" |
| 39 | 39 |
| 40 using appcache::AppCacheService; | 40 using appcache::AppCacheService; |
| 41 using fileapi::FileSystemContext; | 41 using fileapi::FileSystemContext; |
| 42 using webkit_blob::BlobStorageController; | 42 using webkit_blob::BlobStorageController; |
| 43 | 43 |
| 44 namespace content { | 44 namespace content { |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler { | 48 class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { |
| 49 public: | 49 public: |
| 50 BlobProtocolHandler( | 50 static BlobProtocolHandler* Create( |
| 51 webkit_blob::BlobStorageController* blob_storage_controller, | 51 ChromeBlobStorageContext* blob_storage_context, |
| 52 fileapi::FileSystemContext* file_system_context, | 52 fileapi::FileSystemContext* file_system_context) { |
| 53 base::MessageLoopProxy* loop_proxy) | 53 BlobProtocolHandler* blob_protocol_handler = new BlobProtocolHandler(); |
| 54 : webkit_blob::BlobProtocolHandler(blob_storage_controller, | 54 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 55 file_system_context, | 55 &BlobProtocolHandler::IOThreadDelegate::Init, |
| 56 loop_proxy) {} | 56 base::Unretained(blob_protocol_handler->io_thread_delegate_.get()), |
| 57 make_scoped_refptr(blob_storage_context), | |
| 58 make_scoped_refptr(file_system_context))); | |
| 59 return blob_protocol_handler; | |
| 60 } | |
| 57 | 61 |
| 58 virtual ~BlobProtocolHandler() {} | 62 virtual ~BlobProtocolHandler() { |
| 63 BrowserThread::DeleteSoon(BrowserThread::IO, | |
| 64 FROM_HERE, | |
| 65 io_thread_delegate_.release()); | |
| 66 } | |
| 67 | |
| 68 virtual net::URLRequestJob* MaybeCreateJob( | |
| 69 net::URLRequest* request, | |
| 70 net::NetworkDelegate* network_delegate) const OVERRIDE { | |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 72 return io_thread_delegate_->webkit_blob_protocol_handler_impl_-> | |
| 73 MaybeCreateJob(request, network_delegate); | |
| 74 } | |
| 59 | 75 |
| 60 private: | 76 private: |
| 61 virtual scoped_refptr<webkit_blob::BlobData> | 77 // |IOThreadDelegate| is needed because |BlobProtocolHandler| is constructed |
| 62 LookupBlobData(net::URLRequest* request) const { | 78 // on the UI thread while ChromeBlobStorageContext::controller() must be |
| 63 const ResourceRequestInfoImpl* info = | 79 // called on the IO thread and must be called prior to instantiating |
| 64 ResourceRequestInfoImpl::ForRequest(request); | 80 // |webkit_blob_protocol_handler_impl_|. |
| 65 if (!info) | 81 class IOThreadDelegate { |
|
awong
2012/12/13 01:06:15
Names are much nicer. Thanks!
| |
| 66 return NULL; | 82 public: |
| 67 return info->requested_blob_data(); | 83 IOThreadDelegate() {} |
| 68 } | 84 virtual ~IOThreadDelegate() {} |
|
awong
2012/12/13 01:06:15
Why does this need to be virtual?
pauljensen
2012/12/13 17:58:44
I see style says it doesn't need to be virtual if
| |
| 85 | |
| 86 void Init(ChromeBlobStorageContext* blob_storage_context, | |
| 87 fileapi::FileSystemContext* file_system_context) { | |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 89 webkit_blob_protocol_handler_impl_.reset( | |
| 90 new WebKitBlobProtocolHandlerImpl(blob_storage_context->controller(), | |
| 91 file_system_context)); | |
| 92 } | |
| 93 | |
| 94 // An implementation of webkit_blob::BlobProtocolHandler that gets | |
| 95 // the BlobData from ResourceRequestInfoImpl. | |
| 96 class WebKitBlobProtocolHandlerImpl | |
| 97 : public webkit_blob::BlobProtocolHandler { | |
| 98 public: | |
| 99 WebKitBlobProtocolHandlerImpl( | |
| 100 webkit_blob::BlobStorageController* blob_storage_controller, | |
| 101 fileapi::FileSystemContext* file_system_context) | |
| 102 : webkit_blob::BlobProtocolHandler( | |
| 103 blob_storage_controller, file_system_context, | |
| 104 BrowserThread::GetMessageLoopProxyForThread( | |
| 105 BrowserThread::FILE)) {} | |
| 106 | |
| 107 virtual ~WebKitBlobProtocolHandlerImpl() {} | |
| 108 | |
| 109 private: | |
| 110 // webkit_blob::BlobProtocolHandler implementation | |
|
awong
2012/12/13 01:06:15
End comment with a period please.
pauljensen
2012/12/13 17:58:44
Done.
| |
| 111 virtual scoped_refptr<webkit_blob::BlobData> | |
| 112 LookupBlobData(net::URLRequest* request) const OVERRIDE { | |
| 113 const ResourceRequestInfoImpl* info = | |
| 114 ResourceRequestInfoImpl::ForRequest(request); | |
| 115 if (!info) | |
| 116 return NULL; | |
| 117 return info->requested_blob_data(); | |
| 118 } | |
| 119 | |
| 120 DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); | |
| 121 }; | |
| 122 | |
| 123 scoped_ptr<WebKitBlobProtocolHandlerImpl> | |
| 124 webkit_blob_protocol_handler_impl_; | |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(IOThreadDelegate); | |
| 127 }; | |
| 128 | |
| 129 BlobProtocolHandler() : io_thread_delegate_(new IOThreadDelegate()) {} | |
| 130 | |
| 131 scoped_ptr<IOThreadDelegate> io_thread_delegate_; | |
|
awong
2012/12/13 01:06:15
I wouldn't use a scoped_ptr<> here because we don'
pauljensen
2012/12/13 17:58:44
Done.
| |
| 69 | 132 |
| 70 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); | 133 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); |
| 71 }; | 134 }; |
| 72 | 135 |
| 73 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol | 136 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol |
| 74 // handler because we want to reuse the chrome://scheme (everyone is familiar | 137 // handler because we want to reuse the chrome://scheme (everyone is familiar |
| 75 // with it, and no need to expose the content/chrome separation through our UI). | 138 // with it, and no need to expose the content/chrome separation through our UI). |
| 76 class DeveloperProtocolHandler | 139 class DeveloperProtocolHandler |
| 77 : public net::URLRequestJobFactory::Interceptor { | 140 : public net::URLRequestJobFactory::Interceptor { |
| 78 public: | 141 public: |
| 79 DeveloperProtocolHandler( | 142 DeveloperProtocolHandler( |
| 80 AppCacheService* appcache_service, | 143 AppCacheService* appcache_service, |
| 81 BlobStorageController* blob_storage_controller) | 144 ChromeBlobStorageContext* blob_storage_context) |
|
awong
2012/12/13 01:06:15
Why did we change this to take the context rather
pauljensen
2012/12/13 17:58:44
I changed this to take a context because this is n
| |
| 82 : appcache_service_(appcache_service), | 145 : appcache_service_(appcache_service), |
| 83 blob_storage_controller_(blob_storage_controller) {} | 146 blob_storage_context_(blob_storage_context) {} |
| 84 virtual ~DeveloperProtocolHandler() {} | 147 virtual ~DeveloperProtocolHandler() {} |
| 85 | 148 |
| 86 virtual net::URLRequestJob* MaybeIntercept( | 149 virtual net::URLRequestJob* MaybeIntercept( |
| 87 net::URLRequest* request, | 150 net::URLRequest* request, |
| 88 net::NetworkDelegate* network_delegate) const OVERRIDE { | 151 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 89 // Check for chrome://view-http-cache/*, which uses its own job type. | 152 // Check for chrome://view-http-cache/*, which uses its own job type. |
| 90 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | 153 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) |
| 91 return ViewHttpCacheJobFactory::CreateJobForRequest(request, | 154 return ViewHttpCacheJobFactory::CreateJobForRequest(request, |
| 92 network_delegate); | 155 network_delegate); |
| 93 | 156 |
| 94 // Next check for chrome://appcache-internals/, which uses its own job type. | 157 // Next check for chrome://appcache-internals/, which uses its own job type. |
| 95 if (request->url().SchemeIs(chrome::kChromeUIScheme) && | 158 if (request->url().SchemeIs(chrome::kChromeUIScheme) && |
| 96 request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { | 159 request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { |
| 97 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( | 160 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( |
| 98 request, network_delegate, appcache_service_); | 161 request, network_delegate, appcache_service_); |
| 99 } | 162 } |
| 100 | 163 |
| 101 // Next check for chrome://blob-internals/, which uses its own job type. | 164 // Next check for chrome://blob-internals/, which uses its own job type. |
| 102 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { | 165 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { |
| 103 return ViewBlobInternalsJobFactory::CreateJobForRequest( | 166 return ViewBlobInternalsJobFactory::CreateJobForRequest( |
| 104 request, network_delegate, blob_storage_controller_); | 167 request, network_delegate, blob_storage_context_->controller()); |
| 105 } | 168 } |
| 106 | 169 |
| 107 #if defined(USE_TCMALLOC) | 170 #if defined(USE_TCMALLOC) |
| 108 // Next check for chrome://tcmalloc/, which uses its own job type. | 171 // Next check for chrome://tcmalloc/, which uses its own job type. |
| 109 if (request->url().SchemeIs(chrome::kChromeUIScheme) && | 172 if (request->url().SchemeIs(chrome::kChromeUIScheme) && |
| 110 request->url().host() == chrome::kChromeUITcmallocHost) { | 173 request->url().host() == chrome::kChromeUITcmallocHost) { |
| 111 return new TcmallocInternalsRequestJob(request, network_delegate); | 174 return new TcmallocInternalsRequestJob(request, network_delegate); |
| 112 } | 175 } |
| 113 #endif | 176 #endif |
| 114 | 177 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 133 net::NetworkDelegate* network_delegate) const OVERRIDE { | 196 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 134 return NULL; | 197 return NULL; |
| 135 } | 198 } |
| 136 | 199 |
| 137 virtual bool WillHandleProtocol(const std::string& protocol) const { | 200 virtual bool WillHandleProtocol(const std::string& protocol) const { |
| 138 return protocol == chrome::kChromeUIScheme; | 201 return protocol == chrome::kChromeUIScheme; |
| 139 } | 202 } |
| 140 | 203 |
| 141 private: | 204 private: |
| 142 AppCacheService* appcache_service_; | 205 AppCacheService* appcache_service_; |
| 143 BlobStorageController* blob_storage_controller_; | 206 ChromeBlobStorageContext* blob_storage_context_; |
| 144 }; | 207 }; |
| 145 | 208 |
| 146 void InitializeURLRequestContext( | |
| 147 net::URLRequestContextGetter* context_getter, | |
| 148 AppCacheService* appcache_service, | |
| 149 FileSystemContext* file_system_context, | |
| 150 ChromeBlobStorageContext* blob_storage_context) { | |
| 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 152 if (!context_getter) | |
| 153 return; // tests. | |
| 154 | |
| 155 // This code only modifies the URLRequestJobFactory on the context | |
| 156 // to handle blob: URLs, filesystem: URLs, and to let AppCache intercept | |
| 157 // the appropriate requests. This is in addition to the slew of other | |
| 158 // initializtion that is done in during creation of the URLRequestContext. | |
| 159 // We cannot yet centralize this code because URLRequestContext needs | |
| 160 // to be created before the StoragePartition context. | |
| 161 // | |
| 162 // TODO(ajwong): Fix the ordering so all the initialization is in one spot. | |
| 163 net::URLRequestContext* context = context_getter->GetURLRequestContext(); | |
| 164 net::URLRequestJobFactory* job_factory = | |
| 165 const_cast<net::URLRequestJobFactory*>(context->job_factory()); | |
| 166 | |
| 167 // Note: if this is called twice with 2 request contexts that share one job | |
| 168 // factory (as is the case with a media request context and its related | |
| 169 // normal request context) then this will early exit. | |
| 170 if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) | |
| 171 return; // Already initialized this JobFactory. | |
| 172 | |
| 173 bool set_protocol = job_factory->SetProtocolHandler( | |
| 174 chrome::kBlobScheme, | |
| 175 new BlobProtocolHandler( | |
| 176 blob_storage_context->controller(), | |
| 177 file_system_context, | |
| 178 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
| 179 DCHECK(set_protocol); | |
| 180 set_protocol = job_factory->SetProtocolHandler( | |
| 181 chrome::kFileSystemScheme, | |
| 182 CreateFileSystemProtocolHandler(file_system_context)); | |
| 183 DCHECK(set_protocol); | |
| 184 | |
| 185 job_factory->AddInterceptor( | |
| 186 new DeveloperProtocolHandler(appcache_service, | |
| 187 blob_storage_context->controller())); | |
| 188 | |
| 189 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! | |
| 190 } | |
| 191 | |
| 192 // These constants are used to create the directory structure under the profile | 209 // These constants are used to create the directory structure under the profile |
| 193 // where renderers with a non-default storage partition keep their persistent | 210 // where renderers with a non-default storage partition keep their persistent |
| 194 // state. This will contain a set of directories that partially mirror the | 211 // state. This will contain a set of directories that partially mirror the |
| 195 // directory structure of BrowserContext::GetPath(). | 212 // directory structure of BrowserContext::GetPath(). |
| 196 // | 213 // |
| 197 // The kStoragePartitionDirname contains an extensions directory which is | 214 // The kStoragePartitionDirname contains an extensions directory which is |
| 198 // further partitioned by extension id, followed by another level of directories | 215 // further partitioned by extension id, followed by another level of directories |
| 199 // for the "default" extension storage partition and one directory for each | 216 // for the "default" extension storage partition and one directory for each |
| 200 // persistent partition used by a webview tag. Example: | 217 // persistent partition used by a webview tag. Example: |
| 201 // | 218 // |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 return it->second; | 473 return it->second; |
| 457 | 474 |
| 458 FilePath partition_path = | 475 FilePath partition_path = |
| 459 browser_context_->GetPath().Append( | 476 browser_context_->GetPath().Append( |
| 460 GetStoragePartitionPath(partition_domain, partition_name)); | 477 GetStoragePartitionPath(partition_domain, partition_name)); |
| 461 StoragePartitionImpl* partition = | 478 StoragePartitionImpl* partition = |
| 462 StoragePartitionImpl::Create(browser_context_, in_memory, | 479 StoragePartitionImpl::Create(browser_context_, in_memory, |
| 463 partition_path); | 480 partition_path); |
| 464 partitions_[partition_config] = partition; | 481 partitions_[partition_config] = partition; |
| 465 | 482 |
| 483 ChromeBlobStorageContext* blob_storage_context = | |
| 484 ChromeBlobStorageContext::GetFor(browser_context_); | |
| 485 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( | |
| 486 BlobProtocolHandler::Create(blob_storage_context, | |
| 487 partition->GetFileSystemContext())); | |
| 488 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
| 489 file_system_protocol_handler( | |
| 490 CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); | |
| 491 scoped_ptr<net::URLRequestJobFactory::Interceptor> developer_protocol_handler( | |
| 492 new DeveloperProtocolHandler(partition->GetAppCacheService(), | |
| 493 blob_storage_context)); | |
| 494 | |
| 466 // These calls must happen after StoragePartitionImpl::Create(). | 495 // These calls must happen after StoragePartitionImpl::Create(). |
| 467 partition->SetURLRequestContext( | 496 partition->SetURLRequestContext( |
| 468 partition_domain.empty() ? | 497 partition_domain.empty() ? |
| 469 browser_context_->GetRequestContext() : | 498 browser_context_->CreateRequestContext( |
| 470 browser_context_->GetRequestContextForStoragePartition( | 499 blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), |
| 471 partition->GetPath(), in_memory)); | 500 developer_protocol_handler.Pass()) : |
| 501 browser_context_->CreateRequestContextForStoragePartition( | |
| 502 partition->GetPath(), in_memory, blob_protocol_handler.Pass(), | |
| 503 file_system_protocol_handler.Pass(), | |
| 504 developer_protocol_handler.Pass())); | |
| 472 partition->SetMediaURLRequestContext( | 505 partition->SetMediaURLRequestContext( |
| 473 partition_domain.empty() ? | 506 partition_domain.empty() ? |
| 474 browser_context_->GetMediaRequestContext() : | 507 browser_context_->GetMediaRequestContext() : |
| 475 browser_context_->GetMediaRequestContextForStoragePartition( | 508 browser_context_->GetMediaRequestContextForStoragePartition( |
| 476 partition->GetPath(), in_memory)); | 509 partition->GetPath(), in_memory)); |
| 477 | 510 |
| 478 PostCreateInitialization(partition, in_memory); | 511 PostCreateInitialization(partition, in_memory); |
| 479 | 512 |
| 480 return partition; | 513 return partition; |
| 481 } | 514 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 BrowserThread::IO, FROM_HERE, | 616 BrowserThread::IO, FROM_HERE, |
| 584 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 617 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
| 585 partition->GetAppCacheService(), | 618 partition->GetAppCacheService(), |
| 586 in_memory ? FilePath() : | 619 in_memory ? FilePath() : |
| 587 partition->GetPath().Append(kAppCacheDirname), | 620 partition->GetPath().Append(kAppCacheDirname), |
| 588 browser_context_->GetResourceContext(), | 621 browser_context_->GetResourceContext(), |
| 589 make_scoped_refptr(partition->GetURLRequestContext()), | 622 make_scoped_refptr(partition->GetURLRequestContext()), |
| 590 make_scoped_refptr( | 623 make_scoped_refptr( |
| 591 browser_context_->GetSpecialStoragePolicy()))); | 624 browser_context_->GetSpecialStoragePolicy()))); |
| 592 | 625 |
| 593 // Add content's URLRequestContext's hooks. | |
| 594 BrowserThread::PostTask( | |
| 595 BrowserThread::IO, FROM_HERE, | |
| 596 base::Bind( | |
| 597 &InitializeURLRequestContext, | |
| 598 make_scoped_refptr(partition->GetURLRequestContext()), | |
| 599 make_scoped_refptr(partition->GetAppCacheService()), | |
| 600 make_scoped_refptr(partition->GetFileSystemContext()), | |
| 601 make_scoped_refptr( | |
| 602 ChromeBlobStorageContext::GetFor(browser_context_)))); | |
| 603 | |
| 604 // We do not call InitializeURLRequestContext() for media contexts because, | 626 // We do not call InitializeURLRequestContext() for media contexts because, |
| 605 // other than the HTTP cache, the media contexts share the same backing | 627 // other than the HTTP cache, the media contexts share the same backing |
| 606 // objects as their associated "normal" request context. Thus, the previous | 628 // objects as their associated "normal" request context. Thus, the previous |
| 607 // call serves to initialize the media request context for this storage | 629 // call serves to initialize the media request context for this storage |
| 608 // partition as well. | 630 // partition as well. |
| 609 } | 631 } |
| 610 } | 632 } |
| 611 | 633 |
| 612 } // namespace content | 634 } // namespace content |
| OLD | NEW |