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

Side by Side Diff: content/browser/appcache/appcache_url_loader_factory.cc

Issue 2902653002: Get main frame and subframe AppCache loads to work. (Closed)
Patch Set: Address portions of the review comments Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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/appcache/appcache_url_loader_factory.h" 5 #include "content/browser/appcache/appcache_url_loader_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/appcache/appcache_entry.h" 9 #include "content/browser/appcache/appcache_backend_impl.h"
10 #include "content/browser/appcache/appcache_policy.h" 10 #include "content/browser/appcache/appcache_host.h"
11 #include "content/browser/appcache/appcache_navigation_handle_core.h"
11 #include "content/browser/appcache/appcache_request.h" 12 #include "content/browser/appcache/appcache_request.h"
13 #include "content/browser/appcache/appcache_request_handler.h"
12 #include "content/browser/appcache/appcache_storage.h" 14 #include "content/browser/appcache/appcache_storage.h"
15 #include "content/browser/appcache/appcache_url_loader_job.h"
16 #include "content/browser/appcache/appcache_url_loader_request.h"
13 #include "content/browser/appcache/chrome_appcache_service.h" 17 #include "content/browser/appcache/chrome_appcache_service.h"
18 #include "content/browser/loader/url_loader_request_handler.h"
14 #include "content/browser/url_loader_factory_getter.h" 19 #include "content/browser/url_loader_factory_getter.h"
15 #include "content/common/network_service.mojom.h"
16 #include "content/common/resource_request.h" 20 #include "content/common/resource_request.h"
17 #include "content/common/url_loader.mojom.h" 21 #include "content/common/url_loader.mojom.h"
18 #include "content/common/url_loader_factory.mojom.h" 22 #include "content/common/url_loader_factory.mojom.h"
19 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
20 #include "mojo/public/cpp/bindings/binding.h" 24 #include "mojo/public/cpp/bindings/binding.h"
21 #include "mojo/public/cpp/bindings/binding_set.h" 25 #include "mojo/public/cpp/bindings/binding_set.h"
22 #include "mojo/public/cpp/bindings/interface_ptr.h" 26 #include "mojo/public/cpp/bindings/interface_ptr.h"
27 #include "mojo/public/cpp/system/data_pipe.h"
28 #include "net/base/io_buffer.h"
29 #include "net/http/http_response_headers.h"
23 30
24 namespace content { 31 namespace content {
25 32
26 namespace { 33 // This class implements the URLLoader mojom which provides functionality to
34 // service URL loads from the AppCache. It is also invoked for navigation
35 // requests to check if they can be serviced from the AppCache. If yes then
36 // it creates an instance of the AppCacheURLLoaderFactory class and passes it
37 // to the LoaderFactoryCallback callback. If not it invokes the
38 // LoaderFactoryCallback with a null factory pointer which passes the request
39 // to the next handler.
40 class AppCacheURLLoader : public mojom::URLLoader,
41 public AppCacheURLLoaderJob::Delegate {
42 public:
43 // Creates an instance of the AppCacheURLLoader class which checks if the
44 // navigation |request| can be served via AppCache. If yes it creates an
45 // instance of the AppCacheURLLoaderFactory class and passes it to the
46 // |callback|. If not it invokes the callback with a null factory which
47 // indicates that the next handler should be invoked.
48 static AppCacheURLLoader* CreateForNavigationRequest(
49 const ResourceRequest& request,
50 ChromeAppCacheService* appcache_service,
51 LoaderFactoryCallback callback,
52 URLLoaderFactoryGetter* factory_getter) {
53 AppCacheURLLoader* loader = new AppCacheURLLoader(
54 request, appcache_service, std::move(callback), factory_getter);
55 return loader;
56 }
27 57
28 // Handles AppCache URL loads for the network service. 58 // Creates an instance of the AppCacheURLLoader class which is used to handle
29 class AppCacheURLLoader : public AppCacheStorage::Delegate, 59 // URL requests from the client. We expect this function to be called for
30 public mojom::URLLoader { 60 // handling subresource requests.
31 public: 61 static AppCacheURLLoader* CreateForURLLoads(
32 AppCacheURLLoader(const ResourceRequest& request, 62 const ResourceRequest& request,
33 mojom::URLLoaderRequest url_loader_request, 63 mojom::URLLoaderRequest url_loader_request,
34 int32_t routing_id, 64 int32_t routing_id,
35 int32_t request_id, 65 int32_t request_id,
36 mojom::URLLoaderClientPtr client_info, 66 mojom::URLLoaderClientPtr client_info,
37 ChromeAppCacheService* appcache_service, 67 ChromeAppCacheService* appcache_service,
38 URLLoaderFactoryGetter* factory_getter) 68 URLLoaderFactoryGetter* factory_getter) {
39 : request_(request), 69 AppCacheURLLoader* loader = new AppCacheURLLoader(
40 routing_id_(routing_id), 70 request, std::move(url_loader_request), routing_id, request_id,
41 request_id_(request_id), 71 std::move(client_info), appcache_service, factory_getter);
42 client_info_(std::move(client_info)), 72 return loader;
43 appcache_service_(appcache_service),
44 factory_getter_(factory_getter),
45 binding_(this, std::move(url_loader_request)) {
46 binding_.set_connection_error_handler(base::Bind(
47 &AppCacheURLLoader::OnConnectionError, base::Unretained(this)));
48 } 73 }
49 74
50 ~AppCacheURLLoader() override {} 75 ~AppCacheURLLoader() override {}
51 76
52 void Start() { 77 // Starts the process of checking if the request can be served from the
78 // AppCache.
79 void Start(AppCacheHost* host) {
80 DCHECK(host);
53 // If the origin does not exist in the AppCache usage map, then we can 81 // If the origin does not exist in the AppCache usage map, then we can
54 // safely call the network service here. 82 // safely call the network service or pass it to the next handler.
55 if (appcache_service_->storage()->usage_map()->find( 83 if (IsResourceTypeFrame(request_.resource_type) &&
84 appcache_service_->storage()->IsInitialized() &&
michaeln 2017/06/02 23:47:27 ditto about using the host's storage() accessor
ananta 2017/06/03 01:55:56 Not needed anymore.
85 appcache_service_->storage()->usage_map()->find(
56 request_.url.GetOrigin()) == 86 request_.url.GetOrigin()) ==
57 appcache_service_->storage()->usage_map()->end()) { 87 appcache_service_->storage()->usage_map()->end()) {
58 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( 88 SendNetworkResponse();
59 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_,
60 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_));
61 return; 89 return;
62 } 90 }
63 91
64 appcache_service_->storage()->FindResponseForMainRequest(request_.url, 92 if (IsResourceTypeFrame(request_.resource_type)) {
65 GURL(), this); 93 handler_ = host->CreateRequestHandler(
94 AppCacheURLLoaderRequest::Create(request_), request_.resource_type,
95 request_.should_reset_appcache);
96
97 AppCacheJob* job = handler_->MaybeLoadResource(nullptr);
98 if (!job) {
99 SendNetworkResponse();
100 return;
101 }
102
103 job_.reset(job->AsURLLoaderJob());
104 job_->set_delegate(this);
105 } else {
106 // We should not be hitting this yet. We have to plumb the AppCache
107 // response through to the renderer before we receive requests for sub
108 // resources.
109 DCHECK(false);
110 }
111 }
112
113 // Binds the client end point with this instance.
114 void BindEndpoints(const ResourceRequest& request,
115 mojom::URLLoaderRequest url_loader_request,
116 int32_t routing_id,
117 int32_t request_id,
118 mojom::URLLoaderClientPtrInfo client_info) {
119 request_ = request;
120
121 binding_.reset(new mojo::Binding<mojom::URLLoader>(
122 this, std::move(url_loader_request)));
123 binding_->set_connection_error_handler(base::Bind(
124 &AppCacheURLLoader::OnConnectionError, base::Unretained(this)));
125
126 routing_id_ = routing_id;
127 request_id_ = request_id;
128
129 client_info_.Bind(std::move(client_info));
130
131 // We pass the cached AppCache response and the data to the client for
132 // navigation requests.
133 if (navigation_request_) {
134 DCHECK(cached_response_info_.get());
135 HandleAppCacheResponseInternal(cached_response_info_.get());
136 cached_response_info_ = nullptr;
137
138 if (cached_buffer_.get()) {
139 HandleAppCacheDataInternal(cached_buffer_.get(), cached_buffer_size_,
140 buffer_read_callback_);
141 cached_buffer_ = nullptr;
142 cached_buffer_size_ = 0;
143 }
144 }
66 } 145 }
67 146
68 // mojom::URLLoader implementation: 147 // mojom::URLLoader implementation:
69 void FollowRedirect() override { network_loader_request_->FollowRedirect(); } 148 void FollowRedirect() override { network_loader_request_->FollowRedirect(); }
70 149
71 void SetPriority(net::RequestPriority priority, 150 void SetPriority(net::RequestPriority priority,
72 int32_t intra_priority_value) override { 151 int32_t intra_priority_value) override {
73 DCHECK(false); 152 DCHECK(false);
74 } 153 }
75 154
76 private: 155 // AppCacheURLLoaderJob::Delegate overrides.
77 // AppCacheStorage::Delegate methods. 156 void SendNetworkResponse() override {
78 void OnMainResponseFound(const GURL& url, 157 // For a navigation request we invoke the LoaderFactoryCallback with null to
79 const AppCacheEntry& entry, 158 // ensure that the next handler gets a stab at the request.
80 const GURL& fallback_url, 159 if (navigation_request_) {
81 const AppCacheEntry& fallback_entry, 160 std::move(callback_).Run(nullptr);
82 int64_t cache_id, 161 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
83 int64_t group_id,
84 const GURL& manifest_url) override {
85 AppCachePolicy* policy = appcache_service_->appcache_policy();
86 bool was_blocked_by_policy =
87 !manifest_url.is_empty() && policy &&
88 !policy->CanLoadAppCache(manifest_url,
89 request_.first_party_for_cookies);
90
91 if (was_blocked_by_policy || !entry.has_response_id() ||
92 cache_id == kAppCacheNoCacheId) {
93 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart(
94 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_,
95 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_));
96 } else { 162 } else {
97 DLOG(WARNING) << "AppCache found for url " << url
98 << " Returning AppCache factory\n";
99 // TODO(ananta) 163 // TODO(ananta)
100 // Provide the plumbing to initiate AppCache requests here. 164 // We probably need to chain to the next factory instead of always
165 // passing the request to the network factory. This code path will
166 // only execute for subresources.
101 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart( 167 factory_getter_->GetNetworkFactory()->get()->CreateLoaderAndStart(
102 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_, 168 mojo::MakeRequest(&network_loader_request_), routing_id_, request_id_,
103 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_)); 169 mojom::kURLLoadOptionSendSSLInfo, request_, std::move(client_info_));
104 } 170 }
105 } 171 }
106 172
173 void SendErrorResponse() override {
174 // TODO(ananta)
175 // We need to mimic the current URLRequestJob behavior here.
176 DLOG(WARNING) << "Sending error response for URL: " << request_.url;
177 }
178
179 void HandleAppCacheResponseStart(AppCacheResponseInfo* response_info)
180 override {
181 DCHECK(response_info);
182 DCHECK(response_info->http_response_info());
183
184 // For a navigation request, we create an instance of the
185 // AppCacheURLLoaderFactory class which implements the URLLoaderFactory
186 // interface and pass it to the LoaderFactoryCallback.
187 if (navigation_request_) {
188 // Cache the response here to be passed to the client when it connects to
189 // us.
190 cached_response_info_ = response_info;
191 mojom::URLLoaderFactoryPtr appcache_factory;
192 AppCacheURLLoaderFactory::CreateURLLoaderFactory(
193 mojo::MakeRequest(&appcache_factory), appcache_service_.get(),
194 factory_getter_.get(), this, 0);
195 std::move(callback_).Run(appcache_factory.get());
196 return;
197 }
198
199 HandleAppCacheResponseInternal(response_info);
200 }
201
202 void HandleAppCacheData(
203 net::IOBuffer* buffer,
204 int buffer_size,
205 AppCacheURLLoaderJob::BufferReadCallback callback) override {
206 DLOG(WARNING) << "Received AppCache data for URL: " << request_.url;
207
208 // Cache the buffer and the size. We will use it later when the client
209 // connects to us via URLLoaderFactory::CreateLoaderAndStart().
210
211 // If the cached AppCacheResponseInfo member is null, it means that the
212 // client has already connected to us. It is safe to forward the buffer
213 // directly to the client.
214 if (navigation_request_ && cached_response_info_.get()) {
215 cached_buffer_ = buffer;
216 cached_buffer_size_ = buffer_size;
217 buffer_read_callback_ = callback;
218 return;
219 }
220
221 HandleAppCacheDataInternal(buffer, buffer_size, callback);
222 }
223
224 void HandleAppCacheDataCompleted() override {
225 client_info_->OnComplete(ResourceRequestCompletionStatus());
226 }
227
228 private:
229 // This ctor is used for checking if navigation requests can be served from
230 // the AppCache.
231 AppCacheURLLoader(const ResourceRequest& request,
232 ChromeAppCacheService* appcache_service,
233 LoaderFactoryCallback callback,
234 URLLoaderFactoryGetter* factory_getter)
235 : appcache_service_(appcache_service),
236 factory_getter_(factory_getter),
237 request_(request),
238 routing_id_(-1),
239 request_id_(-1),
240 callback_(std::move(callback)),
241 cached_buffer_size_(0),
242 navigation_request_(true) {}
243
244 // This ctor is used for handling URL load requests.
245 AppCacheURLLoader(const ResourceRequest& request,
246 mojom::URLLoaderRequest url_loader_request,
247 int32_t routing_id,
248 int32_t request_id,
249 mojom::URLLoaderClientPtr client_info,
250 ChromeAppCacheService* appcache_service,
251 URLLoaderFactoryGetter* factory_getter)
252 : appcache_service_(appcache_service),
253 factory_getter_(factory_getter),
254 cached_buffer_size_(0),
255 navigation_request_(false) {
256 BindEndpoints(request, std::move(url_loader_request), routing_id,
257 request_id, client_info.PassInterface());
258 }
259
107 void OnConnectionError() { delete this; } 260 void OnConnectionError() { delete this; }
108 261
262 void HandleAppCacheResponseInternal(AppCacheResponseInfo* response_info) {
263 DLOG(WARNING) << "Received AppCache response for URL: " << request_.url;
264
265 const net::HttpResponseInfo* http_info =
266 response_info->http_response_info();
267
268 ResourceResponseHead response_head;
269 response_head.headers = new net::HttpResponseHeaders("");
270
271 std::string name;
272 std::string value;
273
274 for (size_t it = 0;
275 http_info->headers->EnumerateHeaderLines(&it, &name, &value);) {
276 response_head.headers->AddHeader(name + ": " + value);
277 }
278
279 // TODO(ananta)
280 // Copy more fields.
281 http_info->headers->GetMimeType(&response_head.mime_type);
282 http_info->headers->GetCharset(&response_head.charset);
283
284 response_head.request_time = http_info->request_time;
285 response_head.response_time = http_info->response_time;
286 response_head.content_length = response_info->response_data_size();
287
288 client_info_->OnReceiveResponse(response_head, http_info->ssl_info,
289 mojom::DownloadedTempFilePtr());
290 }
291
292 void HandleAppCacheDataInternal(
293 net::IOBuffer* buffer,
294 int buffer_size,
295 AppCacheURLLoaderJob::BufferReadCallback callback) {
296 uint32_t bytes_written = static_cast<uint32_t>(buffer_size);
297 mojo::WriteDataRaw(data_pipe_.producer_handle.get(), buffer->data(),
michaeln 2017/06/02 23:47:27 fyi: jam's CL for the BlobURLLoader looks very ins
ananta 2017/06/03 01:55:56 Thanks for the tip. I will look into that in the u
298 &bytes_written, MOJO_WRITE_DATA_FLAG_NONE);
299 client_info_->OnStartLoadingResponseBody(
300 std::move(data_pipe_.consumer_handle));
301 callback.Run();
302 }
303
304 // Used to query AppCacheStorage to see if a request can be served out of the
305 /// AppCache.
306 scoped_refptr<ChromeAppCacheService> appcache_service_;
307
308 // Used to retrieve the network service factory to pass requests to the
309 // network service.
310 scoped_refptr<URLLoaderFactoryGetter> factory_getter_;
311
109 // The current request. 312 // The current request.
110 ResourceRequest request_; 313 ResourceRequest request_;
111 314
112 // URLLoader proxy for the network service. 315 // URLLoader proxy for the network service.
113 mojom::URLLoaderPtr network_loader_request_; 316 mojom::URLLoaderPtr network_loader_request_;
114 317
115 // Routing id of the request. This is 0 for navigation requests. For 318 // Routing id of the request. This is 0 for navigation requests. For
116 // subresource requests it is non zero. 319 // subresource requests it is non zero.
117 int routing_id_; 320 int routing_id_;
118 321
119 // Request id. 322 // Request id.
120 int request_id_; 323 int request_id_;
121 324
122 // The URLLoaderClient pointer. We call this interface with notifications 325 // The URLLoaderClient pointer. We call this interface with notifications
123 // about the URL load 326 // about the URL load
124 mojom::URLLoaderClientPtr client_info_; 327 mojom::URLLoaderClientPtr client_info_;
125 328
126 // Used to query AppCacheStorage to see if a request can be served out of the 329 // Binds the URLLoaderClient with us.
127 /// AppCache. 330 std::unique_ptr<mojo::Binding<mojom::URLLoader>> binding_;
128 scoped_refptr<ChromeAppCacheService> appcache_service_;
129 331
332 // The handler for the AppCache request.
333 std::unique_ptr<AppCacheRequestHandler> handler_;
334
335 // The job which gets invoked by the handler to deliver the responses to the
336 // client.
337 std::unique_ptr<AppCacheURLLoaderJob> job_;
338
339 // The data pipe used to transfer AppCache data to the client.
340 mojo::DataPipe data_pipe_;
341
342 // Callback to be invoked with the AppCache factory or null to fall through
343 // to the next handler in the chain.
344 LoaderFactoryCallback callback_;
345
346 // Cached AppCache response to be used later when we are initialized with
347 // the connection end point.
348 scoped_refptr<AppCacheResponseInfo> cached_response_info_;
349
350 // Cached IOBuffer to be used later when we are initialized with the
351 // connection end point.
352 scoped_refptr<net::IOBuffer> cached_buffer_;
353
354 // Cached buffer size to be used later when we are initialized with the
355 // connection end point.
356 int cached_buffer_size_;
357
358 // Set to true for navigation requests.
359 bool navigation_request_;
360
361 // Callback to be invoked when we finished reading the buffer.
362 AppCacheURLLoaderJob::BufferReadCallback buffer_read_callback_;
363
364 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader);
365 };
366
367 // This class is instantiated for navigation requests. It initiates checks on
368 // whether the request can be serviced via the AppCache.
369 // It uses the AppCacheURLLoader class defined above for this. If the request
370 // cannot be serviced via AppCache, the AppCacheURLLoader class calls
371 // the LoaderFactoryCallback with a null factory which ensures that the request
372 // goes to the next handler in the chain.
373 // If the request can be serviced with AppCache the AppCacheURLLoader class
374 // creates an instance of the AppCacheURLLoaderFactory class and passes it to
375 // the LoaderFactoryCallback function.
376 class AppCacheNavigationRequestHandler : public URLLoaderRequestHandler {
377 public:
378 AppCacheNavigationRequestHandler(
379 AppCacheNavigationHandleCore* appcache_handle_core,
380 URLLoaderFactoryGetter* url_loader_factory_getter)
381 : appcache_core_(appcache_handle_core),
382 factory_getter_(url_loader_factory_getter) {}
383
384 void MaybeCreateLoaderFactory(const ResourceRequest& resource_request,
385 ResourceContext* resource_context,
386 LoaderFactoryCallback callback) override {
387 // The AppCacheURLLoader instance will be deleted when the URL load request
388 // completes. It can complete in the following ways:
389 // 1. The request is serviced via AppCache. In this case it is deleted when
390 // the connection is dropped by the client.
391 // 2. The request is serviced by the next handler.
392 AppCacheURLLoader* loader = AppCacheURLLoader::CreateForNavigationRequest(
393 resource_request, appcache_core_->GetAppCacheService(),
394 std::move(callback), factory_getter_.get());
395 loader->Start(appcache_core_->host());
396 }
397
398 private:
399 AppCacheNavigationHandleCore* appcache_core_;
130 // Used to retrieve the network service factory to pass requests to the 400 // Used to retrieve the network service factory to pass requests to the
131 // network service. 401 // network service.
132 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; 402 scoped_refptr<URLLoaderFactoryGetter> factory_getter_;
133 403
134 // Binds the URLLoaderClient with us. 404 DISALLOW_COPY_AND_ASSIGN(AppCacheNavigationRequestHandler);
135 mojo::Binding<mojom::URLLoader> binding_;
136
137 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoader);
138 }; 405 };
139 406
140 } // namespace
141
142 // Implements the URLLoaderFactory mojom for AppCache requests. 407 // Implements the URLLoaderFactory mojom for AppCache requests.
143 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory( 408 AppCacheURLLoaderFactory::AppCacheURLLoaderFactory(
144 ChromeAppCacheService* appcache_service, 409 ChromeAppCacheService* appcache_service,
145 URLLoaderFactoryGetter* factory_getter) 410 URLLoaderFactoryGetter* factory_getter,
146 : appcache_service_(appcache_service), factory_getter_(factory_getter) {} 411 AppCacheURLLoader* navigation_url_loader,
412 int process_id)
413 : appcache_service_(appcache_service),
414 factory_getter_(factory_getter),
415 navigation_url_loader_(navigation_url_loader),
416 process_id_(process_id) {}
147 417
148 AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {} 418 AppCacheURLLoaderFactory::~AppCacheURLLoaderFactory() {}
149 419
150 // static 420 // static
151 void AppCacheURLLoaderFactory::CreateURLLoaderFactory( 421 void AppCacheURLLoaderFactory::CreateURLLoaderFactory(
152 mojom::URLLoaderFactoryRequest request, 422 mojom::URLLoaderFactoryRequest request,
153 ChromeAppCacheService* appcache_service, 423 ChromeAppCacheService* appcache_service,
154 URLLoaderFactoryGetter* factory_getter) { 424 URLLoaderFactoryGetter* factory_getter,
425 AppCacheURLLoader* navigation_url_loader,
426 int process_id) {
155 std::unique_ptr<AppCacheURLLoaderFactory> factory_instance( 427 std::unique_ptr<AppCacheURLLoaderFactory> factory_instance(
156 new AppCacheURLLoaderFactory(appcache_service, factory_getter)); 428 new AppCacheURLLoaderFactory(appcache_service, factory_getter,
429 navigation_url_loader, process_id));
157 AppCacheURLLoaderFactory* raw_factory = factory_instance.get(); 430 AppCacheURLLoaderFactory* raw_factory = factory_instance.get();
158 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance), 431 raw_factory->loader_factory_bindings_.AddBinding(std::move(factory_instance),
159 std::move(request)); 432 std::move(request));
160 } 433 }
161 434
435 // static
436 std::unique_ptr<URLLoaderRequestHandler>
437 AppCacheURLLoaderFactory::CreateRequestHandler(
438 AppCacheNavigationHandleCore* appcache_handle_core,
439 URLLoaderFactoryGetter* url_loader_factory_getter) {
440 std::unique_ptr<URLLoaderRequestHandler> handler(
441 new AppCacheNavigationRequestHandler(appcache_handle_core,
442 url_loader_factory_getter));
443 return handler;
444 }
445
162 void AppCacheURLLoaderFactory::CreateLoaderAndStart( 446 void AppCacheURLLoaderFactory::CreateLoaderAndStart(
163 mojom::URLLoaderRequest url_loader_request, 447 mojom::URLLoaderRequest url_loader_request,
164 int32_t routing_id, 448 int32_t routing_id,
165 int32_t request_id, 449 int32_t request_id,
166 uint32_t options, 450 uint32_t options,
167 const ResourceRequest& request, 451 const ResourceRequest& request,
168 mojom::URLLoaderClientPtr client) { 452 mojom::URLLoaderClientPtr client) {
169 DCHECK_CURRENTLY_ON(BrowserThread::IO); 453 DCHECK_CURRENTLY_ON(BrowserThread::IO);
170 454
455 AppCacheHost* host = nullptr;
456 // If we have an ongoing navigation, bind the endpoints here.
457 if (navigation_url_loader_) {
458 navigation_url_loader_->BindEndpoints(
459 request, std::move(url_loader_request), routing_id, request_id,
460 client.PassInterface());
461 return;
462 } else {
463 AppCacheBackendImpl* backend = appcache_service_->GetBackend(process_id_);
464 DCHECK(backend);
465 host = backend->GetHost(request.appcache_host_id);
466 DCHECK(host);
467 }
468
171 // This will get deleted when the connection is dropped by the client. 469 // This will get deleted when the connection is dropped by the client.
172 AppCacheURLLoader* loader = new AppCacheURLLoader( 470 AppCacheURLLoader* loader = AppCacheURLLoader::CreateForURLLoads(
173 request, std::move(url_loader_request), routing_id, request_id, 471 request, std::move(url_loader_request), routing_id, request_id,
174 std::move(client), appcache_service_.get(), factory_getter_.get()); 472 std::move(client), appcache_service_.get(), factory_getter_.get());
175 loader->Start(); 473 loader->Start(host);
176 } 474 }
177 475
178 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id, 476 void AppCacheURLLoaderFactory::SyncLoad(int32_t routing_id,
179 int32_t request_id, 477 int32_t request_id,
180 const ResourceRequest& request, 478 const ResourceRequest& request,
181 SyncLoadCallback callback) { 479 SyncLoadCallback callback) {
182 NOTREACHED(); 480 NOTREACHED();
183 } 481 }
184 482
185 } // namespace content 483 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698