diff options
Diffstat (limited to 'chrome/browser/net/predictor.cc')
-rw-r--r-- | chrome/browser/net/predictor.cc | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc index 20fa822..62dbd98 100644 --- a/chrome/browser/net/predictor.cc +++ b/chrome/browser/net/predictor.cc @@ -34,6 +34,7 @@ #include "net/base/net_errors.h" #include "net/base/net_log.h" #include "net/base/single_request_host_resolver.h" +#include "net/url_request/url_request_context_getter.h" using base::TimeDelta; @@ -123,6 +124,7 @@ class Predictor::LookupRequest { Predictor::Predictor(bool preconnect_enabled) : initial_observer_(NULL), + url_request_context_getter_(NULL), predictor_enabled_(true), peak_pending_lookups_(0), shutdown_(false), @@ -143,8 +145,8 @@ Predictor::~Predictor() { } // static -Predictor* Predictor::CreatePredictor( - bool preconnect_enabled, bool simple_shutdown) { +Predictor* Predictor::CreatePredictor(bool preconnect_enabled, + bool simple_shutdown) { if (simple_shutdown) return new SimplePredictor(preconnect_enabled); return new Predictor(preconnect_enabled); @@ -161,12 +163,15 @@ void Predictor::RegisterUserPrefs(PrefService* user_prefs) { void Predictor::InitNetworkPredictor(PrefService* user_prefs, PrefService* local_state, - IOThread* io_thread) { + IOThread* io_thread, + net::URLRequestContextGetter* getter) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); bool predictor_enabled = user_prefs->GetBoolean(prefs::kNetworkPredictionEnabled); + url_request_context_getter_ = getter; + // Gather the list of hostnames to prefetch on startup. UrlList urls = GetPredictedUrlListAtStartup(user_prefs, local_state); @@ -243,7 +248,8 @@ void Predictor::AnticipateOmniboxUrl(const GURL& url, bool preconnectable) { last_omnibox_preconnect_ = now; const int kConnectionsNeeded = 1; PreconnectOnUIThread(CanonicalizeUrl(url), motivation, - kConnectionsNeeded); + kConnectionsNeeded, + url_request_context_getter_); return; // Skip pre-resolution, since we'll open a connection. } } else { @@ -282,7 +288,8 @@ void Predictor::PreconnectUrlAndSubresources(const GURL& url) { UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); const int kConnectionsNeeded = 1; PreconnectOnUIThread(CanonicalizeUrl(url), motivation, - kConnectionsNeeded); + kConnectionsNeeded, + url_request_context_getter_); PredictFrameSubresources(url.GetWithEmptyPath()); } } @@ -887,8 +894,10 @@ void Predictor::PrepareFrameSubresources(const GURL& url) { // size of the list with all the "Leaf" nodes in the tree (nodes that don't // load any subresources). If we learn about this resource, we will instead // provide a more carefully estimated preconnection count. - if (preconnect_enabled_) - PreconnectOnIOThread(url, UrlInfo::SELF_REFERAL_MOTIVATED, 2); + if (preconnect_enabled_) { + PreconnectOnIOThread(url, UrlInfo::SELF_REFERAL_MOTIVATED, 2, + url_request_context_getter_); + } return; } @@ -911,7 +920,8 @@ void Predictor::PrepareFrameSubresources(const GURL& url) { int count = static_cast<int>(std::ceil(connection_expectation)); if (url.host() == future_url->first.host()) ++count; - PreconnectOnIOThread(future_url->first, motivation, count); + PreconnectOnIOThread(future_url->first, motivation, count, + url_request_context_getter_); } else if (connection_expectation > kDNSPreresolutionWorthyExpectedValue) { evalution = PRERESOLUTION; future_url->second.preresolution_increment(); @@ -1202,9 +1212,11 @@ GURL Predictor::CanonicalizeUrl(const GURL& url) { return GURL(scheme + "://" + url.host() + colon_plus_port); } -void SimplePredictor::InitNetworkPredictor(PrefService* user_prefs, - PrefService* local_state, - IOThread* io_thread) { +void SimplePredictor::InitNetworkPredictor( + PrefService* user_prefs, + PrefService* local_state, + IOThread* io_thread, + net::URLRequestContextGetter* getter) { // Empty function for unittests. } |