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

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

Issue 2956373002: Add support for subresource request loads in AppCache for the network service. (Closed)
Patch Set: Use the precreated AppCacheHost from the AppCacheNavigationHandleCore instance. Created 3 years, 5 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 "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_url_loader_job.h" 17 #include "content/browser/appcache/appcache_url_loader_job.h"
18 #include "content/browser/appcache/appcache_url_loader_request.h" 18 #include "content/browser/appcache/appcache_url_loader_request.h"
19 #include "content/browser/appcache/appcache_url_request_job.h" 19 #include "content/browser/appcache/appcache_url_request_job.h"
20 #include "content/browser/service_worker/service_worker_request_handler.h" 20 #include "content/browser/service_worker/service_worker_request_handler.h"
21 #include "content/public/common/content_switches.h"
21 #include "net/url_request/url_request.h" 22 #include "net/url_request/url_request.h"
22 #include "net/url_request/url_request_job.h" 23 #include "net/url_request/url_request_job.h"
23 24
24 namespace content { 25 namespace content {
25 26
26 AppCacheRequestHandler::AppCacheRequestHandler( 27 AppCacheRequestHandler::AppCacheRequestHandler(
27 AppCacheHost* host, 28 AppCacheHost* host,
28 ResourceType resource_type, 29 ResourceType resource_type,
29 bool should_reset_appcache, 30 bool should_reset_appcache,
30 std::unique_ptr<AppCacheRequest> request) 31 std::unique_ptr<AppCacheRequest> request)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 std::unique_ptr<AppCacheJob> job; 96 std::unique_ptr<AppCacheJob> job;
96 if (is_main_resource()) 97 if (is_main_resource())
97 job = MaybeLoadMainResource(network_delegate); 98 job = MaybeLoadMainResource(network_delegate);
98 else 99 else
99 job = MaybeLoadSubResource(network_delegate); 100 job = MaybeLoadSubResource(network_delegate);
100 101
101 // If its been setup to deliver a network response, we can just delete 102 // 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 103 // it now and return NULL instead to achieve that since it couldn't
103 // have been started yet. 104 // have been started yet.
104 if (job && job->IsDeliveringNetworkResponse()) { 105 if (job && job->IsDeliveringNetworkResponse() && !job->AsURLLoaderJob()) {
105 DCHECK(!job->IsStarted()); 106 DCHECK(!job->IsStarted());
106 job.reset(); 107 job.reset();
107 } 108 }
108 109
109 return job.release(); 110 return job.release();
110 } 111 }
111 112
112 AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( 113 AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect(
113 net::NetworkDelegate* network_delegate, 114 net::NetworkDelegate* network_delegate,
114 const GURL& location) { 115 const GURL& location) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // static 232 // static
232 std::unique_ptr<AppCacheRequestHandler> 233 std::unique_ptr<AppCacheRequestHandler>
233 AppCacheRequestHandler::InitializeForNavigationNetworkService( 234 AppCacheRequestHandler::InitializeForNavigationNetworkService(
234 const ResourceRequest& request, 235 const ResourceRequest& request,
235 AppCacheNavigationHandleCore* appcache_handle_core, 236 AppCacheNavigationHandleCore* appcache_handle_core,
236 URLLoaderFactoryGetter* url_loader_factory_getter) { 237 URLLoaderFactoryGetter* url_loader_factory_getter) {
237 std::unique_ptr<AppCacheRequestHandler> handler = 238 std::unique_ptr<AppCacheRequestHandler> handler =
238 appcache_handle_core->host()->CreateRequestHandler( 239 appcache_handle_core->host()->CreateRequestHandler(
239 AppCacheURLLoaderRequest::Create(request), request.resource_type, 240 AppCacheURLLoaderRequest::Create(request), request.resource_type,
240 request.should_reset_appcache); 241 request.should_reset_appcache);
241 handler->set_network_url_loader_factory_getter(url_loader_factory_getter); 242 handler->network_url_loader_factory_getter_ = url_loader_factory_getter;
243 handler->appcache_host_ = appcache_handle_core->host()->GetWeakPtr();
242 return handler; 244 return handler;
243 } 245 }
244 246
245 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { 247 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) {
246 storage()->CancelDelegateCallbacks(this); 248 storage()->CancelDelegateCallbacks(this);
247 host_ = NULL; // no need to RemoveObserver, the host is being deleted 249 host_ = NULL; // no need to RemoveObserver, the host is being deleted
248 250
249 // Since the host is being deleted, we don't have to complete any job 251 // 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. 252 // that is current running. It's destined for the bit bucket anyway.
251 if (job_.get()) { 253 if (job_.get()) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 job_.reset(); 317 job_.reset();
316 } 318 }
317 319
318 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::CreateJob( 320 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::CreateJob(
319 net::NetworkDelegate* network_delegate) { 321 net::NetworkDelegate* network_delegate) {
320 std::unique_ptr<AppCacheJob> job = AppCacheJob::Create( 322 std::unique_ptr<AppCacheJob> job = AppCacheJob::Create(
321 is_main_resource(), host_, storage(), request_.get(), network_delegate, 323 is_main_resource(), host_, storage(), request_.get(), network_delegate,
322 base::Bind(&AppCacheRequestHandler::OnPrepareToRestart, 324 base::Bind(&AppCacheRequestHandler::OnPrepareToRestart,
323 base::Unretained(this))); 325 base::Unretained(this)));
324 job_ = job->GetWeakPtr(); 326 job_ = job->GetWeakPtr();
327 if (job_.get() && !is_main_resource() &&
328 base::CommandLine::ForCurrentProcess()->HasSwitch(
329 switches::kEnableNetworkService) &&
330 !is_main_resource()) {
331 AppCacheURLLoaderJob* loader_job = job_->AsURLLoaderJob();
332
333 // The job owns us from this point on.
334 loader_job->SetSubresourceLoadInfo(
335 std::move(subresource_load_info_), this,
336 network_url_loader_factory_getter_.get());
337 }
338
325 return job; 339 return job;
326 } 340 }
327 341
328 // Main-resource handling ---------------------------------------------- 342 // Main-resource handling ----------------------------------------------
329 343
330 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( 344 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource(
331 net::NetworkDelegate* network_delegate) { 345 net::NetworkDelegate* network_delegate) {
332 DCHECK(!job_.get()); 346 DCHECK(!job_.get());
333 DCHECK(host_); 347 DCHECK(host_);
334 348
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 if (!navigation_request_job_.get()) { 556 if (!navigation_request_job_.get()) {
543 std::move(callback).Run(StartLoaderCallback()); 557 std::move(callback).Run(StartLoaderCallback());
544 return; 558 return;
545 } 559 }
546 navigation_request_job_->AsURLLoaderJob()->set_loader_callback( 560 navigation_request_job_->AsURLLoaderJob()->set_loader_callback(
547 std::move(callback)); 561 std::move(callback));
548 } 562 }
549 563
550 mojom::URLLoaderFactoryPtr 564 mojom::URLLoaderFactoryPtr
551 AppCacheRequestHandler::MaybeCreateSubresourceFactory() { 565 AppCacheRequestHandler::MaybeCreateSubresourceFactory() {
552 return AppCacheSubresourceURLFactory::CreateURLLoaderFactory( 566 mojom::URLLoaderFactoryPtr factory_ptr = nullptr;
553 network_url_loader_factory_getter_.get()); 567
568 // The factory is destroyed when the renderer drops the connection.
569 AppCacheSubresourceURLFactory::CreateURLLoaderFactory(
570 network_url_loader_factory_getter_.get(), appcache_host_,
571 &factory_ptr);
572
573 return factory_ptr;
554 } 574 }
555 575
556 } // namespace content 576 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698