| 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 "content/browser/appcache/appcache.h" | 11 #include "content/browser/appcache/appcache.h" |
| 11 #include "content/browser/appcache/appcache_backend_impl.h" | 12 #include "content/browser/appcache/appcache_backend_impl.h" |
| 12 #include "content/browser/appcache/appcache_host.h" | 13 #include "content/browser/appcache/appcache_host.h" |
| 13 #include "content/browser/appcache/appcache_navigation_handle_core.h" | 14 #include "content/browser/appcache/appcache_navigation_handle_core.h" |
| 14 #include "content/browser/appcache/appcache_policy.h" | 15 #include "content/browser/appcache/appcache_policy.h" |
| 15 #include "content/browser/appcache/appcache_request.h" | 16 #include "content/browser/appcache/appcache_request.h" |
| 16 #include "content/browser/appcache/appcache_subresource_url_factory.h" | 17 #include "content/browser/appcache/appcache_subresource_url_factory.h" |
| 17 #include "content/browser/appcache/appcache_url_loader_job.h" | 18 #include "content/browser/appcache/appcache_url_loader_job.h" |
| 18 #include "content/browser/appcache/appcache_url_loader_request.h" | 19 #include "content/browser/appcache/appcache_url_loader_request.h" |
| 19 #include "content/browser/appcache/appcache_url_request_job.h" | 20 #include "content/browser/appcache/appcache_url_request_job.h" |
| 20 #include "content/browser/service_worker/service_worker_request_handler.h" | 21 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 22 #include "content/public/common/content_features.h" |
| 21 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
| 22 #include "net/url_request/url_request_job.h" | 24 #include "net/url_request/url_request_job.h" |
| 23 | 25 |
| 24 namespace content { | 26 namespace content { |
| 25 | 27 |
| 26 AppCacheRequestHandler::AppCacheRequestHandler( | 28 AppCacheRequestHandler::AppCacheRequestHandler( |
| 27 AppCacheHost* host, | 29 AppCacheHost* host, |
| 28 ResourceType resource_type, | 30 ResourceType resource_type, |
| 29 bool should_reset_appcache, | 31 bool should_reset_appcache, |
| 30 std::unique_ptr<AppCacheRequest> request) | 32 std::unique_ptr<AppCacheRequest> request) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 96 |
| 95 std::unique_ptr<AppCacheJob> job; | 97 std::unique_ptr<AppCacheJob> job; |
| 96 if (is_main_resource()) | 98 if (is_main_resource()) |
| 97 job = MaybeLoadMainResource(network_delegate); | 99 job = MaybeLoadMainResource(network_delegate); |
| 98 else | 100 else |
| 99 job = MaybeLoadSubResource(network_delegate); | 101 job = MaybeLoadSubResource(network_delegate); |
| 100 | 102 |
| 101 // If its been setup to deliver a network response, we can just delete | 103 // If its been setup to deliver a network response, we can just delete |
| 102 // it now and return NULL instead to achieve that since it couldn't | 104 // it now and return NULL instead to achieve that since it couldn't |
| 103 // have been started yet. | 105 // have been started yet. |
| 104 if (job && job->IsDeliveringNetworkResponse()) { | 106 if (job && job->IsDeliveringNetworkResponse() && !job->AsURLLoaderJob()) { |
| 105 DCHECK(!job->IsStarted()); | 107 DCHECK(!job->IsStarted()); |
| 106 job.reset(); | 108 job.reset(); |
| 107 } | 109 } |
| 108 | 110 |
| 109 return job.release(); | 111 return job.release(); |
| 110 } | 112 } |
| 111 | 113 |
| 112 AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( | 114 AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( |
| 113 net::NetworkDelegate* network_delegate, | 115 net::NetworkDelegate* network_delegate, |
| 114 const GURL& location) { | 116 const GURL& location) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // static | 233 // static |
| 232 std::unique_ptr<AppCacheRequestHandler> | 234 std::unique_ptr<AppCacheRequestHandler> |
| 233 AppCacheRequestHandler::InitializeForNavigationNetworkService( | 235 AppCacheRequestHandler::InitializeForNavigationNetworkService( |
| 234 const ResourceRequest& request, | 236 const ResourceRequest& request, |
| 235 AppCacheNavigationHandleCore* appcache_handle_core, | 237 AppCacheNavigationHandleCore* appcache_handle_core, |
| 236 URLLoaderFactoryGetter* url_loader_factory_getter) { | 238 URLLoaderFactoryGetter* url_loader_factory_getter) { |
| 237 std::unique_ptr<AppCacheRequestHandler> handler = | 239 std::unique_ptr<AppCacheRequestHandler> handler = |
| 238 appcache_handle_core->host()->CreateRequestHandler( | 240 appcache_handle_core->host()->CreateRequestHandler( |
| 239 AppCacheURLLoaderRequest::Create(request), request.resource_type, | 241 AppCacheURLLoaderRequest::Create(request), request.resource_type, |
| 240 request.should_reset_appcache); | 242 request.should_reset_appcache); |
| 241 handler->set_network_url_loader_factory_getter(url_loader_factory_getter); | 243 handler->network_url_loader_factory_getter_ = url_loader_factory_getter; |
| 244 handler->appcache_host_ = appcache_handle_core->host()->GetWeakPtr(); |
| 242 return handler; | 245 return handler; |
| 243 } | 246 } |
| 244 | 247 |
| 248 void AppCacheRequestHandler::SetSubresourceRequestLoadInfo( |
| 249 std::unique_ptr<SubresourceLoadInfo> subresource_load_info) { |
| 250 subresource_load_info_ = std::move(subresource_load_info); |
| 251 } |
| 252 |
| 245 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { | 253 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { |
| 246 storage()->CancelDelegateCallbacks(this); | 254 storage()->CancelDelegateCallbacks(this); |
| 247 host_ = NULL; // no need to RemoveObserver, the host is being deleted | 255 host_ = NULL; // no need to RemoveObserver, the host is being deleted |
| 248 | 256 |
| 249 // Since the host is being deleted, we don't have to complete any job | 257 // Since the host is being deleted, we don't have to complete any job |
| 250 // that is current running. It's destined for the bit bucket anyway. | 258 // that is current running. It's destined for the bit bucket anyway. |
| 251 if (job_.get()) { | 259 if (job_.get()) { |
| 252 job_->Kill(); | 260 job_->Kill(); |
| 253 job_.reset(); | 261 job_.reset(); |
| 254 } | 262 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 job_.reset(); | 323 job_.reset(); |
| 316 } | 324 } |
| 317 | 325 |
| 318 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::CreateJob( | 326 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::CreateJob( |
| 319 net::NetworkDelegate* network_delegate) { | 327 net::NetworkDelegate* network_delegate) { |
| 320 std::unique_ptr<AppCacheJob> job = AppCacheJob::Create( | 328 std::unique_ptr<AppCacheJob> job = AppCacheJob::Create( |
| 321 is_main_resource(), host_, storage(), request_.get(), network_delegate, | 329 is_main_resource(), host_, storage(), request_.get(), network_delegate, |
| 322 base::Bind(&AppCacheRequestHandler::OnPrepareToRestart, | 330 base::Bind(&AppCacheRequestHandler::OnPrepareToRestart, |
| 323 base::Unretained(this))); | 331 base::Unretained(this))); |
| 324 job_ = job->GetWeakPtr(); | 332 job_ = job->GetWeakPtr(); |
| 333 if (!is_main_resource() && |
| 334 base::FeatureList::IsEnabled(features::kNetworkService)) { |
| 335 AppCacheURLLoaderJob* loader_job = job_->AsURLLoaderJob(); |
| 336 |
| 337 loader_job->SetSubresourceLoadInfo( |
| 338 std::move(subresource_load_info_), |
| 339 network_url_loader_factory_getter_.get()); |
| 340 } |
| 341 |
| 325 return job; | 342 return job; |
| 326 } | 343 } |
| 327 | 344 |
| 328 // Main-resource handling ---------------------------------------------- | 345 // Main-resource handling ---------------------------------------------- |
| 329 | 346 |
| 330 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( | 347 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( |
| 331 net::NetworkDelegate* network_delegate) { | 348 net::NetworkDelegate* network_delegate) { |
| 332 DCHECK(!job_.get()); | 349 DCHECK(!job_.get()); |
| 333 DCHECK(host_); | 350 DCHECK(host_); |
| 334 | 351 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 const ResourceRequest& resource_request, | 553 const ResourceRequest& resource_request, |
| 537 ResourceContext* resource_context, | 554 ResourceContext* resource_context, |
| 538 LoaderCallback callback) { | 555 LoaderCallback callback) { |
| 539 // MaybeLoadMainResource will invoke navigation_request_job's methods | 556 // MaybeLoadMainResource will invoke navigation_request_job's methods |
| 540 // asynchronously via AppCacheStorage::Delegate. | 557 // asynchronously via AppCacheStorage::Delegate. |
| 541 navigation_request_job_ = MaybeLoadMainResource(nullptr); | 558 navigation_request_job_ = MaybeLoadMainResource(nullptr); |
| 542 if (!navigation_request_job_.get()) { | 559 if (!navigation_request_job_.get()) { |
| 543 std::move(callback).Run(StartLoaderCallback()); | 560 std::move(callback).Run(StartLoaderCallback()); |
| 544 return; | 561 return; |
| 545 } | 562 } |
| 546 navigation_request_job_->AsURLLoaderJob()->set_loader_callback( | 563 navigation_request_job_->AsURLLoaderJob()->set_main_resource_loader_callback( |
| 547 std::move(callback)); | 564 std::move(callback)); |
| 548 } | 565 } |
| 549 | 566 |
| 550 mojom::URLLoaderFactoryPtr | 567 mojom::URLLoaderFactoryPtr |
| 551 AppCacheRequestHandler::MaybeCreateSubresourceFactory() { | 568 AppCacheRequestHandler::MaybeCreateSubresourceFactory() { |
| 552 return AppCacheSubresourceURLFactory::CreateURLLoaderFactory( | 569 mojom::URLLoaderFactoryPtr factory_ptr = nullptr; |
| 553 network_url_loader_factory_getter_.get()); | 570 |
| 571 // The factory is destroyed when the renderer drops the connection. |
| 572 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( |
| 573 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); |
| 574 |
| 575 return factory_ptr; |
| 554 } | 576 } |
| 555 | 577 |
| 556 } // namespace content | 578 } // namespace content |
| OLD | NEW |