diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 00:08:48 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 00:08:48 +0000 |
commit | c4744cdbbe22df6848e354dbfa9dbb1dc36e76d8 (patch) | |
tree | b6d92d6b17ae0e140485fb53b53ef0017a99a6c0 /chrome/browser | |
parent | 95fb385e5e68a69a39c77d66d801bebdaf39c311 (diff) | |
download | chromium_src-c4744cdbbe22df6848e354dbfa9dbb1dc36e76d8.zip chromium_src-c4744cdbbe22df6848e354dbfa9dbb1dc36e76d8.tar.gz chromium_src-c4744cdbbe22df6848e354dbfa9dbb1dc36e76d8.tar.bz2 |
Revert 75668 for breaking ChromeOS build - Refactor HttpStreamFactory.
Rename StreamFactory and StreamRequest to HttpStreamFactory and HttpStreamRequest.
Rename HttpStreamFactory to HttpStreamFactoryImpl.
Create HttpStreamFactoryImpl::Request (inherits from HttpStreamRequest) and HttpStreamFactoryImpl::Job (most of the old HttpStreamRequest code, other than the interface, moved here).
Currently there is still a strong binding within HttpStreamFactoryImpl between requests and jobs. This will be removed in a future changelist.
Note that due to the preparation for late binding, information like HttpRequestInfo and SSLConfig and ProxyInfo are just copied. It's possible we can consider refcounting them to reduce copies, but I think it's not worth the effort / ugliness.
I also did some minor cleanups like moving SpdySettingsStorage into SpdySessionPool and some CloseIdleConnections() cleanup.
BUG=54371,42669
TEST=unit tests
Review URL: http://codereview.chromium.org/6543004
TBR=willchan@chromium.org
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75670 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/net/preconnect.cc | 76 | ||||
-rw-r--r-- | chrome/browser/net/preconnect.h | 75 | ||||
-rw-r--r-- | chrome/browser/net/predictor.cc | 10 |
3 files changed, 112 insertions, 49 deletions
diff --git a/chrome/browser/net/preconnect.cc b/chrome/browser/net/preconnect.cc index 8152f62..c35bc0e 100644 --- a/chrome/browser/net/preconnect.cc +++ b/chrome/browser/net/preconnect.cc @@ -6,37 +6,44 @@ #include "base/logging.h" #include "base/metrics/histogram.h" -#include "chrome/browser/browser_thread.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/browser_thread.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 { -void PreconnectOnUIThread( - const GURL& url, - UrlInfo::ResolutionMotivation motivation, - int count) { +// static +void Preconnect::PreconnectOnUIThread(const GURL& url, + UrlInfo::ResolutionMotivation motivation, int count) { // Prewarm connection to Search URL. BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - NewRunnableFunction(PreconnectOnIOThread, url, motivation, + NewRunnableFunction(Preconnect::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)) {} -void PreconnectOnIOThread( - const GURL& url, - UrlInfo::ResolutionMotivation motivation, - int count) { +Preconnect::~Preconnect() {} + +void Preconnect::Connect(const GURL& url, int count) { URLRequestContextGetter* getter = Profile::GetDefaultRequestContext(); if (!getter) return; @@ -46,16 +53,16 @@ void PreconnectOnIOThread( } // 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(); - net::HttpRequestInfo request_info; - request_info.url = url; - request_info.method = "GET"; + request_info_.reset(new net::HttpRequestInfo()); + 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 @@ -67,19 +74,19 @@ void PreconnectOnIOThread( // 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. @@ -88,17 +95,26 @@ void PreconnectOnIOThread( } // Setup the SSL Configuration. - net::SSLConfig ssl_config; - session->ssl_config_service()->GetSSLConfig(&ssl_config); + ssl_config_.reset(new net::SSLConfig()); + session->ssl_config_service()->GetSSLConfig(ssl_config_.get()); 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; + 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; +} - net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); - http_stream_factory->PreconnectStreams( - count, request_info, ssl_config, net::BoundNetLog()); +void Preconnect::OnPreconnectComplete(int error_code) { + delete this; } } // namespace chrome_browser_net diff --git a/chrome/browser/net/preconnect.h b/chrome/browser/net/preconnect.h index 0175122..a950167 100644 --- a/chrome/browser/net/preconnect.h +++ b/chrome/browser/net/preconnect.h @@ -9,25 +9,72 @@ #define CHROME_BROWSER_NET_PRECONNECT_H_ #pragma once +#include "base/scoped_ptr.h" #include "chrome/browser/net/url_info.h" +#include "net/base/completion_callback.h" +#include "net/base/net_log.h" +#include "net/http/http_request_info.h" +#include "net/http/stream_factory.h" -class GURL; +namespace net { + +class ProxyInfo; +struct SSLConfig; + +} // namespace net namespace chrome_browser_net { -// Try to preconnect. Typically motivated by OMNIBOX to reach search service. -// |count| may be used to request more than one connection be established in -// parallel. -void PreconnectOnUIThread(const GURL& url, - UrlInfo::ResolutionMotivation motivation, - int count); - -// 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); +class Preconnect { + public: + // Try to preconnect. Typically motivated by OMNIBOX to reach search service. + // |count| may be used to request more than one connection be established in + // parallel. + static void PreconnectOnUIThread(const GURL& url, + UrlInfo::ResolutionMotivation motivation, + int count); + + // 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. + static void PreconnectOnIOThread(const GURL& url, + UrlInfo::ResolutionMotivation motivation, + int count); + + private: + explicit Preconnect(UrlInfo::ResolutionMotivation motivation); + virtual ~Preconnect(); + + void OnPreconnectComplete(int error_code); + + // Request actual connection, via interface that tags request as needed for + // preconnect only (so that they can be merged with connections needed for + // navigations). + void Connect(const GURL& url, int count); + + // Generally either LEARNED_REFERAL_MOTIVATED, OMNIBOX_MOTIVATED or + // EARLY_LOAD_MOTIVATED to indicate why we were trying to do a preconnection. + const UrlInfo::ResolutionMotivation motivation_; + + // HttpRequestInfo used for connecting. + scoped_ptr<net::HttpRequestInfo> request_info_; + + // SSLConfig used for connecting. + scoped_ptr<net::SSLConfig> ssl_config_; + + // ProxyInfo used for connecting. + scoped_ptr<net::ProxyInfo> proxy_info_; + + // A net log to use for this preconnect. + net::BoundNetLog net_log_; + + // Our preconnect. + scoped_ptr<net::StreamRequest> stream_request_; + + net::CompletionCallbackImpl<Preconnect> io_callback_; + + DISALLOW_COPY_AND_ASSIGN(Preconnect); +}; } // namespace chrome_browser_net diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc index 06aca37..327d709 100644 --- a/chrome/browser/net/predictor.cc +++ b/chrome/browser/net/predictor.cc @@ -183,8 +183,8 @@ void Predictor::AnticipateOmniboxUrl(const GURL& url, bool preconnectable) { return; // We've done a preconnect recently. last_omnibox_preconnect_ = now; const int kConnectionsNeeded = 1; - PreconnectOnUIThread(CanonicalizeUrl(url), motivation, - kConnectionsNeeded); + Preconnect::PreconnectOnUIThread(CanonicalizeUrl(url), motivation, + kConnectionsNeeded); return; // Skip pre-resolution, since we'll open a connection. } } else { @@ -217,8 +217,8 @@ void Predictor::PreconnectUrlAndSubresources(const GURL& url) { std::string host = url.HostNoBrackets(); UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); const int kConnectionsNeeded = 1; - PreconnectOnUIThread(CanonicalizeUrl(url), motivation, - kConnectionsNeeded); + Preconnect::PreconnectOnUIThread(CanonicalizeUrl(url), motivation, + kConnectionsNeeded); PredictFrameSubresources(url.GetWithEmptyPath()); } } @@ -259,7 +259,7 @@ 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); + Preconnect::PreconnectOnIOThread(future_url->first, motivation, count); } else if (connection_expectation > kDNSPreresolutionWorthyExpectedValue) { evalution = PRERESOLUTION; future_url->second.preresolution_increment(); |