Commit ad74a59d authored by erg@google.com's avatar erg@google.com

More net/ reordering.

In addition to the normal method reordering, this patch also deinlines
net/base/test_completion_callback.h and places the compiled code in the
net_test_support target. Minimization of that header also required adding
includes in a few unit tests.

BUG=68682
TEST=compiles

Review URL: http://codereview.chromium.org/6341004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72162 0039d316-1c4b-4281-b951-d872f2087c98
parent 9cf72aec
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/message_loop.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/platform_file.h" #include "base/platform_file.h"
#include "net/base/file_stream.h" #include "net/base/file_stream.h"
......
...@@ -51,12 +51,14 @@ ...@@ -51,12 +51,14 @@
namespace net { namespace net {
static const int kExceptionRule = 1; namespace {
static const int kWildcardRule = 2;
RegistryControlledDomainService::RegistryControlledDomainService() const int kExceptionRule = 1;
: find_domain_function_(Perfect_Hash::FindDomain) { const int kWildcardRule = 2;
}
RegistryControlledDomainService* test_instance_;
} // namespace
// static // static
std::string RegistryControlledDomainService::GetDomainAndRegistry( std::string RegistryControlledDomainService::GetDomainAndRegistry(
...@@ -154,6 +156,34 @@ size_t RegistryControlledDomainService::GetRegistryLength( ...@@ -154,6 +156,34 @@ size_t RegistryControlledDomainService::GetRegistryLength(
allow_unknown_registries); allow_unknown_registries);
} }
// static
RegistryControlledDomainService* RegistryControlledDomainService::GetInstance()
{
if (test_instance_)
return test_instance_;
return Singleton<RegistryControlledDomainService>::get();
}
RegistryControlledDomainService::RegistryControlledDomainService()
: find_domain_function_(Perfect_Hash::FindDomain) {
}
// static
RegistryControlledDomainService* RegistryControlledDomainService::SetInstance(
RegistryControlledDomainService* instance) {
RegistryControlledDomainService* old_instance = test_instance_;
test_instance_ = instance;
return old_instance;
}
// static
void RegistryControlledDomainService::UseFindDomainFunction(
FindDomainPtr function) {
RegistryControlledDomainService* instance = GetInstance();
instance->find_domain_function_ = function;
}
// static // static
std::string RegistryControlledDomainService::GetDomainAndRegistryImpl( std::string RegistryControlledDomainService::GetDomainAndRegistryImpl(
const std::string& host) { const std::string& host) {
...@@ -261,30 +291,4 @@ size_t RegistryControlledDomainService::GetRegistryLengthImpl( ...@@ -261,30 +291,4 @@ size_t RegistryControlledDomainService::GetRegistryLengthImpl(
return allow_unknown_registries ? (host.length() - curr_start) : 0; return allow_unknown_registries ? (host.length() - curr_start) : 0;
} }
static RegistryControlledDomainService* test_instance_;
// static
RegistryControlledDomainService* RegistryControlledDomainService::SetInstance(
RegistryControlledDomainService* instance) {
RegistryControlledDomainService* old_instance = test_instance_;
test_instance_ = instance;
return old_instance;
}
// static
RegistryControlledDomainService* RegistryControlledDomainService::GetInstance()
{
if (test_instance_)
return test_instance_;
return Singleton<RegistryControlledDomainService>::get();
}
// static
void RegistryControlledDomainService::UseFindDomainFunction(
FindDomainPtr function) {
RegistryControlledDomainService* instance = GetInstance();
instance->find_domain_function_ = function;
}
} // namespace net } // namespace net
// 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/base/test_completion_callback.h"
#include "base/message_loop.h"
#include "net/base/net_errors.h"
TestCompletionCallback::TestCompletionCallback()
: result_(0),
have_result_(false),
waiting_for_result_(false) {
}
TestCompletionCallback::~TestCompletionCallback() {}
int TestCompletionCallback::WaitForResult() {
DCHECK(!waiting_for_result_);
while (!have_result_) {
waiting_for_result_ = true;
MessageLoop::current()->Run();
waiting_for_result_ = false;
}
have_result_ = false; // auto-reset for next callback
return result_;
}
int TestCompletionCallback::GetResult(int result) {
if (net::ERR_IO_PENDING != result)
return result;
return WaitForResult();
}
void TestCompletionCallback::RunWithParams(const Tuple1<int>& params) {
result_ = params.a;
have_result_ = true;
if (waiting_for_result_)
MessageLoop::current()->Quit();
}
...@@ -7,9 +7,6 @@ ...@@ -7,9 +7,6 @@
#pragma once #pragma once
#include "base/callback.h" #include "base/callback.h"
#include "base/message_loop.h"
#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// completion callback helper // completion callback helper
...@@ -24,37 +21,16 @@ ...@@ -24,37 +21,16 @@
// //
class TestCompletionCallback : public CallbackRunner< Tuple1<int> > { class TestCompletionCallback : public CallbackRunner< Tuple1<int> > {
public: public:
TestCompletionCallback() TestCompletionCallback();
: result_(0), virtual ~TestCompletionCallback();
have_result_(false),
waiting_for_result_(false) {
}
int WaitForResult() { int WaitForResult();
DCHECK(!waiting_for_result_);
while (!have_result_) {
waiting_for_result_ = true;
MessageLoop::current()->Run();
waiting_for_result_ = false;
}
have_result_ = false; // auto-reset for next callback
return result_;
}
int GetResult(int result) { int GetResult(int result);
if (net::ERR_IO_PENDING != result)
return result;
return WaitForResult();
}
bool have_result() const { return have_result_; } bool have_result() const { return have_result_; }
virtual void RunWithParams(const Tuple1<int>& params) { virtual void RunWithParams(const Tuple1<int>& params);
result_ = params.a;
have_result_ = true;
if (waiting_for_result_)
MessageLoop::current()->Quit();
}
private: private:
int result_; int result_;
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
// Illustrates how to use worker threads that issue completion callbacks // Illustrates how to use worker threads that issue completion callbacks
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/task.h"
#include "base/threading/worker_pool.h" #include "base/threading/worker_pool.h"
#include "net/base/completion_callback.h" #include "net/base/completion_callback.h"
#include "net/base/test_completion_callback.h" #include "net/base/test_completion_callback.h"
......
...@@ -28,6 +28,11 @@ class HttpAuthHandlerRegistryFactory; ...@@ -28,6 +28,11 @@ class HttpAuthHandlerRegistryFactory;
// objects that it creates. // objects that it creates.
class HttpAuthHandlerFactory { class HttpAuthHandlerFactory {
public: public:
enum CreateReason {
CREATE_CHALLENGE, // Create a handler in response to a challenge.
CREATE_PREEMPTIVE, // Create a handler preemptively.
};
HttpAuthHandlerFactory() : url_security_manager_(NULL) {} HttpAuthHandlerFactory() : url_security_manager_(NULL) {}
virtual ~HttpAuthHandlerFactory() {} virtual ~HttpAuthHandlerFactory() {}
...@@ -42,11 +47,6 @@ class HttpAuthHandlerFactory { ...@@ -42,11 +47,6 @@ class HttpAuthHandlerFactory {
return url_security_manager_; return url_security_manager_;
} }
enum CreateReason {
CREATE_CHALLENGE, // Create a handler in response to a challenge.
CREATE_PREEMPTIVE, // Create a handler preemptively.
};
// Creates an HttpAuthHandler object based on the authentication // Creates an HttpAuthHandler object based on the authentication
// challenge specified by |*challenge|. |challenge| must point to a valid // challenge specified by |*challenge|. |challenge| must point to a valid
// non-NULL tokenizer. // non-NULL tokenizer.
......
...@@ -225,6 +225,7 @@ class HttpCache : public HttpTransactionFactory, ...@@ -225,6 +225,7 @@ class HttpCache : public HttpTransactionFactory,
typedef base::hash_map<std::string, ActiveEntry*> ActiveEntriesMap; typedef base::hash_map<std::string, ActiveEntry*> ActiveEntriesMap;
typedef base::hash_map<std::string, PendingOp*> PendingOpsMap; typedef base::hash_map<std::string, PendingOp*> PendingOpsMap;
typedef std::set<ActiveEntry*> ActiveEntriesSet; typedef std::set<ActiveEntry*> ActiveEntriesSet;
typedef base::hash_map<std::string, int> PlaybackCacheMap;
// Methods ------------------------------------------------------------------ // Methods ------------------------------------------------------------------
...@@ -371,7 +372,6 @@ class HttpCache : public HttpTransactionFactory, ...@@ -371,7 +372,6 @@ class HttpCache : public HttpTransactionFactory,
ScopedRunnableMethodFactory<HttpCache> task_factory_; ScopedRunnableMethodFactory<HttpCache> task_factory_;
typedef base::hash_map<std::string, int> PlaybackCacheMap;
scoped_ptr<PlaybackCacheMap> playback_cache_map_; scoped_ptr<PlaybackCacheMap> playback_cache_map_;
DISALLOW_COPY_AND_ASSIGN(HttpCache); DISALLOW_COPY_AND_ASSIGN(HttpCache);
......
...@@ -105,12 +105,11 @@ LoadState HttpProxyConnectJob::GetLoadState() const { ...@@ -105,12 +105,11 @@ LoadState HttpProxyConnectJob::GetLoadState() const {
} }
} }
int HttpProxyConnectJob::ConnectInternal() { void HttpProxyConnectJob::GetAdditionalErrorState(ClientSocketHandle * handle) {
if (params_->tcp_params()) if (error_response_info_.cert_request_info) {
next_state_ = STATE_TCP_CONNECT; handle->set_ssl_error_response_info(error_response_info_);
else handle->set_is_ssl_error(true);
next_state_ = STATE_SSL_CONNECT; }
return DoLoop(OK);
} }
void HttpProxyConnectJob::OnIOComplete(int result) { void HttpProxyConnectJob::OnIOComplete(int result) {
...@@ -248,11 +247,33 @@ int HttpProxyConnectJob::DoSSLConnectComplete(int result) { ...@@ -248,11 +247,33 @@ int HttpProxyConnectJob::DoSSLConnectComplete(int result) {
return result; return result;
} }
void HttpProxyConnectJob::GetAdditionalErrorState(ClientSocketHandle * handle) { int HttpProxyConnectJob::DoHttpProxyConnect() {
if (error_response_info_.cert_request_info) { next_state_ = STATE_HTTP_PROXY_CONNECT_COMPLETE;
handle->set_ssl_error_response_info(error_response_info_); const HostResolver::RequestInfo& tcp_destination = params_->destination();
handle->set_is_ssl_error(true); const HostPortPair& proxy_server = tcp_destination.host_port_pair();
// Add a HttpProxy connection on top of the tcp socket.
transport_socket_.reset(
new HttpProxyClientSocket(transport_socket_handle_.release(),
params_->request_url(),
params_->user_agent(),
params_->endpoint(),
proxy_server,
params_->http_auth_cache(),
params_->http_auth_handler_factory(),
params_->tunnel(),
using_spdy_,
params_->ssl_params() != NULL));
return transport_socket_->Connect(&callback_);
}
int HttpProxyConnectJob::DoHttpProxyConnectComplete(int result) {
if (result == OK || result == ERR_PROXY_AUTH_REQUESTED ||
result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) {
set_socket(transport_socket_.release());
} }
return result;
} }
int HttpProxyConnectJob::DoSpdyProxyCreateStream() { int HttpProxyConnectJob::DoSpdyProxyCreateStream() {
...@@ -303,33 +324,12 @@ int HttpProxyConnectJob::DoSpdyProxyCreateStreamComplete(int result) { ...@@ -303,33 +324,12 @@ int HttpProxyConnectJob::DoSpdyProxyCreateStreamComplete(int result) {
return transport_socket_->Connect(&callback_); return transport_socket_->Connect(&callback_);
} }
int HttpProxyConnectJob::DoHttpProxyConnect() { int HttpProxyConnectJob::ConnectInternal() {
next_state_ = STATE_HTTP_PROXY_CONNECT_COMPLETE; if (params_->tcp_params())
const HostResolver::RequestInfo& tcp_destination = params_->destination(); next_state_ = STATE_TCP_CONNECT;
const HostPortPair& proxy_server = tcp_destination.host_port_pair(); else
next_state_ = STATE_SSL_CONNECT;
// Add a HttpProxy connection on top of the tcp socket. return DoLoop(OK);
transport_socket_.reset(
new HttpProxyClientSocket(transport_socket_handle_.release(),
params_->request_url(),
params_->user_agent(),
params_->endpoint(),
proxy_server,
params_->http_auth_cache(),
params_->http_auth_handler_factory(),
params_->tunnel(),
using_spdy_,
params_->ssl_params() != NULL));
return transport_socket_->Connect(&callback_);
}
int HttpProxyConnectJob::DoHttpProxyConnectComplete(int result) {
if (result == OK || result == ERR_PROXY_AUTH_REQUESTED ||
result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) {
set_socket(transport_socket_.release());
}
return result;
} }
HttpProxyClientSocketPool:: HttpProxyClientSocketPool::
......
...@@ -123,15 +123,6 @@ class HttpProxyConnectJob : public ConnectJob { ...@@ -123,15 +123,6 @@ class HttpProxyConnectJob : public ConnectJob {
STATE_NONE, STATE_NONE,
}; };
// Begins the tcp connection and the optional Http proxy tunnel. If the
// request is not immediately servicable (likely), the request will return
// ERR_IO_PENDING. An OK return from this function or the callback means
// that the connection is established; ERR_PROXY_AUTH_REQUESTED means
// that the tunnel needs authentication credentials, the socket will be
// returned in this case, and must be release back to the pool; or
// a standard net error code will be returned.
virtual int ConnectInternal();
void OnIOComplete(int result); void OnIOComplete(int result);
// Runs the state transition loop. // Runs the state transition loop.
...@@ -150,6 +141,15 @@ class HttpProxyConnectJob : public ConnectJob { ...@@ -150,6 +141,15 @@ class HttpProxyConnectJob : public ConnectJob {
int DoSpdyProxyCreateStream(); int DoSpdyProxyCreateStream();
int DoSpdyProxyCreateStreamComplete(int result); int DoSpdyProxyCreateStreamComplete(int result);
// Begins the tcp connection and the optional Http proxy tunnel. If the
// request is not immediately servicable (likely), the request will return
// ERR_IO_PENDING. An OK return from this function or the callback means
// that the connection is established; ERR_PROXY_AUTH_REQUESTED means
// that the tunnel needs authentication credentials, the socket will be
// returned in this case, and must be release back to the pool; or
// a standard net error code will be returned.
virtual int ConnectInternal();
scoped_refptr<HttpProxySocketParams> params_; scoped_refptr<HttpProxySocketParams> params_;
TCPClientSocketPool* const tcp_pool_; TCPClientSocketPool* const tcp_pool_;
SSLClientSocketPool* const ssl_pool_; SSLClientSocketPool* const ssl_pool_;
......
...@@ -189,7 +189,6 @@ ...@@ -189,7 +189,6 @@
'base/transport_security_state.cc', 'base/transport_security_state.cc',
'base/transport_security_state.h', 'base/transport_security_state.h',
'base/sys_addrinfo.h', 'base/sys_addrinfo.h',
'base/test_completion_callback.h',
'base/upload_data.cc', 'base/upload_data.cc',
'base/upload_data.h', 'base/upload_data.h',
'base/upload_data_stream.cc', 'base/upload_data_stream.cc',
...@@ -1159,6 +1158,8 @@ ...@@ -1159,6 +1158,8 @@
'sources': [ 'sources': [
'base/cert_test_util.cc', 'base/cert_test_util.cc',
'base/cert_test_util.h', 'base/cert_test_util.h',
'base/test_completion_callback.cc',
'base/test_completion_callback.h',
'disk_cache/disk_cache_test_util.cc', 'disk_cache/disk_cache_test_util.cc',
'disk_cache/disk_cache_test_util.h', 'disk_cache/disk_cache_test_util.h',
'proxy/proxy_config_service_common_unittest.cc', 'proxy/proxy_config_service_common_unittest.cc',
...@@ -1422,6 +1423,7 @@ ...@@ -1422,6 +1423,7 @@
'type': 'executable', 'type': 'executable',
'dependencies': [ 'dependencies': [
'net', 'net',
'net_test_support',
'../base/base.gyp:base', '../base/base.gyp:base',
], ],
'sources': [ 'sources': [
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "net/proxy/multi_threaded_proxy_resolver.h" #include "net/proxy/multi_threaded_proxy_resolver.h"
#include "base/message_loop.h"
#include "base/stl_util-inl.h" #include "base/stl_util-inl.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
......
This diff is collapsed.
This diff is collapsed.
...@@ -75,11 +75,6 @@ LoadState SOCKSConnectJob::GetLoadState() const { ...@@ -75,11 +75,6 @@ LoadState SOCKSConnectJob::GetLoadState() const {
} }
} }
int SOCKSConnectJob::ConnectInternal() {
next_state_ = STATE_TCP_CONNECT;
return DoLoop(OK);
}
void SOCKSConnectJob::OnIOComplete(int result) { void SOCKSConnectJob::OnIOComplete(int result) {
int rv = DoLoop(result); int rv = DoLoop(result);
if (rv != ERR_IO_PENDING) if (rv != ERR_IO_PENDING)
...@@ -163,6 +158,11 @@ int SOCKSConnectJob::DoSOCKSConnectComplete(int result) { ...@@ -163,6 +158,11 @@ int SOCKSConnectJob::DoSOCKSConnectComplete(int result) {
return result; return result;
} }
int SOCKSConnectJob::ConnectInternal() {
next_state_ = STATE_TCP_CONNECT;
return DoLoop(OK);
}
ConnectJob* SOCKSClientSocketPool::SOCKSConnectJobFactory::NewConnectJob( ConnectJob* SOCKSClientSocketPool::SOCKSConnectJobFactory::NewConnectJob(
const std::string& group_name, const std::string& group_name,
const PoolBase::Request& request, const PoolBase::Request& request,
......
...@@ -75,11 +75,6 @@ class SOCKSConnectJob : public ConnectJob { ...@@ -75,11 +75,6 @@ class SOCKSConnectJob : public ConnectJob {
STATE_NONE, STATE_NONE,
}; };
// Begins the tcp connection and the SOCKS handshake. Returns OK on success
// and ERR_IO_PENDING if it cannot immediately service the request.
// Otherwise, it returns a net error code.
virtual int ConnectInternal();
void OnIOComplete(int result); void OnIOComplete(int result);
// Runs the state transition loop. // Runs the state transition loop.
...@@ -90,6 +85,11 @@ class SOCKSConnectJob : public ConnectJob { ...@@ -90,6 +85,11 @@ class SOCKSConnectJob : public ConnectJob {
int DoSOCKSConnect(); int DoSOCKSConnect();
int DoSOCKSConnectComplete(int result); int DoSOCKSConnectComplete(int result);
// Begins the tcp connection and the SOCKS handshake. Returns OK on success
// and ERR_IO_PENDING if it cannot immediately service the request.
// Otherwise, it returns a net error code.
virtual int ConnectInternal();
scoped_refptr<SOCKSSocketParams> socks_params_; scoped_refptr<SOCKSSocketParams> socks_params_;
TCPClientSocketPool* const tcp_pool_; TCPClientSocketPool* const tcp_pool_;
HostResolver* const resolver_; HostResolver* const resolver_;
......
...@@ -121,24 +121,16 @@ LoadState SSLConnectJob::GetLoadState() const { ...@@ -121,24 +121,16 @@ LoadState SSLConnectJob::GetLoadState() const {
} }
} }
int SSLConnectJob::ConnectInternal() { void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle * handle) {
switch (params_->proxy()) { // Headers in |error_response_info_| indicate a proxy tunnel setup
case ProxyServer::SCHEME_DIRECT: // problem. See DoTunnelConnectComplete.
next_state_ = STATE_TCP_CONNECT; if (error_response_info_.headers) {
break; handle->set_pending_http_proxy_connection(
case ProxyServer::SCHEME_HTTP: transport_socket_handle_.release());
case ProxyServer::SCHEME_HTTPS:
next_state_ = STATE_TUNNEL_CONNECT;
break;
case ProxyServer::SCHEME_SOCKS4:
case ProxyServer::SCHEME_SOCKS5:
next_state_ = STATE_SOCKS_CONNECT;
break;
default:
NOTREACHED() << "unknown proxy type";
break;
} }
return DoLoop(OK); handle->set_ssl_error_response_info(error_response_info_);
if (!ssl_connect_start_time_.is_null())
handle->set_is_ssl_error(true);
} }
void SSLConnectJob::OnIOComplete(int result) { void SSLConnectJob::OnIOComplete(int result) {
...@@ -276,18 +268,6 @@ int SSLConnectJob::DoTunnelConnectComplete(int result) { ...@@ -276,18 +268,6 @@ int SSLConnectJob::DoTunnelConnectComplete(int result) {
return result; return result;
} }
void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle * handle) {
// Headers in |error_response_info_| indicate a proxy tunnel setup
// problem. See DoTunnelConnectComplete.
if (error_response_info_.headers) {
handle->set_pending_http_proxy_connection(
transport_socket_handle_.release());
}
handle->set_ssl_error_response_info(error_response_info_);
if (!ssl_connect_start_time_.is_null())
handle->set_is_ssl_error(true);
}
int SSLConnectJob::DoSSLConnect() { int SSLConnectJob::DoSSLConnect() {
next_state_ = STATE_SSL_CONNECT_COMPLETE; next_state_ = STATE_SSL_CONNECT_COMPLETE;
// Reset the timeout to just the time allowed for the SSL handshake. // Reset the timeout to just the time allowed for the SSL handshake.
...@@ -361,15 +341,24 @@ int SSLConnectJob::DoSSLConnectComplete(int result) { ...@@ -361,15 +341,24 @@ int SSLConnectJob::DoSSLConnectComplete(int result) {
return result; return result;
} }
ConnectJob* SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob( int SSLConnectJob::ConnectInternal() {
const std::string& group_name, switch (params_->proxy()) {
const PoolBase::Request& request, case ProxyServer::SCHEME_DIRECT:
ConnectJob::Delegate* delegate) const { next_state_ = STATE_TCP_CONNECT;
return new SSLConnectJob(group_name, request.params(), ConnectionTimeout(), break;
tcp_pool_, socks_pool_, http_proxy_pool_, case ProxyServer::SCHEME_HTTP:
client_socket_factory_, host_resolver_, case ProxyServer::SCHEME_HTTPS:
cert_verifier_, dnsrr_resolver_, dns_cert_checker_, next_state_ = STATE_TUNNEL_CONNECT;
ssl_host_info_factory_, delegate, net_log_); break;
case ProxyServer::SCHEME_SOCKS4:
case ProxyServer::SCHEME_SOCKS5:
next_state_ = STATE_SOCKS_CONNECT;
break;
default:
NOTREACHED() << "unknown proxy type";
break;
}
return DoLoop(OK);
} }
SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory( SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory(
...@@ -448,6 +437,17 @@ SSLClientSocketPool::~SSLClientSocketPool() { ...@@ -448,6 +437,17 @@ SSLClientSocketPool::~SSLClientSocketPool() {
ssl_config_service_->RemoveObserver(this); ssl_config_service_->RemoveObserver(this);
} }
ConnectJob* SSLClientSocketPool::SSLConnectJobFactory::NewConnectJob(
const std::string& group_name,
const PoolBase::Request& request,
ConnectJob::Delegate* delegate) const {
return new SSLConnectJob(group_name, request.params(), ConnectionTimeout(),
tcp_pool_, socks_pool_, http_proxy_pool_,
client_socket_factory_, host_resolver_,
cert_verifier_, dnsrr_resolver_, dns_cert_checker_,
ssl_host_info_factory_, delegate, net_log_);
}
int SSLClientSocketPool::RequestSocket(const std::string& group_name, int SSLClientSocketPool::RequestSocket(const std::string& group_name,
const void* socket_params, const void* socket_params,
RequestPriority priority, RequestPriority priority,
...@@ -504,10 +504,6 @@ LoadState SSLClientSocketPool::GetLoadState( ...@@ -504,10 +504,6 @@ LoadState SSLClientSocketPool::GetLoadState(
return base_.GetLoadState(group_name, handle); return base_.GetLoadState(group_name, handle);
} }
void SSLClientSocketPool::OnSSLConfigChanged() {
Flush();
}
DictionaryValue* SSLClientSocketPool::GetInfoAsValue( DictionaryValue* SSLClientSocketPool::GetInfoAsValue(
const std::string& name, const std::string& name,
const std::string& type, const std::string& type,
...@@ -543,4 +539,8 @@ ClientSocketPoolHistograms* SSLClientSocketPool::histograms() const { ...@@ -543,4 +539,8 @@ ClientSocketPoolHistograms* SSLClientSocketPool::histograms() const {
return base_.histograms(); return base_.histograms();
} }
void SSLClientSocketPool::OnSSLConfigChanged() {
Flush();
}
} // namespace net } // namespace net
...@@ -122,11 +122,6 @@ class SSLConnectJob : public ConnectJob { ...@@ -122,11 +122,6 @@ class SSLConnectJob : public ConnectJob {
STATE_NONE, STATE_NONE,
}; };
// Starts the SSL connection process. Returns OK on success and
// ERR_IO_PENDING if it cannot immediately service the request.
// Otherwise, it returns a net error code.
virtual int ConnectInternal();
void OnIOComplete(int result); void OnIOComplete(int result);
// Runs the state transition loop. // Runs the state transition loop.
...@@ -141,6 +136,11 @@ class SSLConnectJob : public ConnectJob { ...@@ -141,6 +136,11 @@ class SSLConnectJob : public ConnectJob {
int DoSSLConnect(); int DoSSLConnect();
int DoSSLConnectComplete(int result); int DoSSLConnectComplete(int result);
// Starts the SSL connection process. Returns OK on success and
// ERR_IO_PENDING if it cannot immediately service the request.
// Otherwise, it returns a net error code.
virtual int ConnectInternal();
scoped_refptr<SSLSocketParams> params_; scoped_refptr<SSLSocketParams> params_;
TCPClientSocketPool* const tcp_pool_; TCPClientSocketPool* const tcp_pool_;
SOCKSClientSocketPool* const socks_pool_; SOCKSClientSocketPool* const socks_pool_;
......
...@@ -200,28 +200,19 @@ class SpdySession : public base::RefCounted<SpdySession>, ...@@ -200,28 +200,19 @@ class SpdySession : public base::RefCounted<SpdySession>,
friend class base::RefCounted<SpdySession>; friend class base::RefCounted<SpdySession>;
FRIEND_TEST_ALL_PREFIXES(SpdySessionTest, GetActivePushStream); FRIEND_TEST_ALL_PREFIXES(SpdySessionTest, GetActivePushStream);
enum State {
IDLE,
CONNECTING,
CONNECTED,
CLOSED
};
enum { kDefaultMaxConcurrentStreams = 10 };
struct PendingCreateStream { struct PendingCreateStream {
const GURL* url;
RequestPriority priority;
scoped_refptr<SpdyStream>* spdy_stream;
const BoundNetLog* stream_net_log;
CompletionCallback* callback;
PendingCreateStream(const GURL& url, RequestPriority priority, PendingCreateStream(const GURL& url, RequestPriority priority,
scoped_refptr<SpdyStream>* spdy_stream, scoped_refptr<SpdyStream>* spdy_stream,
const BoundNetLog& stream_net_log, const BoundNetLog& stream_net_log,
CompletionCallback* callback) CompletionCallback* callback)
: url(&url), priority(priority), spdy_stream(spdy_stream), : url(&url), priority(priority), spdy_stream(spdy_stream),
stream_net_log(&stream_net_log), callback(callback) { } stream_net_log(&stream_net_log), callback(callback) { }
const GURL* url;
RequestPriority priority;
scoped_refptr<SpdyStream>* spdy_stream;
const BoundNetLog* stream_net_log;
CompletionCallback* callback;
}; };
typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> > typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> >
PendingCreateStreamQueue; PendingCreateStreamQueue;
...@@ -242,6 +233,15 @@ class SpdySession : public base::RefCounted<SpdySession>, ...@@ -242,6 +233,15 @@ class SpdySession : public base::RefCounted<SpdySession>,
typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair> typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair>
PendingCallbackMap; PendingCallbackMap;
enum State {
IDLE,
CONNECTING,
CONNECTED,
CLOSED
};
enum { kDefaultMaxConcurrentStreams = 10 };
virtual ~SpdySession(); virtual ~SpdySession();
void ProcessPendingCreateStreams(); void ProcessPendingCreateStreams();
...@@ -251,13 +251,6 @@ class SpdySession : public base::RefCounted<SpdySession>, ...@@ -251,13 +251,6 @@ class SpdySession : public base::RefCounted<SpdySession>,
scoped_refptr<SpdyStream>* spdy_stream, scoped_refptr<SpdyStream>* spdy_stream,
const BoundNetLog& stream_net_log); const BoundNetLog& stream_net_log);
// SpdyFramerVisitorInterface
virtual void OnError(spdy::SpdyFramer*);
virtual void OnStreamFrameData(spdy::SpdyStreamId stream_id,
const char* data,
size_t len);
virtual void OnControl(const spdy::SpdyControlFrame* frame);
// Control frame handlers. // Control frame handlers.
void OnSyn(const spdy::SpdySynStreamControlFrame& frame, void OnSyn(const spdy::SpdySynStreamControlFrame& frame,
const linked_ptr<spdy::SpdyHeaderBlock>& headers); const linked_ptr<spdy::SpdyHeaderBlock>& headers);
...@@ -325,6 +318,13 @@ class SpdySession : public base::RefCounted<SpdySession>, ...@@ -325,6 +318,13 @@ class SpdySession : public base::RefCounted<SpdySession>,
// can be deferred to the MessageLoop, so we avoid re-entrancy problems. // can be deferred to the MessageLoop, so we avoid re-entrancy problems.
void InvokeUserStreamCreationCallback(scoped_refptr<SpdyStream>* stream); void InvokeUserStreamCreationCallback(scoped_refptr<SpdyStream>* stream);
// SpdyFramerVisitorInterface:
virtual void OnError(spdy::SpdyFramer*);
virtual void OnStreamFrameData(spdy::SpdyStreamId stream_id,
const char* data,
size_t len);
virtual void OnControl(const spdy::SpdyControlFrame* frame);
// Callbacks for the Spdy session. // Callbacks for the Spdy session.
CompletionCallbackImpl<SpdySession> read_callback_; CompletionCallbackImpl<SpdySession> read_callback_;
CompletionCallbackImpl<SpdySession> write_callback_; CompletionCallbackImpl<SpdySession> write_callback_;
...@@ -439,12 +439,12 @@ class NetLogSpdySynParameter : public NetLog::EventParameters { ...@@ -439,12 +439,12 @@ class NetLogSpdySynParameter : public NetLog::EventParameters {
spdy::SpdyStreamId id, spdy::SpdyStreamId id,
spdy::SpdyStreamId associated_stream); spdy::SpdyStreamId associated_stream);
virtual Value* ToValue() const;
const linked_ptr<spdy::SpdyHeaderBlock>& GetHeaders() const { const linked_ptr<spdy::SpdyHeaderBlock>& GetHeaders() const {
return headers_; return headers_;
} }
virtual Value* ToValue() const;
private: private:
virtual ~NetLogSpdySynParameter(); virtual ~NetLogSpdySynParameter();
......
...@@ -852,6 +852,102 @@ int CombineFrames(const spdy::SpdyFrame** frames, int num_frames, ...@@ -852,6 +852,102 @@ int CombineFrames(const spdy::SpdyFrame** frames, int num_frames,
return total_len; return total_len;
} }
SpdySessionDependencies::SpdySessionDependencies()
: host_resolver(new MockHostResolver),
cert_verifier(new CertVerifier),
proxy_service(ProxyService::CreateDirect()),
ssl_config_service(new SSLConfigServiceDefaults),
socket_factory(new MockClientSocketFactory),
deterministic_socket_factory(new DeterministicMockClientSocketFactory),
http_auth_handler_factory(
HttpAuthHandlerFactory::CreateDefault(host_resolver.get())) {
// Note: The CancelledTransaction test does cleanup by running all
// tasks in the message loop (RunAllPending). Unfortunately, that
// doesn't clean up tasks on the host resolver thread; and
// TCPConnectJob is currently not cancellable. Using synchronous
// lookups allows the test to shutdown cleanly. Until we have
// cancellable TCPConnectJobs, use synchronous lookups.
host_resolver->set_synchronous_mode(true);
}
SpdySessionDependencies::SpdySessionDependencies(ProxyService* proxy_service)
: host_resolver(new MockHostResolver),
cert_verifier(new CertVerifier),
proxy_service(proxy_service),
ssl_config_service(new SSLConfigServiceDefaults),
socket_factory(new MockClientSocketFactory),
deterministic_socket_factory(new DeterministicMockClientSocketFactory),
http_auth_handler_factory(
HttpAuthHandlerFactory::CreateDefault(host_resolver.get())) {}
SpdySessionDependencies::~SpdySessionDependencies() {}
// static
HttpNetworkSession* SpdySessionDependencies::SpdyCreateSession(
SpdySessionDependencies* session_deps) {
return new HttpNetworkSession(session_deps->host_resolver.get(),
session_deps->cert_verifier.get(),
NULL /* dnsrr_resolver */,
NULL /* dns_cert_checker */,
NULL /* ssl_host_info_factory */,
session_deps->proxy_service,
session_deps->socket_factory.get(),
session_deps->ssl_config_service,
new SpdySessionPool(NULL),
session_deps->http_auth_handler_factory.get(),
NULL,
NULL);
}
// static
HttpNetworkSession* SpdySessionDependencies::SpdyCreateSessionDeterministic(
SpdySessionDependencies* session_deps) {
return new HttpNetworkSession(session_deps->host_resolver.get(),
session_deps->cert_verifier.get(),
NULL /* dnsrr_resolver */,
NULL /* dns_cert_checker */,
NULL /* ssl_host_info_factory */,
session_deps->proxy_service,
session_deps->
deterministic_socket_factory.get(),
session_deps->ssl_config_service,
new SpdySessionPool(NULL),
session_deps->http_auth_handler_factory.get(),
NULL,
NULL);
}
SpdyURLRequestContext::SpdyURLRequestContext() {
host_resolver_ = new MockHostResolver();
cert_verifier_ = new CertVerifier;
proxy_service_ = ProxyService::CreateDirect();
ssl_config_service_ = new SSLConfigServiceDefaults;
http_auth_handler_factory_ = HttpAuthHandlerFactory::CreateDefault(
host_resolver_);
http_transaction_factory_ = new HttpCache(
new HttpNetworkLayer(&socket_factory_,
host_resolver_,
cert_verifier_,
NULL /* dnsrr_resolver */,
NULL /* dns_cert_checker */,
NULL /* ssl_host_info_factory */,
proxy_service_,
ssl_config_service_,
new SpdySessionPool(NULL),
http_auth_handler_factory_,
network_delegate_,
NULL),
NULL /* net_log */,
HttpCache::DefaultBackend::InMemory(0));
}
SpdyURLRequestContext::~SpdyURLRequestContext() {
delete http_transaction_factory_;
delete http_auth_handler_factory_;
delete cert_verifier_;
delete host_resolver_;
}
const SpdyHeaderInfo make_spdy_header(spdy::SpdyControlType type) { const SpdyHeaderInfo make_spdy_header(spdy::SpdyControlType type) {
const SpdyHeaderInfo kHeader = { const SpdyHeaderInfo kHeader = {
type, // Kind = Syn type, // Kind = Syn
......
...@@ -326,34 +326,17 @@ int CombineFrames(const spdy::SpdyFrame** frames, int num_frames, ...@@ -326,34 +326,17 @@ int CombineFrames(const spdy::SpdyFrame** frames, int num_frames,
class SpdySessionDependencies { class SpdySessionDependencies {
public: public:
// Default set of dependencies -- "null" proxy service. // Default set of dependencies -- "null" proxy service.
SpdySessionDependencies() SpdySessionDependencies();
: host_resolver(new MockHostResolver),
cert_verifier(new CertVerifier),
proxy_service(ProxyService::CreateDirect()),
ssl_config_service(new SSLConfigServiceDefaults),
socket_factory(new MockClientSocketFactory),
deterministic_socket_factory(new DeterministicMockClientSocketFactory),
http_auth_handler_factory(
HttpAuthHandlerFactory::CreateDefault(host_resolver.get())) {
// Note: The CancelledTransaction test does cleanup by running all
// tasks in the message loop (RunAllPending). Unfortunately, that
// doesn't clean up tasks on the host resolver thread; and
// TCPConnectJob is currently not cancellable. Using synchronous
// lookups allows the test to shutdown cleanly. Until we have
// cancellable TCPConnectJobs, use synchronous lookups.
host_resolver->set_synchronous_mode(true);
}
// Custom proxy service dependency. // Custom proxy service dependency.
explicit SpdySessionDependencies(ProxyService* proxy_service) explicit SpdySessionDependencies(ProxyService* proxy_service);
: host_resolver(new MockHostResolver),
cert_verifier(new CertVerifier), ~SpdySessionDependencies();
proxy_service(proxy_service),
ssl_config_service(new SSLConfigServiceDefaults), static HttpNetworkSession* SpdyCreateSession(
socket_factory(new MockClientSocketFactory), SpdySessionDependencies* session_deps);
deterministic_socket_factory(new DeterministicMockClientSocketFactory), static HttpNetworkSession* SpdyCreateSessionDeterministic(
http_auth_handler_factory( SpdySessionDependencies* session_deps);
HttpAuthHandlerFactory::CreateDefault(host_resolver.get())) {}
// NOTE: host_resolver must be ordered before http_auth_handler_factory. // NOTE: host_resolver must be ordered before http_auth_handler_factory.
scoped_ptr<MockHostResolverBase> host_resolver; scoped_ptr<MockHostResolverBase> host_resolver;
...@@ -363,75 +346,16 @@ class SpdySessionDependencies { ...@@ -363,75 +346,16 @@ class SpdySessionDependencies {
scoped_ptr<MockClientSocketFactory> socket_factory; scoped_ptr<MockClientSocketFactory> socket_factory;
scoped_ptr<DeterministicMockClientSocketFactory> deterministic_socket_factory; scoped_ptr<DeterministicMockClientSocketFactory> deterministic_socket_factory;
scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory;
static HttpNetworkSession* SpdyCreateSession(
SpdySessionDependencies* session_deps) {
return new HttpNetworkSession(session_deps->host_resolver.get(),
session_deps->cert_verifier.get(),
NULL /* dnsrr_resolver */,
NULL /* dns_cert_checker */,
NULL /* ssl_host_info_factory */,
session_deps->proxy_service,
session_deps->socket_factory.get(),
session_deps->ssl_config_service,
new SpdySessionPool(NULL),
session_deps->http_auth_handler_factory.get(),
NULL,
NULL);
}
static HttpNetworkSession* SpdyCreateSessionDeterministic(
SpdySessionDependencies* session_deps) {
return new HttpNetworkSession(session_deps->host_resolver.get(),
session_deps->cert_verifier.get(),
NULL /* dnsrr_resolver */,
NULL /* dns_cert_checker */,
NULL /* ssl_host_info_factory */,
session_deps->proxy_service,
session_deps->
deterministic_socket_factory.get(),
session_deps->ssl_config_service,
new SpdySessionPool(NULL),
session_deps->http_auth_handler_factory.get(),
NULL,
NULL);
}
}; };
class SpdyURLRequestContext : public URLRequestContext { class SpdyURLRequestContext : public URLRequestContext {
public: public:
SpdyURLRequestContext() { SpdyURLRequestContext();
host_resolver_ = new MockHostResolver();
cert_verifier_ = new CertVerifier;
proxy_service_ = ProxyService::CreateDirect();
ssl_config_service_ = new SSLConfigServiceDefaults;
http_auth_handler_factory_ = HttpAuthHandlerFactory::CreateDefault(
host_resolver_);
http_transaction_factory_ = new HttpCache(
new HttpNetworkLayer(&socket_factory_,
host_resolver_,
cert_verifier_,
NULL /* dnsrr_resolver */,
NULL /* dns_cert_checker */,
NULL /* ssl_host_info_factory */,
proxy_service_,
ssl_config_service_,
new SpdySessionPool(NULL),
http_auth_handler_factory_,
network_delegate_,
NULL),
NULL /* net_log */,
HttpCache::DefaultBackend::InMemory(0));
}
MockClientSocketFactory& socket_factory() { return socket_factory_; } MockClientSocketFactory& socket_factory() { return socket_factory_; }
protected: protected:
virtual ~SpdyURLRequestContext() { virtual ~SpdyURLRequestContext();
delete http_transaction_factory_;
delete http_auth_handler_factory_;
delete cert_verifier_;
delete host_resolver_;
}
private: private:
MockClientSocketFactory socket_factory_; MockClientSocketFactory socket_factory_;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "net/base/host_port_pair.h" #include "net/base/host_port_pair.h"
#include "net/base/host_resolver.h" #include "net/base/host_resolver.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h" #include "net/base/test_completion_callback.h"
#include "net/base/test_root_certs.h" #include "net/base/test_root_certs.h"
#include "net/socket/tcp_client_socket.h" #include "net/socket/tcp_client_socket.h"
......
...@@ -35,6 +35,8 @@ class AddressList; ...@@ -35,6 +35,8 @@ class AddressList;
// that can provide various responses useful for testing. // that can provide various responses useful for testing.
class TestServer { class TestServer {
public: public:
typedef std::pair<std::string, std::string> StringPair;
enum Type { enum Type {
TYPE_FTP, TYPE_FTP,
TYPE_HTTP, TYPE_HTTP,
...@@ -126,7 +128,6 @@ class TestServer { ...@@ -126,7 +128,6 @@ class TestServer {
const std::string& user, const std::string& user,
const std::string& password) const; const std::string& password) const;
typedef std::pair<std::string, std::string> StringPair;
static bool GetFilePathWithReplacements( static bool GetFilePathWithReplacements(
const std::string& original_path, const std::string& original_path,
const std::vector<StringPair>& text_to_replace, const std::vector<StringPair>& text_to_replace,
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/win/scoped_handle.h" #include "base/win/scoped_handle.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h" #include "net/base/test_completion_callback.h"
#include "net/disk_cache/backend_impl.h" #include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/entry_impl.h" #include "net/disk_cache/entry_impl.h"
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "net/url_request/view_cache_helper.h" #include "net/url_request/view_cache_helper.h"
#include "base/pickle.h" #include "base/pickle.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h" #include "net/base/test_completion_callback.h"
#include "net/disk_cache/disk_cache.h" #include "net/disk_cache/disk_cache.h"
#include "net/http/http_cache.h" #include "net/http/http_cache.h"
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/scoped_temp_dir.h" #include "base/scoped_temp_dir.h"
#include "base/time.h" #include "base/time.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h" #include "net/base/test_completion_callback.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "webkit/database/database_tracker.h" #include "webkit/database/database_tracker.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment