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..aa2bdbeb8e56d6e133c9b115ae9ba31a74687ff7 100644 |
| --- a/content/browser/appcache/appcache_url_loader_factory.cc |
| +++ b/content/browser/appcache/appcache_url_loader_factory.cc |
| @@ -6,157 +6,40 @@ |
| #include "base/bind.h" |
| #include "base/logging.h" |
| -#include "content/browser/appcache/appcache_entry.h" |
| -#include "content/browser/appcache/appcache_policy.h" |
| -#include "content/browser/appcache/appcache_request.h" |
| -#include "content/browser/appcache/appcache_storage.h" |
| -#include "content/browser/appcache/chrome_appcache_service.h" |
| +#include "content/browser/appcache/appcache_request_handler.h" |
| +#include "content/browser/appcache/appcache_url_loader_job.h" |
| +#include "content/browser/appcache/appcache_url_loader_request.h" |
| #include "content/browser/url_loader_factory_getter.h" |
| -#include "content/common/network_service.mojom.h" |
| #include "content/common/resource_request.h" |
| -#include "content/common/url_loader.mojom.h" |
| #include "content/common/url_loader_factory.mojom.h" |
| #include "content/public/browser/browser_thread.h" |
| -#include "mojo/public/cpp/bindings/associated_binding.h" |
| -#include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| #include "mojo/public/cpp/bindings/binding_set.h" |
| +#include "mojo/public/cpp/bindings/interface_ptr.h" |
| namespace content { |
| -namespace { |
| - |
| -// Handles AppCache URL loads for the network service. |
| -class AppCacheURLLoader : public AppCacheStorage::Delegate, |
| - public mojom::URLLoader { |
| - public: |
| - AppCacheURLLoader(const ResourceRequest& request, |
| - mojom::URLLoaderAssociatedRequest url_loader_request, |
| - int32_t routing_id, |
| - int32_t request_id, |
| - mojom::URLLoaderClientPtr client_info, |
| - ChromeAppCacheService* appcache_service, |
| - URLLoaderFactoryGetter* factory_getter) |
| - : request_(request), |
| - routing_id_(routing_id), |
| - request_id_(request_id), |
| - client_info_(std::move(client_info)), |
| - appcache_service_(appcache_service), |
| - factory_getter_(factory_getter), |
| - binding_(this, std::move(url_loader_request)) { |
| - binding_.set_connection_error_handler(base::Bind( |
| - &AppCacheURLLoader::OnConnectionError, base::Unretained(this))); |
| - } |
| - |
| - ~AppCacheURLLoader() override {} |
| - |
| - void Start() { |
| - // If the origin does not exist in the AppCache usage map, then we can |
| - // safely call the network service here. |
| - if (appcache_service_->storage()->usage_map()->find( |
| - request_.url.GetOrigin()) == |
| - appcache_service_->storage()->usage_map()->end()) { |
| - factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( |
| - mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, |
| - mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); |
| - return; |
| - } |
| - |
| - appcache_service_->storage()->FindResponseForMainRequest(request_.url, |
| - GURL(), this); |
| - } |
| - |
| - // mojom::URLLoader implementation: |
| - void FollowRedirect() override { network_loader_request_->FollowRedirect(); } |
| - |
| - void SetPriority(net::RequestPriority priority, |
| - int32_t intra_priority_value) override { |
| - DCHECK(false); |
| - } |
| - |
| - private: |
| - // AppCacheStorage::Delegate methods. |
| - void OnMainResponseFound(const GURL& url, |
| - const AppCacheEntry& entry, |
| - const GURL& fallback_url, |
| - const AppCacheEntry& fallback_entry, |
| - int64_t cache_id, |
| - int64_t group_id, |
| - const GURL& manifest_url) override { |
| - AppCachePolicy* policy = appcache_service_->appcache_policy(); |
| - bool was_blocked_by_policy = |
| - !manifest_url.is_empty() && policy && |
| - !policy->CanLoadAppCache(manifest_url, |
| - request_.first_party_for_cookies); |
| - |
| - if (was_blocked_by_policy || !entry.has_response_id() || |
| - cache_id == kAppCacheNoCacheId) { |
| - factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( |
| - mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, |
| - mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); |
| - } else { |
| - DLOG(WARNING) << "AppCache found for url " << url |
| - << " Returning AppCache factory\n"; |
| - // TODO(ananta) |
| - // Provide the plumbing to initiate AppCache requests here. |
| - factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( |
| - mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, |
| - mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); |
| - } |
| - } |
| - |
| - void OnConnectionError() { delete this; } |
| - |
| - // The current request. |
| - ResourceRequest request_; |
| - |
| - // URLLoader proxy for the network service. |
| - mojom::URLLoaderAssociatedPtr network_loader_request_; |
| - |
| - // Routing id of the request. This is 0 for navigation requests. For |
| - // subresource requests it is non zero. |
| - int routing_id_; |
| - |
| - // Request id. |
| - int request_id_; |
| - |
| - // The URLLoaderClient pointer. We call this interface with notifications |
| - // about the URL load |
| - mojom::URLLoaderClientPtr client_info_; |
| - |
| - // Used to query AppCacheStorage to see if a request can be served out of the |
| - /// AppCache. |
| - scoped_refptr<ChromeAppCacheService> appcache_service_; |
| - |
| - // Used to retrieve the network service factory to pass requests to the |
| - // network service. |
| - scoped_refptr<URLLoaderFactoryGetter> factory_getter_; |
| - |
| - // Binds the URLLoaderClient with us. |
| - mojo::AssociatedBinding<mojom::URLLoader> binding_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader); |
| -}; |
| - |
| -} // namespace |
| - |
| // Implements the URLLoaderFactory mojom for AppCache requests. |
| AppCacheURLLoaderFactory::AppCacheURLLoaderFactory( |
| - ChromeAppCacheService* appcache_service, |
| + mojom::URLLoaderFactoryRequest request, |
| URLLoaderFactoryGetter* factory_getter) |
| - : appcache_service_(appcache_service), factory_getter_(factory_getter) {} |
| + : binding_(this, std::move(request)), factory_getter_(factory_getter) { |
| + binding_.set_connection_error_handler(base::Bind( |
| + &AppCacheURLLoaderFactory::OnConnectionError, base::Unretained(this))); |
| +} |
| AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {} |
| // static |
| -void AppCacheURLLoaderFactory::CreateURLLoaderFactory( |
| - mojom::URLLoaderFactoryRequest request, |
| - ChromeAppCacheService* appcache_service, |
| +mojom::URLLoaderFactoryPtr AppCacheURLLoaderFactory::CreateURLLoaderFactory( |
|
kinuko
2017/06/08 10:31:21
Is this still used somewhere?
ananta
2017/06/08 13:48:56
Not at the moment. Will be used in some capacity w
|
| URLLoaderFactoryGetter* factory_getter) { |
| - std::unique_ptr<AppCacheURLLoaderFactory> factory_instance( |
| - new AppCacheURLLoaderFactory(appcache_service, factory_getter)); |
| - AppCacheURLLoaderFactory* raw_factory = factory_instance.get(); |
| - raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance), |
| - std::move(request)); |
| + mojom::URLLoaderFactoryPtr loader_factory; |
| + mojom::URLLoaderFactoryRequest request = mojo::MakeRequest(&loader_factory); |
| + |
| + // This instance will get deleted when the client drops the connection. |
| + // Please see OnConnectionError() for details. |
| + new AppCacheURLLoaderFactory(std::move(request), factory_getter); |
| + return loader_factory; |
| } |
| void AppCacheURLLoaderFactory::CreateLoaderAndStart( |
| @@ -167,12 +50,7 @@ void AppCacheURLLoaderFactory::CreateLoaderAndStart( |
| const ResourceRequest& request, |
| mojom::URLLoaderClientPtr client) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - |
| - // 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()); |
| - loader->Start(); |
| + NOTREACHED() << "Currently not implemented"; |
| } |
| void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id, |
| @@ -182,4 +60,8 @@ void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id, |
| NOTREACHED(); |
| } |
| +void AppCacheURLLoaderFactory::OnConnectionError() { |
| + base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| +} |
| + |
| } // namespace content |