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

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

Issue 2902653002: Get main frame and subframe AppCache loads to work. (Closed)
Patch Set: Address review comments Created 3 years, 6 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 "content/browser/appcache/appcache.h" 10 #include "content/browser/appcache/appcache.h"
11 #include "content/browser/appcache/appcache_backend_impl.h" 11 #include "content/browser/appcache/appcache_backend_impl.h"
12 #include "content/browser/appcache/appcache_host.h"
13 #include "content/browser/appcache/appcache_navigation_handle_core.h"
12 #include "content/browser/appcache/appcache_policy.h" 14 #include "content/browser/appcache/appcache_policy.h"
13 #include "content/browser/appcache/appcache_request.h" 15 #include "content/browser/appcache/appcache_request.h"
16 #include "content/browser/appcache/appcache_url_loader_factory.h"
17 #include "content/browser/appcache/appcache_url_loader_job.h"
18 #include "content/browser/appcache/appcache_url_loader_request.h"
14 #include "content/browser/appcache/appcache_url_request_job.h" 19 #include "content/browser/appcache/appcache_url_request_job.h"
15 #include "content/browser/service_worker/service_worker_request_handler.h" 20 #include "content/browser/service_worker/service_worker_request_handler.h"
16 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_job.h" 22 #include "net/url_request/url_request_job.h"
18 23
19 namespace content { 24 namespace content {
20 25
21 AppCacheRequestHandler::AppCacheRequestHandler( 26 AppCacheRequestHandler::AppCacheRequestHandler(
22 AppCacheHost* host, 27 AppCacheHost* host,
23 ResourceType resource_type, 28 ResourceType resource_type,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 221
217 void AppCacheRequestHandler::MaybeCompleteCrossSiteTransferInOldProcess( 222 void AppCacheRequestHandler::MaybeCompleteCrossSiteTransferInOldProcess(
218 int old_process_id) { 223 int old_process_id) {
219 if (!host_ || !host_for_cross_site_transfer_.get() || 224 if (!host_ || !host_for_cross_site_transfer_.get() ||
220 old_process_id != old_process_id_) { 225 old_process_id != old_process_id_) {
221 return; 226 return;
222 } 227 }
223 CompleteCrossSiteTransfer(old_process_id_, old_host_id_); 228 CompleteCrossSiteTransfer(old_process_id_, old_host_id_);
224 } 229 }
225 230
231 // static
232 std::unique_ptr<AppCacheRequestHandler>
233 AppCacheRequestHandler::InitializeForNavigationNetworkService(
234 const ResourceRequest& request,
235 AppCacheNavigationHandleCore* appcache_handle_core) {
236 std::unique_ptr<AppCacheRequestHandler> handler =
237 appcache_handle_core->host()->CreateRequestHandler(
238 AppCacheURLLoaderRequest::Create(request), request.resource_type,
239 request.should_reset_appcache);
240 return handler;
241 }
242
226 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { 243 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) {
227 storage()->CancelDelegateCallbacks(this); 244 storage()->CancelDelegateCallbacks(this);
228 host_ = NULL; // no need to RemoveObserver, the host is being deleted 245 host_ = NULL; // no need to RemoveObserver, the host is being deleted
229 246
230 // Since the host is being deleted, we don't have to complete any job 247 // Since the host is being deleted, we don't have to complete any job
231 // that is current running. It's destined for the bit bucket anyway. 248 // that is current running. It's destined for the bit bucket anyway.
232 if (job_.get()) { 249 if (job_.get()) {
233 job_->Kill(); 250 job_->Kill();
234 job_.reset(); 251 job_.reset();
235 } 252 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // Main-resource handling ---------------------------------------------- 326 // Main-resource handling ----------------------------------------------
310 327
311 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( 328 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource(
312 net::NetworkDelegate* network_delegate) { 329 net::NetworkDelegate* network_delegate) {
313 DCHECK(!job_.get()); 330 DCHECK(!job_.get());
314 DCHECK(host_); 331 DCHECK(host_);
315 332
316 // If a page falls into the scope of a ServiceWorker, any matching AppCaches 333 // If a page falls into the scope of a ServiceWorker, any matching AppCaches
317 // should be ignored. This depends on the ServiceWorker handler being invoked 334 // should be ignored. This depends on the ServiceWorker handler being invoked
318 // prior to the AppCache handler. 335 // prior to the AppCache handler.
319 if (ServiceWorkerRequestHandler::IsControlledByServiceWorker( 336 // TODO(ananta)
337 // We need to handle this for AppCache requests initiated for the network
338 // service
339 if (request_->GetURLRequest() &&
340 ServiceWorkerRequestHandler::IsControlledByServiceWorker(
320 request_->GetURLRequest())) { 341 request_->GetURLRequest())) {
321 host_->enable_cache_selection(false); 342 host_->enable_cache_selection(false);
322 return nullptr; 343 return nullptr;
323 } 344 }
324 345
346 if (storage()->IsInitialized() &&
347 service_->storage()->usage_map()->find(request_->GetURL().GetOrigin()) ==
348 service_->storage()->usage_map()->end()) {
349 return nullptr;
350 }
351
325 host_->enable_cache_selection(true); 352 host_->enable_cache_selection(true);
326 353
327 const AppCacheHost* spawning_host = 354 const AppCacheHost* spawning_host =
328 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ? 355 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ?
329 host_ : host_->GetSpawningHost(); 356 host_ : host_->GetSpawningHost();
330 GURL preferred_manifest_url = spawning_host ? 357 GURL preferred_manifest_url = spawning_host ?
331 spawning_host->preferred_manifest_url() : GURL(); 358 spawning_host->preferred_manifest_url() : GURL();
332 359
333 // We may have to wait for our storage query to complete, but 360 // We may have to wait for our storage query to complete, but
334 // this query can also complete syncrhonously. 361 // this query can also complete syncrhonously.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 523
497 if (!host_->associated_cache() || 524 if (!host_->associated_cache() ||
498 !host_->associated_cache()->is_complete()) { 525 !host_->associated_cache()->is_complete()) {
499 DeliverNetworkResponse(); 526 DeliverNetworkResponse();
500 return; 527 return;
501 } 528 }
502 529
503 ContinueMaybeLoadSubResource(); 530 ContinueMaybeLoadSubResource();
504 } 531 }
505 532
533 void AppCacheRequestHandler::MaybeCreateLoader(
534 const ResourceRequest& resource_request,
535 ResourceContext* resource_context,
536 LoaderCallback callback) {
537 // MaybeLoadMainResource will invoke navigation_request_job's methods
538 // asynchronously via AppCacheStorage::Delegate.
539 navigation_request_job_ = MaybeLoadMainResource(nullptr);
540 if (!navigation_request_job_.get()) {
541 std::move(callback).Run(StartLoaderCallback());
542 return;
543 }
544 navigation_request_job_->AsURLLoaderJob()->set_loader_callback(
545 std::move(callback));
546 }
547
506 } // namespace content 548 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_request_handler.h ('k') | content/browser/appcache/appcache_storage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698