summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 01:54:24 +0000
committerrlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 01:54:24 +0000
commit1b2747da8cf41299c56b60a87fc3200eceb8c002 (patch)
treefdadaf99cb015b88fb8de5b93c61909ef99d08b4
parent8e479ac1b1c72ae85683a3ce85640803ddaf1cae (diff)
downloadchromium_src-1b2747da8cf41299c56b60a87fc3200eceb8c002.zip
chromium_src-1b2747da8cf41299c56b60a87fc3200eceb8c002.tar.gz
chromium_src-1b2747da8cf41299c56b60a87fc3200eceb8c002.tar.bz2
Updating Preconnect to no longer get the default context. Instead it now gets the profile's context.
BUG=97759 TEST=passes existing Review URL: http://codereview.chromium.org/8165015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106437 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/login/login_utils.cc8
-rw-r--r--chrome/browser/net/preconnect.cc19
-rw-r--r--chrome/browser/net/preconnect.h10
-rw-r--r--chrome/browser/net/predictor.cc34
-rw-r--r--chrome/browser/net/predictor.h11
-rw-r--r--chrome/browser/profiles/profile.h4
-rw-r--r--chrome/browser/profiles/profile_impl_io_data.cc16
7 files changed, 64 insertions, 38 deletions
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index a1a6425..c891b76 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -1000,7 +1000,9 @@ class WarmingObserver : public NetworkLibrary::NetworkManagerObserver {
chrome_browser_net::PreconnectOnUIThread(
GURL(GaiaUrls::GetInstance()->client_login_url()),
chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED,
- kConnectionsNeeded);
+ kConnectionsNeeded,
+ make_scoped_refptr(
+ ProfileManager::GetDefaultProfile()->GetRequestContext()));
netlib->RemoveNetworkManagerObserver(this);
delete this;
}
@@ -1015,7 +1017,9 @@ void LoginUtilsImpl::PrewarmAuthentication() {
chrome_browser_net::PreconnectOnUIThread(
GURL(GaiaUrls::GetInstance()->client_login_url()),
chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED,
- kConnectionsNeeded);
+ kConnectionsNeeded,
+ make_scoped_refptr(
+ ProfileManager::GetDefaultProfile()->GetRequestContext()));
} else {
new WarmingObserver();
}
diff --git a/chrome/browser/net/preconnect.cc b/chrome/browser/net/preconnect.cc
index 56342df..456a471 100644
--- a/chrome/browser/net/preconnect.cc
+++ b/chrome/browser/net/preconnect.cc
@@ -4,9 +4,9 @@
#include "chrome/browser/net/preconnect.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
-#include "chrome/browser/profiles/profile.h"
#include "content/browser/browser_thread.h"
#include "net/base/net_log.h"
#include "net/base/ssl_config_service.h"
@@ -22,13 +22,14 @@ namespace chrome_browser_net {
void PreconnectOnUIThread(
const GURL& url,
UrlInfo::ResolutionMotivation motivation,
- int count) {
+ int count,
+ net::URLRequestContextGetter* getter) {
// Prewarm connection to Search URL.
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableFunction(PreconnectOnIOThread, url, motivation,
- count));
+ base::Bind(&PreconnectOnIOThread, url, motivation,
+ count, make_scoped_refptr(getter)));
return;
}
@@ -36,16 +37,14 @@ void PreconnectOnUIThread(
void PreconnectOnIOThread(
const GURL& url,
UrlInfo::ResolutionMotivation motivation,
- int count) {
- net::URLRequestContextGetter* getter =
- Profile::Deprecated::GetDefaultRequestContext();
- if (!getter)
- return;
+ int count,
+ net::URLRequestContextGetter* getter) {
if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
LOG(DFATAL) << "This must be run only on the IO thread.";
return;
}
-
+ if (!getter)
+ return;
// We are now commited to doing the async preconnection call.
UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation,
UrlInfo::MAX_MOTIVATED);
diff --git a/chrome/browser/net/preconnect.h b/chrome/browser/net/preconnect.h
index 056d5d6..89e48db 100644
--- a/chrome/browser/net/preconnect.h
+++ b/chrome/browser/net/preconnect.h
@@ -13,6 +13,10 @@
class GURL;
+namespace net {
+class URLRequestContextGetter;
+}
+
namespace chrome_browser_net {
// Try to preconnect. Typically motivated by OMNIBOX to reach search service.
@@ -20,14 +24,16 @@ namespace chrome_browser_net {
// parallel.
void PreconnectOnUIThread(const GURL& url,
UrlInfo::ResolutionMotivation motivation,
- int count);
+ int count,
+ net::URLRequestContextGetter* getter);
// Try to preconnect. Typically used by predictor when a subresource probably
// needs a connection. |count| may be used to request more than one connection
// be established in parallel.
void PreconnectOnIOThread(const GURL& url,
UrlInfo::ResolutionMotivation motivation,
- int count);
+ int count,
+ net::URLRequestContextGetter* getter);
} // namespace chrome_browser_net
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.
}
diff --git a/chrome/browser/net/predictor.h b/chrome/browser/net/predictor.h
index 710b8ae..1ed7007 100644
--- a/chrome/browser/net/predictor.h
+++ b/chrome/browser/net/predictor.h
@@ -43,6 +43,7 @@ class WaitableEvent;
namespace net {
class HostResolver;
+class URLRequestContextGetter;
} // namespace net
class IOThread;
@@ -106,7 +107,8 @@ class Predictor {
virtual void InitNetworkPredictor(PrefService* user_prefs,
PrefService* local_state,
- IOThread* io_thread);
+ IOThread* io_thread,
+ net::URLRequestContextGetter* getter);
// The Omnibox has proposed a given url to the user, and if it is a search
// URL, then it also indicates that this is preconnectable (i.e., we could
@@ -431,6 +433,10 @@ class Predictor {
scoped_ptr<InitialObserver> initial_observer_;
+ // Reference to URLRequestContextGetter from the Profile which owns the
+ // predictor. Used by Preconnect.
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
+
// Status of speculative DNS resolution and speculative TCP/IP connection
// feature.
bool predictor_enabled_;
@@ -505,7 +511,8 @@ class SimplePredictor : public Predictor {
virtual ~SimplePredictor() {}
virtual void InitNetworkPredictor(PrefService* user_prefs,
PrefService* local_state,
- IOThread* io_thread);
+ IOThread* io_thread,
+ net::URLRequestContextGetter* getter);
virtual void ShutdownOnUIThread(PrefService* user_prefs);
};
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index 794796f..22905e9 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -132,10 +132,6 @@ class Profile : public content::BrowserContext {
class Deprecated {
private:
friend bool IsGoogleGAIACookieInstalled();
- friend void chrome_browser_net::PreconnectOnIOThread(
- const GURL&,
- chrome_browser_net::UrlInfo::ResolutionMotivation,
- int);
friend class AutofillDownloadManager;
friend class ChromePluginMessageFilter;
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc
index d6ef5ec..b6564c0 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -109,10 +109,18 @@ void ProfileImplIOData::Handle::Init(
// Keep track of isolated app path separately so we can use it on demand.
io_data_->app_path_ = app_path;
+ // Initialize the URLRequestContextGetter which is needed for the predictor.
+ if (!main_request_context_getter_) {
+ main_request_context_getter_ =
+ ChromeURLRequestContextGetter::CreateOriginal(
+ profile_, io_data_);
+ }
+
io_data_->predictor_.reset(predictor);
io_data_->predictor_->InitNetworkPredictor(profile_->GetPrefs(),
local_state,
- io_thread);
+ io_thread,
+ main_request_context_getter_);
}
base::Callback<ChromeURLDataManagerBackend*(void)>
@@ -135,12 +143,6 @@ ProfileImplIOData::Handle::GetResourceContext() const {
scoped_refptr<ChromeURLRequestContextGetter>
ProfileImplIOData::Handle::GetMainRequestContextGetter() const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- LazyInitialize();
- if (!main_request_context_getter_) {
- main_request_context_getter_ =
- ChromeURLRequestContextGetter::CreateOriginal(
- profile_, io_data_);
- }
return main_request_context_getter_;
}