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

Side by Side Diff: content/browser/loader/resource_loader.cc

Issue 25772002: Allows prefetch requests to live beyond the renderer by delaying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change delay from 3s to 60s for initial timing. Obey the browser process when it wants to cancel. Created 7 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "base/timer/timer.h"
11 #include "content/browser/child_process_security_policy_impl.h" 12 #include "content/browser/child_process_security_policy_impl.h"
12 #include "content/browser/loader/resource_loader_delegate.h" 13 #include "content/browser/loader/resource_loader_delegate.h"
13 #include "content/browser/loader/resource_request_info_impl.h" 14 #include "content/browser/loader/resource_request_info_impl.h"
14 #include "content/browser/ssl/ssl_client_auth_handler.h" 15 #include "content/browser/ssl/ssl_client_auth_handler.h"
15 #include "content/browser/ssl/ssl_manager.h" 16 #include "content/browser/ssl/ssl_manager.h"
16 #include "content/common/ssl_status_serialization.h" 17 #include "content/common/ssl_status_serialization.h"
17 #include "content/public/browser/cert_store.h" 18 #include "content/public/browser/cert_store.h"
18 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" 19 #include "content/public/browser/resource_dispatcher_host_login_delegate.h"
19 #include "content/public/browser/site_instance.h" 20 #include "content/public/browser/site_instance.h"
20 #include "content/public/common/content_client.h" 21 #include "content/public/common/content_client.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 request, 56 request,
56 &response->head.appcache_id, 57 &response->head.appcache_id,
57 &response->head.appcache_manifest_url); 58 &response->head.appcache_manifest_url);
58 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove. 59 // TODO(mmenke): Figure out if LOAD_ENABLE_LOAD_TIMING is safe to remove.
59 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING) 60 if (request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING)
60 request->GetLoadTimingInfo(&response->head.load_timing); 61 request->GetLoadTimingInfo(&response->head.load_timing);
61 } 62 }
62 63
63 } // namespace 64 } // namespace
64 65
66 int ResourceLoader::delay_prefetch_cancel_ms_ = 60000;
67
65 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request, 68 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request,
66 scoped_ptr<ResourceHandler> handler, 69 scoped_ptr<ResourceHandler> handler,
67 ResourceLoaderDelegate* delegate) 70 ResourceLoaderDelegate* delegate)
68 : weak_ptr_factory_(this) { 71 : weak_ptr_factory_(this) {
69 scoped_ptr<net::ClientCertStore> client_cert_store; 72 scoped_ptr<net::ClientCertStore> client_cert_store;
70 #if !defined(USE_OPENSSL) 73 #if !defined(USE_OPENSSL)
71 client_cert_store.reset(new net::ClientCertStoreImpl()); 74 client_cert_store.reset(new net::ClientCertStoreImpl());
72 #endif 75 #endif
73 Init(request.Pass(), handler.Pass(), delegate, client_cert_store.Pass()); 76 Init(request.Pass(), handler.Pass(), delegate, client_cert_store.Pass());
74 } 77 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 VLOG(1) << "CancelRequestInternal: " << request_->url().spec(); 463 VLOG(1) << "CancelRequestInternal: " << request_->url().spec();
461 464
462 ResourceRequestInfoImpl* info = GetRequestInfo(); 465 ResourceRequestInfoImpl* info = GetRequestInfo();
463 466
464 // WebKit will send us a cancel for downloads since it no longer handles 467 // WebKit will send us a cancel for downloads since it no longer handles
465 // them. In this case, ignore the cancel since we handle downloads in the 468 // them. In this case, ignore the cancel since we handle downloads in the
466 // browser. 469 // browser.
467 if (from_renderer && (info->is_download() || info->is_stream())) 470 if (from_renderer && (info->is_download() || info->is_stream()))
468 return; 471 return;
469 472
473 // Delay requests to cancel prefetches
474 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
475 if (from_renderer &&
476 command_line.HasSwitch(switches::kDelayPrefetchCancellation) &&
477 info->GetResourceType() == ResourceType::PREFETCH) {
478 if (prefetch_timer_.get() && prefetch_timer_->IsRunning()) {
479 // We've already processed a cancel for this prefetch, ignore this cancel.
480 return;
481 } else if (!prefetch_timer_.get()) {
482 // Our first call to cancel this prefetch, start a delay timer.
483 prefetch_timer_.reset(new base::OneShotTimer<ResourceLoader>());
484 prefetch_timer_->Start(
485 FROM_HERE, TimeDelta::FromMilliseconds(delay_prefetch_cancel_ms_),
486 this, &ResourceLoader::Cancel);
487 return;
488 } // else we have an expired delay timer, cancel the load.
489 }
490
470 // TODO(darin): Perhaps we should really be looking to see if the status is 491 // TODO(darin): Perhaps we should really be looking to see if the status is
471 // IO_PENDING? 492 // IO_PENDING?
472 bool was_pending = request_->is_pending(); 493 bool was_pending = request_->is_pending();
473 494
474 if (login_delegate_.get()) { 495 if (login_delegate_.get()) {
475 login_delegate_->OnRequestCancelled(); 496 login_delegate_->OnRequestCancelled();
476 login_delegate_ = NULL; 497 login_delegate_ = NULL;
477 } 498 }
478 if (ssl_client_auth_handler_.get()) { 499 if (ssl_client_auth_handler_.get()) {
479 ssl_client_auth_handler_->OnRequestCancelled(); 500 ssl_client_auth_handler_->OnRequestCancelled();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 // we resume. 669 // we resume.
649 deferred_stage_ = DEFERRED_FINISH; 670 deferred_stage_ = DEFERRED_FINISH;
650 } 671 }
651 } 672 }
652 673
653 void ResourceLoader::CallDidFinishLoading() { 674 void ResourceLoader::CallDidFinishLoading() {
654 delegate_->DidFinishLoading(this); 675 delegate_->DidFinishLoading(this);
655 } 676 }
656 677
657 } // namespace content 678 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698