Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/appcache/appcache_url_loader_factory.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "content/browser/appcache/appcache_entry.h" | |
| 10 #include "content/browser/appcache/appcache_policy.h" | |
| 11 #include "content/browser/appcache/appcache_request.h" | |
| 12 #include "content/browser/appcache/appcache_storage.h" | |
| 13 #include "content/browser/appcache/chrome_appcache_service.h" | |
| 14 #include "content/browser/url_loader_factory_getter.h" | |
| 15 #include "content/common/network_service.mojom.h" | |
| 16 #include "content/common/resource_request.h" | |
| 17 #include "content/common/url_loader.mojom.h" | |
| 18 #include "content/common/url_loader_factory.mojom.h" | |
| 19 #include "content/public/browser/browser_thread.h" | |
| 20 #include "mojo/public/cpp/bindings/associated_binding.h" | |
| 21 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" | |
| 22 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 23 | |
| 24 namespace content { | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 // Handles AppCache URL loads for the network service. | |
| 29 class AppCacheURLLoader : public AppCacheStorage::Delegate, | |
| 30 public mojom::URLLoader { | |
| 31 public: | |
| 32 AppCacheURLLoader(const ResourceRequest& request, | |
| 33 mojom::URLLoaderAssociatedRequest url_loader_request, | |
| 34 int32_t routing_id, | |
| 35 int32_t request_id, | |
| 36 mojom::URLLoaderClientPtr client_info, | |
| 37 ResourceType resource_type, | |
| 38 ChromeAppCacheService* appcache_service, | |
| 39 URLLoaderFactoryGetter* factory_getter) | |
| 40 : request_(request), | |
| 41 routing_id_(routing_id), | |
| 42 request_id_(request_id), | |
| 43 client_info_(std::move(client_info)), | |
| 44 resource_type_(resource_type), | |
| 45 appcache_service_(appcache_service), | |
| 46 factory_getter_(factory_getter), | |
| 47 binding_(this, std::move(url_loader_request)) { | |
| 48 binding_.set_connection_error_handler(base::Bind( | |
| 49 &AppCacheURLLoader::OnConnectionError, base::Unretained(this))); | |
| 50 } | |
| 51 | |
| 52 ~AppCacheURLLoader() override {} | |
| 53 | |
| 54 void Start() { | |
| 55 appcache_service_->storage()->FindResponseForMainRequest(request_.url, | |
| 56 GURL(), this); | |
| 57 } | |
| 58 | |
| 59 // mojom::URLLoader implementation: | |
| 60 void FollowRedirect() override { | |
| 61 network_loader_request_->FollowRedirect(); | |
| 62 } | |
| 63 | |
| 64 void SetPriority(net::RequestPriority priority, | |
| 65 int32_t intra_priority_value) override { | |
| 66 DCHECK(false); | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 // AppCacheStorage::Delegate methods | |
| 71 // The AppCacheNetworkServiceHandler instance is deleted on return from this | |
|
kinuko
2017/05/17 16:54:29
The comment looks stale now
ananta
2017/05/17 18:14:08
Done.
| |
| 72 // function. | |
| 73 void OnMainResponseFound(const GURL& url, | |
| 74 const AppCacheEntry& entry, | |
| 75 const GURL& fallback_url, | |
| 76 const AppCacheEntry& fallback_entry, | |
| 77 int64_t cache_id, | |
| 78 int64_t group_id, | |
| 79 const GURL& manifest_url) override { | |
| 80 AppCachePolicy* policy = appcache_service_->appcache_policy(); | |
| 81 bool was_blocked_by_policy = | |
| 82 !manifest_url.is_empty() && policy && | |
| 83 !policy->CanLoadAppCache(manifest_url, | |
| 84 request_.first_party_for_cookies); | |
| 85 | |
| 86 if (was_blocked_by_policy || !entry.has_response_id() || | |
| 87 cache_id == kAppCacheNoCacheId) { | |
| 88 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( | |
| 89 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, | |
|
jam
2017/05/17 16:51:12
I think you want to call Unbind() here and pass th
ananta
2017/05/17 18:14:08
I ran into a number of problems trying to do that.
jam
2017/05/18 14:16:14
Which problems did you run into? I think we should
jam
2017/05/19 00:03:50
ok, nvm mind this comment for now, Ananta/Yuzhu/me
| |
| 90 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); | |
| 91 } else { | |
| 92 DLOG(WARNING) << "AppCache found for url " << url | |
| 93 << " Returning AppCache factory\n"; | |
| 94 // TODO(ananta) | |
| 95 // Provide the plumbing to initiate AppCache requests here. | |
| 96 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( | |
| 97 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, | |
| 98 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 void OnConnectionError() { delete this; } | |
| 103 | |
| 104 // The current request. | |
| 105 ResourceRequest request_; | |
| 106 | |
| 107 // URLLoader proxy for the network service. | |
| 108 mojom::URLLoaderAssociatedPtr network_loader_request_; | |
| 109 | |
| 110 // Routing id of the request. This is 0 for navigation requests. For | |
| 111 // subresource requests it is non zero. | |
| 112 int routing_id_; | |
| 113 | |
| 114 // Request id. | |
| 115 int request_id_; | |
| 116 | |
| 117 // The URLLoaderClient pointer. We call this interface with notifications | |
| 118 // about the URL load | |
| 119 mojom::URLLoaderClientPtr client_info_; | |
| 120 | |
| 121 // Used to query AppCacheStorage to see if a request can be served out of the | |
| 122 /// AppCache. | |
| 123 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
| 124 | |
| 125 // Used to retrieve the network service factory to pass requests to the | |
| 126 // network service. | |
| 127 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; | |
| 128 | |
| 129 // Binds the URLLoaderClient with us. | |
| 130 mojo::AssociatedBinding<mojom::URLLoader> binding_; | |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader); | |
| 133 }; | |
| 134 | |
| 135 } // namespace | |
| 136 | |
| 137 // Implements the URLLoaderFactory mojom for AppCache requests. | |
| 138 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory( | |
| 139 ChromeAppCacheService* appcache_service, | |
| 140 URLLoaderFactoryGetter* factory_getter) | |
| 141 : appcache_service_(appcache_service), factory_getter_(factory_getter) {} | |
| 142 | |
| 143 AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {} | |
| 144 | |
| 145 // static | |
| 146 void AppCacheURLLoaderFactory::CreateURLLoaderFactory( | |
| 147 mojom::URLLoaderFactoryRequest request, | |
| 148 ChromeAppCacheService* appcache_service, | |
| 149 URLLoaderFactoryGetter* factory_getter) { | |
| 150 std::unique_ptr<AppCacheURLLoaderFactory> factory_instance( | |
| 151 new AppCacheURLLoaderFactory(appcache_service, factory_getter)); | |
| 152 AppCacheURLLoaderFactory* raw_factory = factory_instance.get(); | |
| 153 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance), | |
| 154 std::move(request)); | |
| 155 } | |
| 156 | |
| 157 void AppCacheURLLoaderFactory::CreateLoaderAndStart( | |
| 158 mojom::URLLoaderAssociatedRequest url_loader_request, | |
| 159 int32_t routing_id, | |
| 160 int32_t request_id, | |
| 161 uint32_t options, | |
| 162 const ResourceRequest& request, | |
| 163 mojom::URLLoaderClientPtr client) { | |
| 164 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 165 StartURLLoader(request, std::move(url_loader_request), routing_id, request_id, | |
| 166 std::move(client)); | |
| 167 } | |
| 168 | |
| 169 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id, | |
| 170 int32_t request_id, | |
| 171 const ResourceRequest& request, | |
| 172 SyncLoadCallback callback) { | |
| 173 NOTREACHED(); | |
| 174 } | |
| 175 | |
| 176 void AppCacheURLLoaderFactory::StartURLLoader( | |
|
jam
2017/05/17 16:51:12
nit: what's the purpose of this separate method?
ananta
2017/05/17 18:14:08
Thanks removed.
| |
| 177 const ResourceRequest& request, | |
| 178 mojom::URLLoaderAssociatedRequest url_loader_request, | |
| 179 int32_t routing_id, | |
| 180 int32_t request_id, | |
| 181 mojom::URLLoaderClientPtr client_info) { | |
| 182 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 183 // This will get deleted when the connection is dropped by the client. | |
|
kinuko
2017/05/17 16:54:30
It doesn't look using StrongBinding, is it true?
ananta
2017/05/17 18:14:08
We delete the object in the connection error. Plea
| |
| 184 AppCacheURLLoader* loader = new AppCacheURLLoader( | |
| 185 request, std::move(url_loader_request), routing_id, request_id, | |
| 186 std::move(client_info), request.resource_type, appcache_service_.get(), | |
| 187 factory_getter_.get()); | |
| 188 loader->Start(); | |
| 189 } | |
| 190 | |
| 191 } // namespace content | |
| OLD | NEW |