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

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: Remove newline 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
kinuko 2017/07/28 09:50:28 nit: extra space
ananta 2017/07/28 22:59:22 Done.
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
kinuko 2017/07/28 09:50:28 ditto
ananta 2017/07/28 22:59:22 Done.
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());
318 job_->DeliverNetworkResponse(); 326 job_->DeliverNetworkResponse();
327
328 // In the network service world, we need to destroy the AppCacheJob instance
329 // created for handling navigation requests.
kinuko 2017/07/28 09:50:28 ditto
ananta 2017/07/28 22:59:22 Done.
330 navigation_request_job_.reset(nullptr);
319 } 331 }
320 332
321 void AppCacheRequestHandler::OnPrepareToRestart() { 333 void AppCacheRequestHandler::OnPrepareToRestart() {
322 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound()); 334 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound());
323 335
324 // Any information about the source of the response is no longer relevant. 336 // Any information about the source of the response is no longer relevant.
325 cache_id_ = kAppCacheNoCacheId; 337 cache_id_ = kAppCacheNoCacheId;
326 manifest_url_ = GURL(); 338 manifest_url_ = GURL();
327 339
328 cache_entry_not_found_ = job_->IsCacheEntryNotFound(); 340 cache_entry_not_found_ = job_->IsCacheEntryNotFound();
(...skipping 18 matching lines...) Expand all
347 loader_job->SetSubresourceLoadInfo( 359 loader_job->SetSubresourceLoadInfo(
348 std::move(subresource_load_info_), 360 std::move(subresource_load_info_),
349 network_url_loader_factory_getter_.get()); 361 network_url_loader_factory_getter_.get());
350 } 362 }
351 363
352 return job; 364 return job;
353 } 365 }
354 366
355 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeCreateJobForFallback( 367 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeCreateJobForFallback(
356 net::NetworkDelegate* network_delegate) { 368 net::NetworkDelegate* network_delegate) {
357 if (!base::FeatureList::IsEnabled(features::kNetworkService)) 369 if (!base::FeatureList::IsEnabled(features::kNetworkService) ||
370 IsMainResourceType(resource_type_)) {
358 return CreateJob(network_delegate); 371 return CreateJob(network_delegate);
372 }
359 // In network service land, the job initiates a fallback request. We reuse 373 // In network service land, the job initiates a fallback request. We reuse
360 // the existing job to deliver the fallback response. 374 // the existing job to deliver the fallback response.
kinuko 2017/07/28 09:50:28 This comment doesn't explain why we have IsMainRes
361 DCHECK(job_.get()); 375 DCHECK(job_.get());
362 return std::unique_ptr<AppCacheJob>(job_.get()); 376 return std::unique_ptr<AppCacheJob>(job_.get());
363 } 377 }
364 378
365 // Main-resource handling ---------------------------------------------- 379 // Main-resource handling ----------------------------------------------
366 380
367 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( 381 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource(
368 net::NetworkDelegate* network_delegate) { 382 net::NetworkDelegate* network_delegate) {
369 DCHECK(!job_.get()); 383 DCHECK(!job_.get());
370 DCHECK(host_); 384 DCHECK(host_);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 const ResourceRequest& resource_request, 587 const ResourceRequest& resource_request,
574 ResourceContext* resource_context, 588 ResourceContext* resource_context,
575 LoaderCallback callback) { 589 LoaderCallback callback) {
576 // MaybeLoadMainResource will invoke navigation_request_job's methods 590 // MaybeLoadMainResource will invoke navigation_request_job's methods
577 // asynchronously via AppCacheStorage::Delegate. 591 // asynchronously via AppCacheStorage::Delegate.
578 navigation_request_job_ = MaybeLoadMainResource(nullptr); 592 navigation_request_job_ = MaybeLoadMainResource(nullptr);
579 if (!navigation_request_job_.get()) { 593 if (!navigation_request_job_.get()) {
580 std::move(callback).Run(StartLoaderCallback()); 594 std::move(callback).Run(StartLoaderCallback());
581 return; 595 return;
582 } 596 }
597 // The AppCacheJob for the navigation request will get destroyed when the
598 // client connection is dropped.
michaeln 2017/07/28 19:11:02 the lifetime is explained well enough in other com
ananta 2017/07/28 22:59:22 Thanks. Removed
583 navigation_request_job_->AsURLLoaderJob()->set_main_resource_loader_callback( 599 navigation_request_job_->AsURLLoaderJob()->set_main_resource_loader_callback(
584 std::move(callback)); 600 std::move(callback));
585 } 601 }
586 602
587 mojom::URLLoaderFactoryPtr 603 mojom::URLLoaderFactoryPtr
588 AppCacheRequestHandler::MaybeCreateSubresourceFactory() { 604 AppCacheRequestHandler::MaybeCreateSubresourceFactory() {
589 mojom::URLLoaderFactoryPtr factory_ptr = nullptr; 605 mojom::URLLoaderFactoryPtr factory_ptr = nullptr;
590 606
591 // The factory is destroyed when the renderer drops the connection. 607 // The factory is destroyed when the renderer drops the connection.
592 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( 608 AppCacheSubresourceURLFactory::CreateURLLoaderFactory(
593 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); 609 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr);
594 610
595 return factory_ptr; 611 return factory_ptr;
596 } 612 }
597 613
614 bool AppCacheRequestHandler::MaybeCreateLoaderForResponse(
615 const ResourceResponseHead& response,
616 mojom::URLLoaderPtr* loader,
617 mojom::URLLoaderClientRequest* client_request) {
618 request_->AsURLLoaderRequest()->set_response(response);
619 // The AppCacheJob will get destroyed when the client connection is
620 // dropped.
621 AppCacheJob* job = MaybeLoadFallbackForResponse(nullptr);
622 if (job) {
623 mojom::URLLoaderClientPtr client;
624 *client_request = mojo::MakeRequest(&client);
625 mojom::URLLoaderRequest loader_request = mojo::MakeRequest(loader);
626
627 job->AsURLLoaderJob()->BindRequest(std::move(client),
628 std::move(loader_request));
629 return true;
630 }
631 return false;
632 }
633
598 } // namespace content 634 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698