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

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

Issue 2982363002: Add support for fallback content for the frame. This includes main and subframes. (Closed)
Patch Set: Changed the MaybeCreateLoaderForResponse function to return the URLLoaderPtr and URLLoaderClientReq… Created 3 years, 4 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_request_handler.h" 5 #include "content/browser/appcache/appcache_request_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 DCHECK(entry.has_response_id()); 295 DCHECK(entry.has_response_id());
296 296
297 // Cache information about the response, for use by GetExtraResponseInfo. 297 // Cache information about the response, for use by GetExtraResponseInfo.
298 cache_id_ = cache_id; 298 cache_id_ = cache_id;
299 manifest_url_ = manifest_url; 299 manifest_url_ = manifest_url;
300 300
301 if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty()) 301 if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty())
302 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); 302 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url);
303 303
304 job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback); 304 job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback);
305 // In the network service world, we need to release the AppCacheJob instance
306 // created for handling navigation requests. These instances will get
307 // destroyed when the client disconnects.
308 navigation_request_job_.release();
305 } 309 }
306 310
307 void AppCacheRequestHandler::DeliverErrorResponse() { 311 void AppCacheRequestHandler::DeliverErrorResponse() {
308 DCHECK(job_.get() && job_->IsWaiting()); 312 DCHECK(job_.get() && job_->IsWaiting());
309 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); 313 DCHECK_EQ(kAppCacheNoCacheId, cache_id_);
310 DCHECK(manifest_url_.is_empty()); 314 DCHECK(manifest_url_.is_empty());
311 job_->DeliverErrorResponse(); 315 job_->DeliverErrorResponse();
316 // In the network service world, we need to release the AppCacheJob instance
317 // created for handling navigation requests. These instances will get
318 // destroyed when the client disconnects.
319 navigation_request_job_.release();
312 } 320 }
313 321
314 void AppCacheRequestHandler::DeliverNetworkResponse() { 322 void AppCacheRequestHandler::DeliverNetworkResponse() {
315 DCHECK(job_.get() && job_->IsWaiting()); 323 DCHECK(job_.get() && job_->IsWaiting());
316 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); 324 DCHECK_EQ(kAppCacheNoCacheId, cache_id_);
317 DCHECK(manifest_url_.is_empty()); 325 DCHECK(manifest_url_.is_empty());
326
318 job_->DeliverNetworkResponse(); 327 job_->DeliverNetworkResponse();
328
329 // In the network service world, we need to destroy the AppCacheJob instance
330 // created for handling navigation requests.
331 navigation_request_job_.reset(nullptr);
319 } 332 }
320 333
321 void AppCacheRequestHandler::OnPrepareToRestart() { 334 void AppCacheRequestHandler::OnPrepareToRestart() {
322 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound()); 335 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound());
323 336
324 // Any information about the source of the response is no longer relevant. 337 // Any information about the source of the response is no longer relevant.
325 cache_id_ = kAppCacheNoCacheId; 338 cache_id_ = kAppCacheNoCacheId;
326 manifest_url_ = GURL(); 339 manifest_url_ = GURL();
327 340
328 cache_entry_not_found_ = job_->IsCacheEntryNotFound(); 341 cache_entry_not_found_ = job_->IsCacheEntryNotFound();
(...skipping 18 matching lines...) Expand all
347 loader_job->SetSubresourceLoadInfo( 360 loader_job->SetSubresourceLoadInfo(
348 std::move(subresource_load_info_), 361 std::move(subresource_load_info_),
349 network_url_loader_factory_getter_.get()); 362 network_url_loader_factory_getter_.get());
350 } 363 }
351 364
352 return job; 365 return job;
353 } 366 }
354 367
355 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeCreateJobForFallback( 368 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeCreateJobForFallback(
356 net::NetworkDelegate* network_delegate) { 369 net::NetworkDelegate* network_delegate) {
357 if (!base::FeatureList::IsEnabled(features::kNetworkService)) 370 if (!base::FeatureList::IsEnabled(features::kNetworkService) ||
371 IsMainResourceType(resource_type_)) {
358 return CreateJob(network_delegate); 372 return CreateJob(network_delegate);
373 }
359 // In network service land, the job initiates a fallback request. We reuse 374 // In network service land, the job initiates a fallback request. We reuse
360 // the existing job to deliver the fallback response. 375 // the existing job to deliver the fallback response.
361 DCHECK(job_.get()); 376 DCHECK(job_.get());
362 return std::unique_ptr<AppCacheJob>(job_.get()); 377 return std::unique_ptr<AppCacheJob>(job_.get());
363 } 378 }
364 379
365 // Main-resource handling ---------------------------------------------- 380 // Main-resource handling ----------------------------------------------
366 381
367 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( 382 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource(
368 net::NetworkDelegate* network_delegate) { 383 net::NetworkDelegate* network_delegate) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 const ResourceRequest& resource_request, 588 const ResourceRequest& resource_request,
574 ResourceContext* resource_context, 589 ResourceContext* resource_context,
575 LoaderCallback callback) { 590 LoaderCallback callback) {
576 // MaybeLoadMainResource will invoke navigation_request_job's methods 591 // MaybeLoadMainResource will invoke navigation_request_job's methods
577 // asynchronously via AppCacheStorage::Delegate. 592 // asynchronously via AppCacheStorage::Delegate.
578 navigation_request_job_ = MaybeLoadMainResource(nullptr); 593 navigation_request_job_ = MaybeLoadMainResource(nullptr);
579 if (!navigation_request_job_.get()) { 594 if (!navigation_request_job_.get()) {
580 std::move(callback).Run(StartLoaderCallback()); 595 std::move(callback).Run(StartLoaderCallback());
581 return; 596 return;
582 } 597 }
598 // The AppCacheJob for the navigation request will get destroyed when the
599 // client connection is dropped.
583 navigation_request_job_->AsURLLoaderJob()->set_main_resource_loader_callback( 600 navigation_request_job_->AsURLLoaderJob()->set_main_resource_loader_callback(
584 std::move(callback)); 601 std::move(callback));
585 } 602 }
586 603
587 mojom::URLLoaderFactoryPtr 604 mojom::URLLoaderFactoryPtr
588 AppCacheRequestHandler::MaybeCreateSubresourceFactory() { 605 AppCacheRequestHandler::MaybeCreateSubresourceFactory() {
589 mojom::URLLoaderFactoryPtr factory_ptr = nullptr; 606 mojom::URLLoaderFactoryPtr factory_ptr = nullptr;
590 607
591 // The factory is destroyed when the renderer drops the connection. 608 // The factory is destroyed when the renderer drops the connection.
592 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( 609 AppCacheSubresourceURLFactory::CreateURLLoaderFactory(
593 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); 610 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr);
594 611
595 return factory_ptr; 612 return factory_ptr;
596 } 613 }
597 614
615 bool AppCacheRequestHandler::MaybeCreateLoaderForResponse(
616 const ResourceResponseHead& response,
617 mojom::URLLoaderPtr* loader,
618 mojom::URLLoaderClientRequest* client_request) {
619 request_->AsURLLoaderRequest()->set_response(response);
620 // The AppCacheJob will get destroyed when the client connection is
621 // dropped.
622 AppCacheJob* job = MaybeLoadFallbackForResponse(nullptr);
623 if (job) {
624 mojom::URLLoaderClientPtr client;
625 *client_request = mojo::MakeRequest(&client);
626 mojom::URLLoaderRequest loader_request = mojo::MakeRequest(loader);
627
628 job->AsURLLoaderJob()->BindRequest(std::move(client),
629 std::move(loader_request));
630 return true;
631 }
632 return false;
633 }
634
598 } // namespace content 635 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698