| 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 15 matching lines...) Expand all Loading... |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
| 28 #include "content/public/browser/storage_partition.h" | 28 #include "content/public/browser/storage_partition.h" |
| 29 #include "content/public/common/content_constants.h" | 29 #include "content/public/common/content_constants.h" |
| 30 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
| 31 #include "crypto/sha2.h" | 31 #include "crypto/sha2.h" |
| 32 #include "net/url_request/url_request_context_getter.h" | 32 #include "net/url_request/url_request_context_getter.h" |
| 33 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
| 34 #include "webkit/appcache/view_appcache_internals_job.h" | 34 #include "webkit/appcache/view_appcache_internals_job.h" |
| 35 #include "webkit/blob/blob_data.h" | 35 #include "webkit/blob/blob_data.h" |
| 36 #include "webkit/blob/blob_storage_context.h" |
| 36 #include "webkit/blob/blob_url_request_job_factory.h" | 37 #include "webkit/blob/blob_url_request_job_factory.h" |
| 37 #include "webkit/fileapi/file_system_url_request_job_factory.h" | 38 #include "webkit/fileapi/file_system_url_request_job_factory.h" |
| 38 | 39 |
| 39 using appcache::AppCacheService; | 40 using appcache::AppCacheService; |
| 40 using fileapi::FileSystemContext; | 41 using fileapi::FileSystemContext; |
| 41 using webkit_blob::BlobStorageController; | 42 using webkit_blob::BlobStorageContext; |
| 42 | 43 |
| 43 namespace content { | 44 namespace content { |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler { | |
| 48 public: | |
| 49 BlobProtocolHandler( | |
| 50 webkit_blob::BlobStorageController* blob_storage_controller, | |
| 51 fileapi::FileSystemContext* file_system_context, | |
| 52 base::MessageLoopProxy* loop_proxy) | |
| 53 : webkit_blob::BlobProtocolHandler(blob_storage_controller, | |
| 54 file_system_context, | |
| 55 loop_proxy) {} | |
| 56 | |
| 57 virtual ~BlobProtocolHandler() {} | |
| 58 | |
| 59 private: | |
| 60 virtual scoped_refptr<webkit_blob::BlobData> | |
| 61 LookupBlobData(net::URLRequest* request) const { | |
| 62 const ResourceRequestInfoImpl* info = | |
| 63 ResourceRequestInfoImpl::ForRequest(request); | |
| 64 if (!info) | |
| 65 return NULL; | |
| 66 return info->requested_blob_data(); | |
| 67 } | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); | |
| 70 }; | |
| 71 | |
| 72 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol | 48 // Adds a bunch of debugging urls. We use an interceptor instead of a protocol |
| 73 // handler because we want to reuse the chrome://scheme (everyone is familiar | 49 // handler because we want to reuse the chrome://scheme (everyone is familiar |
| 74 // with it, and no need to expose the content/chrome separation through our UI). | 50 // with it, and no need to expose the content/chrome separation through our UI). |
| 75 class DeveloperProtocolHandler | 51 class DeveloperProtocolHandler |
| 76 : public net::URLRequestJobFactory::Interceptor { | 52 : public net::URLRequestJobFactory::Interceptor { |
| 77 public: | 53 public: |
| 78 DeveloperProtocolHandler( | 54 DeveloperProtocolHandler( |
| 79 AppCacheService* appcache_service, | 55 AppCacheService* appcache_service, |
| 80 BlobStorageController* blob_storage_controller) | 56 BlobStorageContext* blob_storage_context) |
| 81 : appcache_service_(appcache_service), | 57 : appcache_service_(appcache_service), |
| 82 blob_storage_controller_(blob_storage_controller) {} | 58 blob_storage_context_(blob_storage_context) {} |
| 83 virtual ~DeveloperProtocolHandler() {} | 59 virtual ~DeveloperProtocolHandler() {} |
| 84 | 60 |
| 85 virtual net::URLRequestJob* MaybeIntercept( | 61 virtual net::URLRequestJob* MaybeIntercept( |
| 86 net::URLRequest* request, | 62 net::URLRequest* request, |
| 87 net::NetworkDelegate* network_delegate) const OVERRIDE { | 63 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 88 // Check for chrome://view-http-cache/*, which uses its own job type. | 64 // Check for chrome://view-http-cache/*, which uses its own job type. |
| 89 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | 65 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) |
| 90 return ViewHttpCacheJobFactory::CreateJobForRequest(request, | 66 return ViewHttpCacheJobFactory::CreateJobForRequest(request, |
| 91 network_delegate); | 67 network_delegate); |
| 92 | 68 |
| 93 // Next check for chrome://appcache-internals/, which uses its own job type. | 69 // Next check for chrome://appcache-internals/, which uses its own job type. |
| 94 if (request->url().SchemeIs(chrome::kChromeUIScheme) && | 70 if (request->url().SchemeIs(chrome::kChromeUIScheme) && |
| 95 request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { | 71 request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { |
| 96 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( | 72 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( |
| 97 request, network_delegate, appcache_service_); | 73 request, network_delegate, appcache_service_); |
| 98 } | 74 } |
| 99 | 75 |
| 100 // Next check for chrome://blob-internals/, which uses its own job type. | 76 //// Next check for chrome://blob-internals/, which uses its own job type. |
| 101 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { | 77 //if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { |
| 102 return ViewBlobInternalsJobFactory::CreateJobForRequest( | 78 // return ViewBlobInternalsJobFactory::CreateJobForRequest( |
| 103 request, network_delegate, blob_storage_controller_); | 79 // request, network_delegate, blob_storage_controller_); |
| 104 } | 80 //} |
| 105 | 81 |
| 106 #if defined(USE_TCMALLOC) | 82 #if defined(USE_TCMALLOC) |
| 107 // Next check for chrome://tcmalloc/, which uses its own job type. | 83 // Next check for chrome://tcmalloc/, which uses its own job type. |
| 108 if (request->url().SchemeIs(chrome::kChromeUIScheme) && | 84 if (request->url().SchemeIs(chrome::kChromeUIScheme) && |
| 109 request->url().host() == chrome::kChromeUITcmallocHost) { | 85 request->url().host() == chrome::kChromeUITcmallocHost) { |
| 110 return new TcmallocInternalsRequestJob(request, network_delegate); | 86 return new TcmallocInternalsRequestJob(request, network_delegate); |
| 111 } | 87 } |
| 112 #endif | 88 #endif |
| 113 | 89 |
| 114 // Next check for chrome://histograms/, which uses its own job type. | 90 // Next check for chrome://histograms/, which uses its own job type. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 132 net::NetworkDelegate* network_delegate) const OVERRIDE { | 108 net::NetworkDelegate* network_delegate) const OVERRIDE { |
| 133 return NULL; | 109 return NULL; |
| 134 } | 110 } |
| 135 | 111 |
| 136 virtual bool WillHandleProtocol(const std::string& protocol) const { | 112 virtual bool WillHandleProtocol(const std::string& protocol) const { |
| 137 return protocol == chrome::kChromeUIScheme; | 113 return protocol == chrome::kChromeUIScheme; |
| 138 } | 114 } |
| 139 | 115 |
| 140 private: | 116 private: |
| 141 AppCacheService* appcache_service_; | 117 AppCacheService* appcache_service_; |
| 142 BlobStorageController* blob_storage_controller_; | 118 BlobStorageContext* blob_storage_context_; |
| 143 }; | 119 }; |
| 144 | 120 |
| 145 void InitializeURLRequestContext( | 121 void InitializeURLRequestContext( |
| 146 net::URLRequestContextGetter* context_getter, | 122 net::URLRequestContextGetter* context_getter, |
| 147 AppCacheService* appcache_service, | 123 AppCacheService* appcache_service, |
| 148 FileSystemContext* file_system_context, | 124 FileSystemContext* file_system_context, |
| 149 ChromeBlobStorageContext* blob_storage_context) { | 125 ChromeBlobStorageContext* blob_storage_context) { |
| 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 151 if (!context_getter) | 127 if (!context_getter) |
| 152 return; // tests. | 128 return; // tests. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 164 const_cast<net::URLRequestJobFactory*>(context->job_factory()); | 140 const_cast<net::URLRequestJobFactory*>(context->job_factory()); |
| 165 | 141 |
| 166 // Note: if this is called twice with 2 request contexts that share one job | 142 // Note: if this is called twice with 2 request contexts that share one job |
| 167 // factory (as is the case with a media request context and its related | 143 // factory (as is the case with a media request context and its related |
| 168 // normal request context) then this will early exit. | 144 // normal request context) then this will early exit. |
| 169 if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) | 145 if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) |
| 170 return; // Already initialized this JobFactory. | 146 return; // Already initialized this JobFactory. |
| 171 | 147 |
| 172 bool set_protocol = job_factory->SetProtocolHandler( | 148 bool set_protocol = job_factory->SetProtocolHandler( |
| 173 chrome::kBlobScheme, | 149 chrome::kBlobScheme, |
| 174 new BlobProtocolHandler( | 150 new webkit_blob::BlobProtocolHandler( |
| 175 blob_storage_context->controller(), | 151 blob_storage_context->context(), |
| 176 file_system_context, | 152 file_system_context, |
| 177 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 153 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); |
| 178 DCHECK(set_protocol); | 154 DCHECK(set_protocol); |
| 179 set_protocol = job_factory->SetProtocolHandler( | 155 set_protocol = job_factory->SetProtocolHandler( |
| 180 chrome::kFileSystemScheme, | 156 chrome::kFileSystemScheme, |
| 181 CreateFileSystemProtocolHandler(file_system_context)); | 157 CreateFileSystemProtocolHandler(file_system_context)); |
| 182 DCHECK(set_protocol); | 158 DCHECK(set_protocol); |
| 183 | 159 |
| 184 job_factory->AddInterceptor( | 160 job_factory->AddInterceptor( |
| 185 new DeveloperProtocolHandler(appcache_service, | 161 new DeveloperProtocolHandler(appcache_service, |
| 186 blob_storage_context->controller())); | 162 blob_storage_context->context())); |
| 187 | 163 |
| 188 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! | 164 // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! |
| 189 } | 165 } |
| 190 | 166 |
| 191 // These constants are used to create the directory structure under the profile | 167 // These constants are used to create the directory structure under the profile |
| 192 // where renderers with a non-default storage partition keep their persistent | 168 // where renderers with a non-default storage partition keep their persistent |
| 193 // state. This will contain a set of directories that partially mirror the | 169 // state. This will contain a set of directories that partially mirror the |
| 194 // directory structure of BrowserContext::GetPath(). | 170 // directory structure of BrowserContext::GetPath(). |
| 195 // | 171 // |
| 196 // The kStoragePartitionDirname contains an extensions directory which is | 172 // The kStoragePartitionDirname contains an extensions directory which is |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 482 |
| 507 // We do not call InitializeURLRequestContext() for media contexts because, | 483 // We do not call InitializeURLRequestContext() for media contexts because, |
| 508 // other than the HTTP cache, the media contexts share the same backing | 484 // other than the HTTP cache, the media contexts share the same backing |
| 509 // objects as their associated "normal" request context. Thus, the previous | 485 // objects as their associated "normal" request context. Thus, the previous |
| 510 // call serves to initialize the media request context for this storage | 486 // call serves to initialize the media request context for this storage |
| 511 // partition as well. | 487 // partition as well. |
| 512 } | 488 } |
| 513 } | 489 } |
| 514 | 490 |
| 515 } // namespace content | 491 } // namespace content |
| OLD | NEW |