Chromium Code Reviews| Index: content/browser/appcache/appcache_url_loader_factory.cc |
| diff --git a/content/browser/appcache/appcache_url_loader_factory.cc b/content/browser/appcache/appcache_url_loader_factory.cc |
| index 37c105abc9091b0170aa1fb9541736d9d434d9ec..8ac0dbf4f192c7c127c98e40424616d85d7bf8b9 100644 |
| --- a/content/browser/appcache/appcache_url_loader_factory.cc |
| +++ b/content/browser/appcache/appcache_url_loader_factory.cc |
| @@ -6,7 +6,9 @@ |
| #include "base/bind.h" |
| #include "base/logging.h" |
| +#include "content/browser/appcache/appcache_backend_impl.h" |
| #include "content/browser/appcache/appcache_entry.h" |
| +#include "content/browser/appcache/appcache_host.h" |
| #include "content/browser/appcache/appcache_policy.h" |
| #include "content/browser/appcache/appcache_request.h" |
| #include "content/browser/appcache/appcache_storage.h" |
| @@ -25,6 +27,8 @@ namespace content { |
| namespace { |
| +AppCacheHost* g_host = nullptr; |
|
michaeln
2017/05/24 00:59:32
I don't think we should add this, i'd vote to take
ananta
2017/05/24 02:14:03
This code is going to change once kinuko lands her
|
| + |
| // Handles AppCache URL loads for the network service. |
| class AppCacheURLLoader : public AppCacheStorage::Delegate, |
| public mojom::URLLoader { |
| @@ -35,13 +39,15 @@ class AppCacheURLLoader : public AppCacheStorage::Delegate, |
| int32_t request_id, |
| mojom::URLLoaderClientPtr client_info, |
| ChromeAppCacheService* appcache_service, |
| - URLLoaderFactoryGetter* factory_getter) |
| + URLLoaderFactoryGetter* factory_getter, |
| + AppCacheHost* host) |
| : request_(request), |
| routing_id_(routing_id), |
| request_id_(request_id), |
| client_info_(std::move(client_info)), |
| appcache_service_(appcache_service), |
| factory_getter_(factory_getter), |
| + host_(host), |
| binding_(this, std::move(url_loader_request)) { |
| binding_.set_connection_error_handler(base::Bind( |
| &AppCacheURLLoader::OnConnectionError, base::Unretained(this))); |
| @@ -95,7 +101,8 @@ class AppCacheURLLoader : public AppCacheStorage::Delegate, |
| mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); |
| } else { |
| DLOG(WARNING) << "AppCache found for url " << url |
| - << " Returning AppCache factory\n"; |
| + << " host id is " << host_->host_id() |
| + << " Passing request to default factory\n"; |
| // TODO(ananta) |
| // Provide the plumbing to initiate AppCache requests here. |
| factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( |
| @@ -131,6 +138,10 @@ class AppCacheURLLoader : public AppCacheStorage::Delegate, |
| // network service. |
| scoped_refptr<URLLoaderFactoryGetter> factory_getter_; |
| + // We don't own the AppCacheHost pointer. This is safe as the host outlives |
|
michaeln
2017/05/24 00:59:32
what guarantees that?
ananta
2017/05/24 02:14:03
Changed to take the host in the Start() function.
|
| + // us. |
| + AppCacheHost* host_; |
| + |
| // Binds the URLLoaderClient with us. |
| mojo::AssociatedBinding<mojom::URLLoader> binding_; |
| @@ -142,8 +153,11 @@ class AppCacheURLLoader : public AppCacheStorage::Delegate, |
| // Implements the URLLoaderFactory mojom for AppCache requests. |
| AppCacheURLLoaderFactory::AppCacheURLLoaderFactory( |
| ChromeAppCacheService* appcache_service, |
| - URLLoaderFactoryGetter* factory_getter) |
| - : appcache_service_(appcache_service), factory_getter_(factory_getter) {} |
| + URLLoaderFactoryGetter* factory_getter, |
| + int renderer_process_id) |
| + : appcache_service_(appcache_service), |
| + factory_getter_(factory_getter), |
| + renderer_process_id_(renderer_process_id) {} |
| AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {} |
| @@ -151,14 +165,22 @@ AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {} |
| void AppCacheURLLoaderFactory::CreateURLLoaderFactory( |
| mojom::URLLoaderFactoryRequest request, |
| ChromeAppCacheService* appcache_service, |
| - URLLoaderFactoryGetter* factory_getter) { |
| + URLLoaderFactoryGetter* factory_getter, |
| + int renderer_process_id) { |
| std::unique_ptr<AppCacheURLLoaderFactory> factory_instance( |
| - new AppCacheURLLoaderFactory(appcache_service, factory_getter)); |
| + new AppCacheURLLoaderFactory(appcache_service, factory_getter, |
| + renderer_process_id)); |
| AppCacheURLLoaderFactory* raw_factory = factory_instance.get(); |
| raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance), |
| std::move(request)); |
| } |
| +// static |
| +void AppCacheURLLoaderFactory::SetAppCacheHost(AppCacheHost* host) { |
| + DCHECK(!g_host); |
| + g_host = host; |
| +} |
| + |
| void AppCacheURLLoaderFactory::CreateLoaderAndStart( |
| mojom::URLLoaderAssociatedRequest url_loader_request, |
| int32_t routing_id, |
| @@ -168,10 +190,23 @@ void AppCacheURLLoaderFactory::CreateLoaderAndStart( |
| mojom::URLLoaderClientPtr client) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + AppCacheHost* host = nullptr; |
| + if (renderer_process_id_ != -1) { |
| + AppCacheBackendImpl* backend = |
| + appcache_service_->GetBackend(renderer_process_id_); |
| + DCHECK(backend); |
| + host = backend->GetHost(request.appcache_host_id); |
| + DCHECK(host); |
| + } else { |
| + DCHECK(g_host); |
| + host = g_host; |
| + g_host = nullptr; |
| + } |
| + |
| // This will get deleted when the connection is dropped by the client. |
| AppCacheURLLoader* loader = new AppCacheURLLoader( |
| request, std::move(url_loader_request), routing_id, request_id, |
| - std::move(client), appcache_service_.get(), factory_getter_.get()); |
| + std::move(client), appcache_service_.get(), factory_getter_.get(), host); |
| loader->Start(); |
| } |