Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Unified Diff: content/browser/resource_context_impl.cc

Issue 9834039: Remove resource_request_info_impl.h dependency from chrome. This also makes blob/file system urls w… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/resource_context_impl.h ('k') | content/browser/worker_host/worker_process_host.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/resource_context_impl.cc
===================================================================
--- content/browser/resource_context_impl.cc (revision 128327)
+++ content/browser/resource_context_impl.cc (working copy)
@@ -4,14 +4,27 @@
#include "content/browser/resource_context_impl.h"
+#include "base/logging.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/host_zoom_map_impl.h"
#include "content/browser/in_process_webkit/indexed_db_context_impl.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/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/common/url_constants.h"
+#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "webkit/appcache/appcache_service.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/database/database_tracker.h"
+#include "webkit/fileapi/file_system_url_request_job_factory.h"
// Key names on ResourceContext.
static const char* kAppCacheServicKeyName = "content_appcache_service_tracker";
@@ -30,6 +43,8 @@
namespace content {
+namespace {
+
class NonOwningZoomData : public base::SupportsUserData::Data {
public:
explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {}
@@ -39,19 +54,119 @@
HostZoomMap* host_zoom_map_;
};
+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) const OVERRIDE {
+ // Check for chrome://view-http-cache/*, which uses its own job type.
+ if (ViewHttpCacheJobFactory::IsSupportedURL(request->url()))
+ return ViewHttpCacheJobFactory::CreateJobForRequest(request);
+
+ // 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, appcache_service_);
+ }
+
+ // Next check for chrome://blob-internals/, which uses its own job type.
+ if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) {
+ return ViewBlobInternalsJobFactory::CreateJobForRequest(
+ request, blob_storage_controller_);
+ }
+ return NULL;
+ }
+
+ virtual net::URLRequestJob* MaybeInterceptRedirect(
+ const GURL& location,
+ net::URLRequest* request) const OVERRIDE {
+ return NULL;
+ }
+
+ virtual net::URLRequestJob* MaybeInterceptResponse(
+ net::URLRequest* request) const OVERRIDE {
+ return NULL;
+ }
+
+ private:
+ AppCacheService* appcache_service_;
+ BlobStorageController* blob_storage_controller_;
+};
+
+void InitializeRequestContext(
+ ResourceContext* resource_context,
+ scoped_refptr<net::URLRequestContextGetter> context_getter) {
+ 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(
+ GetBlobStorageControllerForResourceContext(resource_context),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
+ DCHECK(set_protocol);
+ set_protocol = job_factory->SetProtocolHandler(
+ chrome::kFileSystemScheme,
+ CreateFileSystemProtocolHandler(
+ GetFileSystemContextForResourceContext(resource_context),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
+ DCHECK(set_protocol);
+
+ job_factory->AddInterceptor(new DeveloperProtocolHandler(
+ ResourceContext::GetAppCacheService(resource_context),
+ GetBlobStorageControllerForResourceContext(resource_context)));
+
+ // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here!
+}
+
+} // namespace
+
AppCacheService* ResourceContext::GetAppCacheService(ResourceContext* context) {
return UserDataAdapter<ChromeAppCacheService>::Get(
context, kAppCacheServicKeyName);
}
-FileSystemContext* ResourceContext::GetFileSystemContext(
+BlobStorageController* GetBlobStorageControllerForResourceContext(
ResourceContext* resource_context) {
- return UserDataAdapter<FileSystemContext>::Get(
- resource_context, kFileSystemContextKeyName);
-}
-
-BlobStorageController* ResourceContext::GetBlobStorageController(
- ResourceContext* resource_context) {
return GetChromeBlobStorageContextForResourceContext(resource_context)->
controller();
}
@@ -62,6 +177,12 @@
resource_context, kDatabaseTrackerKeyName);
}
+FileSystemContext* GetFileSystemContextForResourceContext(
+ ResourceContext* resource_context) {
+ return UserDataAdapter<FileSystemContext>::Get(
+ resource_context, kFileSystemContextKeyName);
+}
+
IndexedDBContextImpl* GetIndexedDBContextForResourceContext(
ResourceContext* resource_context) {
return UserDataAdapter<IndexedDBContextImpl>::Get(
@@ -112,6 +233,22 @@
kHostZoomMapKeyName,
new NonOwningZoomData(
HostZoomMap::GetForBrowserContext(browser_context)));
+
+ // Add content's URLRequestContext's hooks.
+ // Check first to avoid memory leak in unittests.
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&InitializeRequestContext,
+ resource_context,
+ make_scoped_refptr(browser_context->GetRequestContext())));
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&InitializeRequestContext,
+ resource_context,
+ make_scoped_refptr(
+ browser_context->GetRequestContextForMedia())));
+ }
}
} // namespace content
« no previous file with comments | « content/browser/resource_context_impl.h ('k') | content/browser/worker_host/worker_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698