summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/preconnect.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/net/preconnect.cc')
-rw-r--r--chrome/browser/net/preconnect.cc76
1 files changed, 30 insertions, 46 deletions
diff --git a/chrome/browser/net/preconnect.cc b/chrome/browser/net/preconnect.cc
index c35bc0e..8152f62 100644
--- a/chrome/browser/net/preconnect.cc
+++ b/chrome/browser/net/preconnect.cc
@@ -6,44 +6,37 @@
#include "base/logging.h"
#include "base/metrics/histogram.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/common/net/url_request_context_getter.h"
+#include "net/base/net_log.h"
+#include "net/base/ssl_config_service.h"
#include "net/http/http_network_session.h"
+#include "net/http/http_request_info.h"
+#include "net/http/http_stream_factory.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h"
namespace chrome_browser_net {
-// static
-void Preconnect::PreconnectOnUIThread(const GURL& url,
- UrlInfo::ResolutionMotivation motivation, int count) {
+void PreconnectOnUIThread(
+ const GURL& url,
+ UrlInfo::ResolutionMotivation motivation,
+ int count) {
// Prewarm connection to Search URL.
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableFunction(Preconnect::PreconnectOnIOThread, url, motivation,
+ NewRunnableFunction(PreconnectOnIOThread, url, motivation,
count));
return;
}
-// static
-void Preconnect::PreconnectOnIOThread(const GURL& url,
- UrlInfo::ResolutionMotivation motivation, int count) {
- Preconnect* preconnect = new Preconnect(motivation);
- // TODO(jar): Should I use PostTask for LearnedSubresources to delay the
- // preconnection a tad?
- preconnect->Connect(url, count);
-}
-
-Preconnect::Preconnect(UrlInfo::ResolutionMotivation motivation)
- : motivation_(motivation),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- io_callback_(this, &Preconnect::OnPreconnectComplete)) {}
-Preconnect::~Preconnect() {}
-
-void Preconnect::Connect(const GURL& url, int count) {
+void PreconnectOnIOThread(
+ const GURL& url,
+ UrlInfo::ResolutionMotivation motivation,
+ int count) {
URLRequestContextGetter* getter = Profile::GetDefaultRequestContext();
if (!getter)
return;
@@ -53,16 +46,16 @@ void Preconnect::Connect(const GURL& url, int count) {
}
// We are now commited to doing the async preconnection call.
- UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation_,
+ UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation,
UrlInfo::MAX_MOTIVATED);
net::URLRequestContext* context = getter->GetURLRequestContext();
net::HttpTransactionFactory* factory = context->http_transaction_factory();
net::HttpNetworkSession* session = factory->GetSession();
- request_info_.reset(new net::HttpRequestInfo());
- request_info_->url = url;
- request_info_->method = "GET";
+ net::HttpRequestInfo request_info;
+ request_info.url = url;
+ request_info.method = "GET";
// It almost doesn't matter whether we use net::LOWEST or net::HIGHEST
// priority here, as we won't make a request, and will surrender the created
// socket to the pool as soon as we can. However, we would like to mark the
@@ -74,19 +67,19 @@ void Preconnect::Connect(const GURL& url, int count) {
// as speculative, and better detect stats (if it gets used).
// TODO(jar): histogram to see how often we accidentally use a previously-
// unused socket, when a previously used socket was available.
- request_info_->priority = net::HIGHEST;
+ request_info.priority = net::HIGHEST;
// Translate the motivation from UrlRequest motivations to HttpRequest
// motivations.
- switch (motivation_) {
+ switch (motivation) {
case UrlInfo::OMNIBOX_MOTIVATED:
- request_info_->motivation = net::HttpRequestInfo::OMNIBOX_MOTIVATED;
+ request_info.motivation = net::HttpRequestInfo::OMNIBOX_MOTIVATED;
break;
case UrlInfo::LEARNED_REFERAL_MOTIVATED:
- request_info_->motivation = net::HttpRequestInfo::PRECONNECT_MOTIVATED;
+ request_info.motivation = net::HttpRequestInfo::PRECONNECT_MOTIVATED;
break;
case UrlInfo::EARLY_LOAD_MOTIVATED:
- request_info_->motivation = net::HttpRequestInfo::EARLY_LOAD_MOTIVATED;
+ request_info.motivation = net::HttpRequestInfo::EARLY_LOAD_MOTIVATED;
break;
default:
// Other motivations should never happen here.
@@ -95,26 +88,17 @@ void Preconnect::Connect(const GURL& url, int count) {
}
// Setup the SSL Configuration.
- ssl_config_.reset(new net::SSLConfig());
- session->ssl_config_service()->GetSSLConfig(ssl_config_.get());
+ net::SSLConfig ssl_config;
+ session->ssl_config_service()->GetSSLConfig(&ssl_config);
if (session->http_stream_factory()->next_protos())
- ssl_config_->next_protos = *session->http_stream_factory()->next_protos();
+ ssl_config.next_protos = *session->http_stream_factory()->next_protos();
// All preconnects should perform EV certificate verification.
- ssl_config_->verify_ev_cert = true;
-
- proxy_info_.reset(new net::ProxyInfo());
- net::StreamFactory* stream_factory = session->http_stream_factory();
- int rv = stream_factory->PreconnectStreams(count, request_info_.get(),
- ssl_config_.get(),
- proxy_info_.get(), session,
- net_log_, &io_callback_);
- if (rv != net::ERR_IO_PENDING)
- delete this;
-}
+ ssl_config.verify_ev_cert = true;
-void Preconnect::OnPreconnectComplete(int error_code) {
- delete this;
+ net::HttpStreamFactory* http_stream_factory = session->http_stream_factory();
+ http_stream_factory->PreconnectStreams(
+ count, request_info, ssl_config, net::BoundNetLog());
}
} // namespace chrome_browser_net