diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 01:01:31 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 01:01:31 +0000 |
commit | 102e27c64d9deae4c32f346214fd7c2bddaa9fb3 (patch) | |
tree | d7372b853f79764c4ec200f4cd6d26c9bb512d65 /net/http/http_stream_factory.cc | |
parent | d7f21d5584fb4962617644833fd2a80b6d0c7e8d (diff) | |
download | chromium_src-102e27c64d9deae4c32f346214fd7c2bddaa9fb3.zip chromium_src-102e27c64d9deae4c32f346214fd7c2bddaa9fb3.tar.gz chromium_src-102e27c64d9deae4c32f346214fd7c2bddaa9fb3.tar.bz2 |
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
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=75668
Review URL: http://codereview.chromium.org/6543004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75688 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_stream_factory.cc')
-rw-r--r-- | net/http/http_stream_factory.cc | 107 |
1 files changed, 32 insertions, 75 deletions
diff --git a/net/http/http_stream_factory.cc b/net/http/http_stream_factory.cc index 4673d58..9189e99 100644 --- a/net/http/http_stream_factory.cc +++ b/net/http/http_stream_factory.cc @@ -1,17 +1,16 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "net/http/http_stream_factory.h" -#include "base/stl_util-inl.h" +#include "base/logging.h" #include "base/string_number_conversions.h" #include "base/string_split.h" -#include "base/string_util.h" -#include "net/base/net_log.h" -#include "net/base/net_util.h" -#include "net/http/http_network_session.h" -#include "net/http/http_stream_request.h" +#include "googleurl/src/gurl.h" +#include "net/base/host_mapping_rules.h" +#include "net/base/host_port_pair.h" +#include "net/http/http_alternate_protocols.h" namespace net { @@ -32,62 +31,7 @@ std::list<HostPortPair>* HttpStreamFactory::forced_spdy_exclusions_ = NULL; // static bool HttpStreamFactory::ignore_certificate_errors_ = false; -HttpStreamFactory::HttpStreamFactory() { -} - -HttpStreamFactory::~HttpStreamFactory() { - RequestCallbackMap request_callback_map; - request_callback_map.swap(request_callback_map_); - for (RequestCallbackMap::iterator it = request_callback_map.begin(); - it != request_callback_map.end(); ++it) { - delete it->first; - // We don't invoke the callback in the destructor. - } -} - -// static -void HttpStreamFactory::SetHostMappingRules(const std::string& rules) { - HostMappingRules* host_mapping_rules = new HostMappingRules(); - host_mapping_rules->SetRulesFromString(rules); - delete host_mapping_rules_; - host_mapping_rules_ = host_mapping_rules; -} - -StreamRequest* HttpStreamFactory::RequestStream( - const HttpRequestInfo* request_info, - SSLConfig* ssl_config, - ProxyInfo* proxy_info, - HttpNetworkSession* session, - StreamRequest::Delegate* delegate, - const BoundNetLog& net_log) { - HttpStreamRequest* stream = new HttpStreamRequest(this, session); - stream->Start(request_info, ssl_config, proxy_info, delegate, net_log); - return stream; -} - -int HttpStreamFactory::PreconnectStreams( - int num_streams, - const HttpRequestInfo* request_info, - SSLConfig* ssl_config, - ProxyInfo* proxy_info, - HttpNetworkSession* session, - const BoundNetLog& net_log, - CompletionCallback* callback) { - HttpStreamRequest* stream = new HttpStreamRequest(this, session); - int rv = stream->Preconnect(num_streams, request_info, ssl_config, - proxy_info, this, net_log); - DCHECK_EQ(ERR_IO_PENDING, rv); - request_callback_map_[stream] = callback; - return rv; -} - -void HttpStreamFactory::AddTLSIntolerantServer(const GURL& url) { - tls_intolerant_servers_.insert(GetHostAndPort(url)); -} - -bool HttpStreamFactory::IsTLSIntolerantServer(const GURL& url) { - return ContainsKey(tls_intolerant_servers_, GetHostAndPort(url)); -} +HttpStreamFactory::~HttpStreamFactory() {} void HttpStreamFactory::ProcessAlternateProtocol( HttpAlternateProtocols* alternate_protocols, @@ -128,8 +72,7 @@ void HttpStreamFactory::ProcessAlternateProtocol( } HostPortPair host_port(http_host_port_pair); - if (host_mapping_rules_) - host_mapping_rules_->RewriteHost(&host_port); + host_mapping_rules().RewriteHost(&host_port); if (alternate_protocols->HasAlternateProtocolFor(host_port)) { const HttpAlternateProtocols::PortProtocolPair existing_alternate = @@ -144,7 +87,7 @@ void HttpStreamFactory::ProcessAlternateProtocol( GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint) { - if (host_mapping_rules_ && host_mapping_rules_->RewriteHost(endpoint)) { + if (host_mapping_rules().RewriteHost(endpoint)) { url_canon::Replacements<char> replacements; const std::string port_str = base::IntToString(endpoint->port()); replacements.SetPort(port_str.c_str(), @@ -156,15 +99,29 @@ GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, return url; } -void HttpStreamFactory::OnPreconnectsComplete( - HttpStreamRequest* request, int result) { - RequestCallbackMap::iterator it = request_callback_map_.find(request); - DCHECK(it != request_callback_map_.end()); - CompletionCallback* callback = it->second; - request_callback_map_.erase(it); - delete request; - callback->Run(result); +// static +void HttpStreamFactory::add_forced_spdy_exclusion(const std::string& value) { + HostPortPair pair = HostPortPair::FromURL(GURL(value)); + if (!forced_spdy_exclusions_) + forced_spdy_exclusions_ = new std::list<HostPortPair>(); + forced_spdy_exclusions_->push_back(pair); } -} // namespace net +// static +void HttpStreamFactory::SetHostMappingRules(const std::string& rules) { + HostMappingRules* host_mapping_rules = new HostMappingRules; + host_mapping_rules->SetRulesFromString(rules); + delete host_mapping_rules_; + host_mapping_rules_ = host_mapping_rules; +} + +HttpStreamFactory::HttpStreamFactory() {} +// static +const HostMappingRules& HttpStreamFactory::host_mapping_rules() { + if (!host_mapping_rules_) + host_mapping_rules_ = new HostMappingRules; + return *host_mapping_rules_; +} + +} // namespace net |