| OLD | NEW |
| 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 Loading... |
| 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()); |
| 318 job_->DeliverNetworkResponse(); | 326 job_->DeliverNetworkResponse(); |
| 327 // In the network service world, we need to destroy the AppCacheJob instance |
| 328 // created for handling navigation requests. |
| 329 navigation_request_job_.reset(nullptr); |
| 319 } | 330 } |
| 320 | 331 |
| 321 void AppCacheRequestHandler::OnPrepareToRestart() { | 332 void AppCacheRequestHandler::OnPrepareToRestart() { |
| 322 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound()); | 333 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound()); |
| 323 | 334 |
| 324 // Any information about the source of the response is no longer relevant. | 335 // Any information about the source of the response is no longer relevant. |
| 325 cache_id_ = kAppCacheNoCacheId; | 336 cache_id_ = kAppCacheNoCacheId; |
| 326 manifest_url_ = GURL(); | 337 manifest_url_ = GURL(); |
| 327 | 338 |
| 328 cache_entry_not_found_ = job_->IsCacheEntryNotFound(); | 339 cache_entry_not_found_ = job_->IsCacheEntryNotFound(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 347 loader_job->SetSubresourceLoadInfo( | 358 loader_job->SetSubresourceLoadInfo( |
| 348 std::move(subresource_load_info_), | 359 std::move(subresource_load_info_), |
| 349 network_url_loader_factory_getter_.get()); | 360 network_url_loader_factory_getter_.get()); |
| 350 } | 361 } |
| 351 | 362 |
| 352 return job; | 363 return job; |
| 353 } | 364 } |
| 354 | 365 |
| 355 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeCreateJobForFallback( | 366 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeCreateJobForFallback( |
| 356 net::NetworkDelegate* network_delegate) { | 367 net::NetworkDelegate* network_delegate) { |
| 357 if (!base::FeatureList::IsEnabled(features::kNetworkService)) | 368 if (!base::FeatureList::IsEnabled(features::kNetworkService) || |
| 369 IsMainResourceType(resource_type_)) { |
| 358 return CreateJob(network_delegate); | 370 return CreateJob(network_delegate); |
| 371 } |
| 359 // In network service land, the job initiates a fallback request. We reuse | 372 // In network service land, the job initiates a fallback request. We reuse |
| 360 // the existing job to deliver the fallback response. | 373 // the existing job to deliver the fallback response. |
| 361 DCHECK(job_.get()); | 374 DCHECK(job_.get()); |
| 362 return std::unique_ptr<AppCacheJob>(job_.get()); | 375 return std::unique_ptr<AppCacheJob>(job_.get()); |
| 363 } | 376 } |
| 364 | 377 |
| 365 // Main-resource handling ---------------------------------------------- | 378 // Main-resource handling ---------------------------------------------- |
| 366 | 379 |
| 367 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( | 380 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( |
| 368 net::NetworkDelegate* network_delegate) { | 381 net::NetworkDelegate* network_delegate) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 AppCacheRequestHandler::MaybeCreateSubresourceFactory() { | 601 AppCacheRequestHandler::MaybeCreateSubresourceFactory() { |
| 589 mojom::URLLoaderFactoryPtr factory_ptr = nullptr; | 602 mojom::URLLoaderFactoryPtr factory_ptr = nullptr; |
| 590 | 603 |
| 591 // The factory is destroyed when the renderer drops the connection. | 604 // The factory is destroyed when the renderer drops the connection. |
| 592 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( | 605 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( |
| 593 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); | 606 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); |
| 594 | 607 |
| 595 return factory_ptr; | 608 return factory_ptr; |
| 596 } | 609 } |
| 597 | 610 |
| 611 bool AppCacheRequestHandler::MaybeCreateLoaderForResponse( |
| 612 const ResourceResponseHead& response, |
| 613 mojom::URLLoaderPtr* loader, |
| 614 mojom::URLLoaderClientRequest* client_request) { |
| 615 request_->AsURLLoaderRequest()->set_response(response); |
| 616 // The AppCacheJob will get destroyed when the client connection is |
| 617 // dropped. |
| 618 AppCacheJob* job = MaybeLoadFallbackForResponse(nullptr); |
| 619 if (job) { |
| 620 mojom::URLLoaderClientPtr client; |
| 621 *client_request = mojo::MakeRequest(&client); |
| 622 mojom::URLLoaderRequest loader_request = mojo::MakeRequest(loader); |
| 623 |
| 624 job->AsURLLoaderJob()->BindRequest(std::move(client), |
| 625 std::move(loader_request)); |
| 626 return true; |
| 627 } |
| 628 return false; |
| 629 } |
| 630 |
| 598 } // namespace content | 631 } // namespace content |
| OLD | NEW |