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 b1ba82c3bc2fea5c60ba5d49637704f18f14147f..3263a0be7bd92c28ec50113dcd08505a23b8aba9 100644 |
--- a/content/browser/storage_partition_impl_map.cc |
+++ b/content/browser/storage_partition_impl_map.cc |
@@ -10,15 +10,166 @@ |
#include "base/stl_util.h" |
#include "base/string_util.h" |
#include "content/browser/appcache/chrome_appcache_service.h" |
+#include "content/browser/fileapi/browser_file_system_helper.h" |
+#include "content/browser/fileapi/chrome_blob_storage_context.h" |
+#include "content/browser/histogram_internals_request_job.h" |
+#include "content/browser/net/view_blob_internals_job_factory.h" |
+#include "content/browser/net/view_http_cache_job_factory.h" |
+#include "content/browser/renderer_host/resource_request_info_impl.h" |
#include "content/browser/resource_context_impl.h" |
#include "content/browser/storage_partition_impl.h" |
+#include "content/browser/tcmalloc_internals_request_job.h" |
#include "content/public/browser/browser_context.h" |
#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/storage_partition.h" |
#include "content/public/common/content_constants.h" |
+#include "content/public/common/url_constants.h" |
#include "net/url_request/url_request_context_getter.h" |
+#include "net/url_request/url_request_context.h" |
+#include "webkit/appcache/view_appcache_internals_job.h" |
+#include "webkit/blob/blob_data.h" |
+#include "webkit/blob/blob_url_request_job_factory.h" |
+#include "webkit/fileapi/file_system_url_request_job_factory.h" |
+ |
+using appcache::AppCacheService; |
+using content::BrowserThread; |
+using fileapi::FileSystemContext; |
+using webkit_blob::BlobStorageController; |
namespace content { |
+namespace { |
+ |
+class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler { |
+ public: |
+ BlobProtocolHandler( |
+ webkit_blob::BlobStorageController* blob_storage_controller, |
+ base::MessageLoopProxy* loop_proxy) |
+ : webkit_blob::BlobProtocolHandler(blob_storage_controller, |
+ loop_proxy) {} |
+ |
+ virtual ~BlobProtocolHandler() {} |
+ |
+ 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(); |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); |
+}; |
+ |
+// Adds a bunch of debugging urls. We use an interceptor instead of a protocol |
+// handler because we want to reuse the chrome://scheme (everyone is familiar |
+// with it, and no need to expose the content/chrome separation through our UI). |
+class DeveloperProtocolHandler |
+ : public net::URLRequestJobFactory::Interceptor { |
+ public: |
+ DeveloperProtocolHandler( |
+ AppCacheService* appcache_service, |
+ BlobStorageController* blob_storage_controller) |
+ : appcache_service_(appcache_service), |
+ blob_storage_controller_(blob_storage_controller) {} |
+ virtual ~DeveloperProtocolHandler() {} |
+ |
+ virtual net::URLRequestJob* MaybeIntercept( |
+ net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate) const OVERRIDE { |
+ // Check for chrome://view-http-cache/*, which uses its own job type. |
+ if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) |
+ return ViewHttpCacheJobFactory::CreateJobForRequest(request, |
+ network_delegate); |
+ |
+ // Next check for chrome://appcache-internals/, which uses its own job type. |
+ if (request->url().SchemeIs(chrome::kChromeUIScheme) && |
+ request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { |
+ return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( |
+ request, network_delegate, appcache_service_); |
+ } |
+ |
+ // 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_); |
+ } |
+ |
+#if defined(USE_TCMALLOC) |
+ // Next check for chrome://tcmalloc/, which uses its own job type. |
+ if (request->url().SchemeIs(chrome::kChromeUIScheme) && |
+ request->url().host() == chrome::kChromeUITcmallocHost) { |
+ return new TcmallocInternalsRequestJob(request, network_delegate); |
+ } |
+#endif |
+ |
+ // Next check for chrome://histograms/, which uses its own job type. |
+ if (request->url().SchemeIs(chrome::kChromeUIScheme) && |
+ request->url().host() == chrome::kChromeUIHistogramHost) { |
+ return new HistogramInternalsRequestJob(request, network_delegate); |
+ } |
+ |
+ return NULL; |
+ } |
+ |
+ virtual net::URLRequestJob* MaybeInterceptRedirect( |
+ const GURL& location, |
+ net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate) const OVERRIDE { |
+ return NULL; |
+ } |
+ |
+ virtual net::URLRequestJob* MaybeInterceptResponse( |
+ net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate) const OVERRIDE { |
+ return NULL; |
+ } |
+ |
+ virtual bool WillHandleProtocol(const std::string& protocol) const { |
+ return protocol == chrome::kChromeUIScheme; |
+ } |
+ |
+ private: |
+ AppCacheService* appcache_service_; |
+ BlobStorageController* blob_storage_controller_; |
+}; |
+ |
+void InitializeURLRequestContext( |
+ scoped_refptr<net::URLRequestContextGetter> context_getter, |
michaeln
2012/09/15 01:48:33
this first argument could be a raw ptr like the ot
awong
2012/09/15 02:05:02
Done.
|
+ AppCacheService* appcache_service, |
+ FileSystemContext* file_system_context, |
+ ChromeBlobStorageContext* blob_storage_context) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ if (!context_getter) |
+ return; // tests. |
+ net::URLRequestContext* context = context_getter->GetURLRequestContext(); |
+ net::URLRequestJobFactory* job_factory = |
+ const_cast<net::URLRequestJobFactory*>(context->job_factory()); |
+ if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) |
+ return; // Already initialized this RequestContext. |
+ |
+ bool set_protocol = job_factory->SetProtocolHandler( |
+ chrome::kBlobScheme, |
+ new BlobProtocolHandler( |
+ blob_storage_context->controller(), |
+ 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! |
+} |
+ |
+} // namespace |
+ |
StoragePartitionImplMap::StoragePartitionImplMap( |
BrowserContext* browser_context) |
: browser_context_(browser_context) { |
@@ -46,24 +197,31 @@ StoragePartitionImpl* StoragePartitionImplMap::Get( |
.AppendASCII(partition_id); |
} |
- StoragePartitionImpl* storage_partition = |
+ StoragePartitionImpl* partition = |
StoragePartitionImpl::Create(browser_context_, partition_path); |
- partitions_[partition_id] = storage_partition; |
+ partitions_[partition_id] = partition; |
- net::URLRequestContextGetter* request_context = partition_id.empty() ? |
+ // These calls must happen after StoragePartitionImpl::Create(). |
+ partition->SetURLRequestContext( |
+ partition_id.empty() ? |
browser_context_->GetRequestContext() : |
- browser_context_->GetRequestContextForStoragePartition(partition_id); |
+ browser_context_->GetRequestContextForStoragePartition(partition_id)); |
+ partition->SetMediaURLRequestContext( |
+ partition_id.empty() ? browser_context_->GetMediaRequestContext() : |
michaeln
2012/09/15 01:48:33
nit: using a more consistent wrapping style for th
awong
2012/09/15 02:05:02
Done.
|
+ browser_context_->GetMediaRequestContextForStoragePartition( |
+ partition_id)); |
- PostCreateInitialization(storage_partition, partition_path, request_context); |
+ PostCreateInitialization(partition, partition_path); |
- // TODO(ajwong): We need to remove this conditional by making |
- // InitializeResourceContext() understand having different partition data |
- // based on the renderer_id. |
+ // TODO(ajwong): ResourceContexts no longer have any storage related state. |
+ // We should move this into a place where it is called once per |
+ // BrowserContext creation rather than piggybacking off the default context |
+ // creation. |
if (partition_id.empty()) { |
InitializeResourceContext(browser_context_); |
} |
- return storage_partition; |
+ return partition; |
} |
void StoragePartitionImplMap::ForEach( |
@@ -78,8 +236,7 @@ void StoragePartitionImplMap::ForEach( |
void StoragePartitionImplMap::PostCreateInitialization( |
StoragePartitionImpl* partition, |
- const FilePath& partition_path, |
- net::URLRequestContextGetter* request_context_getter) { |
+ const FilePath& partition_path) { |
// Check first to avoid memory leak in unittests. |
if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
BrowserThread::PostTask( |
@@ -89,9 +246,29 @@ void StoragePartitionImplMap::PostCreateInitialization( |
browser_context_->IsOffTheRecord() ? FilePath() : |
partition_path.Append(kAppCacheDirname), |
browser_context_->GetResourceContext(), |
- make_scoped_refptr(request_context_getter), |
+ make_scoped_refptr(partition->GetURLRequestContext()), |
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_)))); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind( |
+ &InitializeURLRequestContext, |
+ make_scoped_refptr(partition->GetMediaURLRequestContext()), |
+ make_scoped_refptr(partition->GetAppCacheService()), |
+ make_scoped_refptr(partition->GetFileSystemContext()), |
+ make_scoped_refptr( |
+ ChromeBlobStorageContext::GetFor(browser_context_)))); |
} |
} |