Index: content/browser/storage_partition_impl_map.cc |
diff --git a/content/browser/storage_partition_impl_map.cc b/content/browser/storage_partition_impl_map.cc |
index 06f3dc432c7b73310544acca214c5fa1f66d2c58..9fe0779e58c50ca3fcb0cffb91b17796c1eb12e4 100644 |
--- a/content/browser/storage_partition_impl_map.cc |
+++ b/content/browser/storage_partition_impl_map.cc |
@@ -44,28 +44,85 @@ namespace content { |
namespace { |
-class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler { |
+class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { |
public: |
- BlobProtocolHandler( |
- webkit_blob::BlobStorageController* blob_storage_controller, |
- fileapi::FileSystemContext* file_system_context, |
- base::MessageLoopProxy* loop_proxy) |
- : webkit_blob::BlobProtocolHandler(blob_storage_controller, |
- file_system_context, |
- loop_proxy) {} |
+ BlobProtocolHandler(ChromeBlobStorageContext* blob_storage_context, |
+ fileapi::FileSystemContext* file_system_context) |
+ : delegate_(new Delegate()) { |
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
+ &BlobProtocolHandler::Delegate::Init, |
+ base::Unretained(delegate_.get()), |
+ make_scoped_refptr(blob_storage_context), |
+ make_scoped_refptr(file_system_context))); |
+ } |
- virtual ~BlobProtocolHandler() {} |
+ virtual ~BlobProtocolHandler() { |
+ BrowserThread::DeleteSoon(BrowserThread::IO, |
+ FROM_HERE, |
+ delegate_.release()); |
+ } |
- private: |
- virtual scoped_refptr<webkit_blob::BlobData> |
- LookupBlobData(net::URLRequest* request) const { |
- const ResourceRequestInfoImpl* info = |
- ResourceRequestInfoImpl::ForRequest(request); |
- if (!info) |
- return NULL; |
- return info->requested_blob_data(); |
+ virtual net::URLRequestJob* MaybeCreateJob( |
+ net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate) const OVERRIDE { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ return delegate_->core_->MaybeCreateJob(request, network_delegate); |
} |
+ private: |
+ // Constructed on any thread and then lives on IO thread. |
+ class Delegate { |
+ public: |
+ Delegate() {} |
+ virtual ~Delegate() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ } |
+ |
+ void Init(ChromeBlobStorageContext* blob_storage_context, |
+ fileapi::FileSystemContext* file_system_context) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ core_.reset(new Core(blob_storage_context->controller(), |
+ file_system_context)); |
+ } |
+ |
+ // |Core| is needed because |BlobProtocolHandler| is constructed on UI |
+ // thread while ChromeBlobStorageContext::controller() must be called on |
+ // IO thread and must be called prior to webkit_blob::BlobProtocolHandler(). |
+ class Core : public webkit_blob::BlobProtocolHandler { |
+ public: |
+ Core(webkit_blob::BlobStorageController* blob_storage_controller, |
+ fileapi::FileSystemContext* file_system_context) |
+ : webkit_blob::BlobProtocolHandler( |
+ blob_storage_controller, file_system_context, |
+ BrowserThread::GetMessageLoopProxyForThread( |
+ BrowserThread::FILE)) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ } |
+ |
+ virtual ~Core() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ } |
+ |
+ private: |
+ virtual scoped_refptr<webkit_blob::BlobData> |
+ LookupBlobData(net::URLRequest* request) const OVERRIDE { |
+ const ResourceRequestInfoImpl* info = |
+ ResourceRequestInfoImpl::ForRequest(request); |
+ if (!info) |
+ return NULL; |
+ return info->requested_blob_data(); |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Core); |
+ }; |
+ |
+ scoped_ptr<Core> core_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Delegate); |
+ }; |
+ |
+ scoped_ptr<Delegate> delegate_; |
+ |
DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); |
}; |
@@ -77,9 +134,9 @@ class DeveloperProtocolHandler |
public: |
DeveloperProtocolHandler( |
AppCacheService* appcache_service, |
- BlobStorageController* blob_storage_controller) |
+ ChromeBlobStorageContext* blob_storage_context) |
: appcache_service_(appcache_service), |
- blob_storage_controller_(blob_storage_controller) {} |
+ blob_storage_context_(blob_storage_context) {} |
virtual ~DeveloperProtocolHandler() {} |
virtual net::URLRequestJob* MaybeIntercept( |
@@ -100,7 +157,7 @@ class DeveloperProtocolHandler |
// Next check for chrome://blob-internals/, which uses its own job type. |
if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { |
return ViewBlobInternalsJobFactory::CreateJobForRequest( |
- request, network_delegate, blob_storage_controller_); |
+ request, network_delegate, blob_storage_context_->controller()); |
} |
#if defined(USE_TCMALLOC) |
@@ -139,55 +196,9 @@ class DeveloperProtocolHandler |
private: |
AppCacheService* appcache_service_; |
- BlobStorageController* blob_storage_controller_; |
+ ChromeBlobStorageContext* blob_storage_context_; |
}; |
-void InitializeURLRequestContext( |
- net::URLRequestContextGetter* context_getter, |
- AppCacheService* appcache_service, |
- FileSystemContext* file_system_context, |
- ChromeBlobStorageContext* blob_storage_context) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- if (!context_getter) |
- return; // tests. |
- |
- // This code only modifies the URLRequestJobFactory on the context |
- // to handle blob: URLs, filesystem: URLs, and to let AppCache intercept |
- // the appropriate requests. This is in addition to the slew of other |
- // initializtion that is done in during creation of the URLRequestContext. |
- // We cannot yet centralize this code because URLRequestContext needs |
- // to be created before the StoragePartition context. |
- // |
- // TODO(ajwong): Fix the ordering so all the initialization is in one spot. |
- net::URLRequestContext* context = context_getter->GetURLRequestContext(); |
- net::URLRequestJobFactory* job_factory = |
- const_cast<net::URLRequestJobFactory*>(context->job_factory()); |
- |
- // Note: if this is called twice with 2 request contexts that share one job |
- // factory (as is the case with a media request context and its related |
- // normal request context) then this will early exit. |
- if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) |
- return; // Already initialized this JobFactory. |
- |
- bool set_protocol = job_factory->SetProtocolHandler( |
- chrome::kBlobScheme, |
- new BlobProtocolHandler( |
- blob_storage_context->controller(), |
- file_system_context, |
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); |
- DCHECK(set_protocol); |
- set_protocol = job_factory->SetProtocolHandler( |
- chrome::kFileSystemScheme, |
- CreateFileSystemProtocolHandler(file_system_context)); |
- DCHECK(set_protocol); |
- |
- job_factory->AddInterceptor( |
- new DeveloperProtocolHandler(appcache_service, |
- blob_storage_context->controller())); |
- |
- // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! |
-} |
- |
// These constants are used to create the directory structure under the profile |
// where renderers with a non-default storage partition keep their persistent |
// state. This will contain a set of directories that partially mirror the |
@@ -401,12 +412,28 @@ StoragePartitionImpl* StoragePartitionImplMap::Get( |
partition_path); |
partitions_[partition_config] = partition; |
+ ChromeBlobStorageContext* blob_storage_context = |
+ ChromeBlobStorageContext::GetFor(browser_context_); |
+ scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( |
+ new BlobProtocolHandler(blob_storage_context, |
+ partition->GetFileSystemContext())); |
+ scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
+ file_system_protocol_handler( |
+ CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); |
+ scoped_ptr<net::URLRequestJobFactory::Interceptor> developer_protocol_handler( |
+ new DeveloperProtocolHandler(partition->GetAppCacheService(), |
+ blob_storage_context)); |
+ |
// These calls must happen after StoragePartitionImpl::Create(). |
partition->SetURLRequestContext( |
partition_domain.empty() ? |
- browser_context_->GetRequestContext() : |
- browser_context_->GetRequestContextForStoragePartition( |
- partition->GetPath(), in_memory)); |
+ browser_context_->CreateRequestContext( |
+ blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), |
+ developer_protocol_handler.Pass()) : |
+ browser_context_->CreateRequestContextForStoragePartition( |
+ partition->GetPath(), in_memory, blob_protocol_handler.Pass(), |
+ file_system_protocol_handler.Pass(), |
+ developer_protocol_handler.Pass())); |
partition->SetMediaURLRequestContext( |
partition_domain.empty() ? |
browser_context_->GetMediaRequestContext() : |
@@ -493,17 +520,6 @@ void StoragePartitionImplMap::PostCreateInitialization( |
make_scoped_refptr( |
browser_context_->GetSpecialStoragePolicy()))); |
- // Add content's URLRequestContext's hooks. |
- BrowserThread::PostTask( |
- BrowserThread::IO, FROM_HERE, |
- base::Bind( |
- &InitializeURLRequestContext, |
- make_scoped_refptr(partition->GetURLRequestContext()), |
- make_scoped_refptr(partition->GetAppCacheService()), |
- make_scoped_refptr(partition->GetFileSystemContext()), |
- make_scoped_refptr( |
- ChromeBlobStorageContext::GetFor(browser_context_)))); |
- |
// We do not call InitializeURLRequestContext() for media contexts because, |
// other than the HTTP cache, the media contexts share the same backing |
// objects as their associated "normal" request context. Thus, the previous |