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 @@
#include "base/callback.h"
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/platform_file.h"
#include "net/base/file_stream.h"
......
......@@ -51,12 +51,14 @@
namespace net {
static const int kExceptionRule = 1;
static const int kWildcardRule = 2;
namespace {
RegistryControlledDomainService::RegistryControlledDomainService()
: find_domain_function_(Perfect_Hash::FindDomain) {
}
const int kExceptionRule = 1;
const int kWildcardRule = 2;
RegistryControlledDomainService* test_instance_;
} // namespace
// static
std::string RegistryControlledDomainService::GetDomainAndRegistry(
......@@ -154,6 +156,34 @@ size_t RegistryControlledDomainService::GetRegistryLength(
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
std::string RegistryControlledDomainService::GetDomainAndRegistryImpl(
const std::string& host) {
......@@ -261,30 +291,4 @@ size_t RegistryControlledDomainService::GetRegistryLengthImpl(
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
// 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 @@
#pragma once
#include "base/callback.h"
#include "base/message_loop.h"
#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
//-----------------------------------------------------------------------------
// completion callback helper
......@@ -24,37 +21,16 @@
//
class TestCompletionCallback : public CallbackRunner< Tuple1<int> > {
public:
TestCompletionCallback()
: result_(0),
have_result_(false),
waiting_for_result_(false) {
}
TestCompletionCallback();
virtual ~TestCompletionCallback();
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 WaitForResult();
int GetResult(int result) {
if (net::ERR_IO_PENDING != result)
return result;
return WaitForResult();
}
int GetResult(int result);
bool have_result() const { return have_result_; }
virtual void RunWithParams(const Tuple1<int>& params) {
result_ = params.a;
have_result_ = true;
if (waiting_for_result_)
MessageLoop::current()->Quit();
}
virtual void RunWithParams(const Tuple1<int>& params);
private:
int result_;
......
......@@ -4,6 +4,9 @@
// 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 "net/base/completion_callback.h"
#include "net/base/test_completion_callback.h"
......
......@@ -28,6 +28,11 @@ class HttpAuthHandlerRegistryFactory;
// objects that it creates.
class HttpAuthHandlerFactory {
public:
enum CreateReason {
CREATE_CHALLENGE, // Create a handler in response to a challenge.
CREATE_PREEMPTIVE, // Create a handler preemptively.
};
HttpAuthHandlerFactory() : url_security_manager_(NULL) {}
virtual ~HttpAuthHandlerFactory() {}
......@@ -42,11 +47,6 @@ class HttpAuthHandlerFactory {
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
// challenge specified by |*challenge|. |challenge| must point to a valid
// non-NULL tokenizer.
......
......@@ -225,6 +225,7 @@ class HttpCache : public HttpTransactionFactory,
typedef base::hash_map<std::string, ActiveEntry*> ActiveEntriesMap;
typedef base::hash_map<std::string, PendingOp*> PendingOpsMap;
typedef std::set<ActiveEntry*> ActiveEntriesSet;
typedef base::hash_map<std::string, int> PlaybackCacheMap;
// Methods ------------------------------------------------------------------
......@@ -371,7 +372,6 @@ class HttpCache : public HttpTransactionFactory,
ScopedRunnableMethodFactory<HttpCache> task_factory_;
typedef base::hash_map<std::string, int> PlaybackCacheMap;
scoped_ptr<PlaybackCacheMap> playback_cache_map_;
DISALLOW_COPY_AND_ASSIGN(HttpCache);
......
......@@ -105,12 +105,11 @@ LoadState HttpProxyConnectJob::GetLoadState() const {
}
}
int HttpProxyConnectJob::ConnectInternal() {
if (params_->tcp_params())
next_state_ = STATE_TCP_CONNECT;
else
next_state_ = STATE_SSL_CONNECT;
return DoLoop(OK);
void HttpProxyConnectJob::GetAdditionalErrorState(ClientSocketHandle * handle) {
if (error_response_info_.cert_request_info) {
handle->set_ssl_error_response_info(error_response_info_);
handle->set_is_ssl_error(true);
}
}
void HttpProxyConnectJob::OnIOComplete(int result) {
......@@ -248,11 +247,33 @@ int HttpProxyConnectJob::DoSSLConnectComplete(int result) {
return result;
}
void HttpProxyConnectJob::GetAdditionalErrorState(ClientSocketHandle * handle) {
if (error_response_info_.cert_request_info) {
handle->set_ssl_error_response_info(error_response_info_);
handle->set_is_ssl_error(true);
int HttpProxyConnectJob::DoHttpProxyConnect() {
next_state_ = STATE_HTTP_PROXY_CONNECT_COMPLETE;
const HostResolver::RequestInfo& tcp_destination = params_->destination();
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() {
......@@ -303,33 +324,12 @@ int HttpProxyConnectJob::DoSpdyProxyCreateStreamComplete(int result) {
return transport_socket_->Connect(&callback_);
}
int HttpProxyConnectJob::DoHttpProxyConnect() {
next_state_ = STATE_HTTP_PROXY_CONNECT_COMPLETE;
const HostResolver::RequestInfo& tcp_destination = params_->destination();
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::ConnectInternal() {
if (params_->tcp_params())
next_state_ = STATE_TCP_CONNECT;
else
next_state_ = STATE_SSL_CONNECT;
return DoLoop(OK);
}
HttpProxyClientSocketPool::
......
......@@ -123,15 +123,6 @@ class HttpProxyConnectJob : public ConnectJob {
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);
// Runs the state transition loop.
......@@ -150,6 +141,15 @@ class HttpProxyConnectJob : public ConnectJob {
int DoSpdyProxyCreateStream();
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_;
TCPClientSocketPool* const tcp_pool_;
SSLClientSocketPool* const ssl_pool_;
......
......@@ -189,7 +189,6 @@
'base/transport_security_state.cc',
'base/transport_security_state.h',
'base/sys_addrinfo.h',
'base/test_completion_callback.h',
'base/upload_data.cc',
'base/upload_data.h',
'base/upload_data_stream.cc',
......@@ -1159,6 +1158,8 @@
'sources': [
'base/cert_test_util.cc',
'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.h',
'proxy/proxy_config_service_common_unittest.cc',
......@@ -1422,6 +1423,7 @@
'type': 'executable',
'dependencies': [
'net',
'net_test_support',
'../base/base.gyp:base',
],
'sources': [
......
......@@ -4,6 +4,7 @@
#include "net/proxy/multi_threaded_proxy_resolver.h"
#include "base/message_loop.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
......
This diff is collapsed.
This diff is collapsed.
......@@ -75,11 +75,6 @@ LoadState SOCKSConnectJob::GetLoadState() const {
}
}
int SOCKSConnectJob::ConnectInternal() {
next_state_ = STATE_TCP_CONNECT;
return DoLoop(OK);
}
void SOCKSConnectJob::OnIOComplete(int result) {
int rv = DoLoop(result);
if (rv != ERR_IO_PENDING)
......@@ -163,6 +158,11 @@ int SOCKSConnectJob::DoSOCKSConnectComplete(int result) {
return result;
}
int SOCKSConnectJob::ConnectInternal() {
next_state_ = STATE_TCP_CONNECT;
return DoLoop(OK);
}
ConnectJob* SOCKSClientSocketPool::SOCKSConnectJobFactory::NewConnectJob(
const std::string& group_name,
const PoolBase::Request& request,
......
......@@ -75,11 +75,6 @@ class SOCKSConnectJob : public ConnectJob {
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);
// Runs the state transition loop.
......@@ -90,6 +85,11 @@ class SOCKSConnectJob : public ConnectJob {
int DoSOCKSConnect();
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_;
TCPClientSocketPool* const tcp_pool_;
HostResolver* const resolver_;
......
......@@ -121,24 +121,16 @@ LoadState SSLConnectJob::GetLoadState() const {
}
}
int SSLConnectJob::ConnectInternal() {
switch (params_->proxy()) {
case ProxyServer::SCHEME_DIRECT:
next_state_ = STATE_TCP_CONNECT;
break;
case ProxyServer::SCHEME_HTTP:
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;
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());
}
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) {
......@@ -276,18 +268,6 @@ int SSLConnectJob::DoTunnelConnectComplete(int 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() {
next_state_ = STATE_SSL_CONNECT_COMPLETE;
// Reset the timeout to just the time allowed for the SSL handshake.
......@@ -361,15 +341,24 @@ int SSLConnectJob::DoSSLConnectComplete(int result) {
return result;
}
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 SSLConnectJob::ConnectInternal() {
switch (params_->proxy()) {
case ProxyServer::SCHEME_DIRECT:
next_state_ = STATE_TCP_CONNECT;
break;
case ProxyServer::SCHEME_HTTP:
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);
}
SSLClientSocketPool::SSLConnectJobFactory::SSLConnectJobFactory(
......@@ -448,6 +437,17 @@ SSLClientSocketPool::~SSLClientSocketPool() {
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,
const void* socket_params,
RequestPriority priority,
......@@ -504,10 +504,6 @@ LoadState SSLClientSocketPool::GetLoadState(
return base_.GetLoadState(group_name, handle);
}
void SSLClientSocketPool::OnSSLConfigChanged() {
Flush();
}
DictionaryValue* SSLClientSocketPool::GetInfoAsValue(
const std::string& name,
const std::string& type,
......@@ -543,4 +539,8 @@ ClientSocketPoolHistograms* SSLClientSocketPool::histograms() const {
return base_.histograms();
}
void SSLClientSocketPool::OnSSLConfigChanged() {
Flush();
}
} // namespace net
......@@ -122,11 +122,6 @@ class SSLConnectJob : public ConnectJob {
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);
// Runs the state transition loop.
......@@ -141,6 +136,11 @@ class SSLConnectJob : public ConnectJob {
int DoSSLConnect();
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_;
TCPClientSocketPool* const tcp_pool_;
SOCKSClientSocketPool* const socks_pool_;
......
......@@ -200,28 +200,19 @@ class SpdySession : public base::RefCounted<SpdySession>,
friend class base::RefCounted<SpdySession>;
FRIEND_TEST_ALL_PREFIXES(SpdySessionTest, GetActivePushStream);
enum State {
IDLE,
CONNECTING,
CONNECTED,
CLOSED
};
enum { kDefaultMaxConcurrentStreams = 10 };
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,
scoped_refptr<SpdyStream>* spdy_stream,
const BoundNetLog& stream_net_log,
CompletionCallback* callback)
: url(&url), priority(priority), spdy_stream(spdy_stream),
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> >
PendingCreateStreamQueue;
......@@ -242,6 +233,15 @@ class SpdySession : public base::RefCounted<SpdySession>,
typedef std::map<const scoped_refptr<SpdyStream>*, CallbackResultPair>
PendingCallbackMap;
enum State {
IDLE,
CONNECTING,
CONNECTED,
CLOSED
};
enum { kDefaultMaxConcurrentStreams = 10 };
virtual ~SpdySession();
void ProcessPendingCreateStreams();
......@@ -251,13 +251,6 @@ class SpdySession : public base::RefCounted<SpdySession>,
scoped_refptr<SpdyStream>* spdy_stream,
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.
void OnSyn(const spdy::SpdySynStreamControlFrame& frame,
const linked_ptr<spdy::SpdyHeaderBlock>& headers);
......@@ -325,6 +318,13 @@ class SpdySession : public base::RefCounted<SpdySession>,
// can be deferred to the MessageLoop, so we avoid re-entrancy problems.
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.
CompletionCallbackImpl<SpdySession> read_callback_;
CompletionCallbackImpl<SpdySession> write_callback_;
......@@ -439,12 +439,12 @@ class NetLogSpdySynParameter : public NetLog::EventParameters {
spdy::SpdyStreamId id,
spdy::SpdyStreamId associated_stream);
virtual Value* ToValue() const;
const linked_ptr<spdy::SpdyHeaderBlock>& GetHeaders() const {
return headers_;
}
virtual Value* ToValue() const;
private:
virtual ~NetLogSpdySynParameter();
......
......@@ -852,6 +852,102 @@ int CombineFrames(const spdy::SpdyFrame** frames, int num_frames,
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 kHeader = {
type, // Kind = Syn
......
......@@ -326,34 +326,17 @@ int CombineFrames(const spdy::SpdyFrame** frames, int num_frames,
class SpdySessionDependencies {
public:
// Default set of dependencies -- "null" proxy service.
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();
// Custom proxy service dependency.
explicit 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())) {}
explicit SpdySessionDependencies(ProxyService* proxy_service);
~SpdySessionDependencies();
static HttpNetworkSession* SpdyCreateSession(
SpdySessionDependencies* session_deps);
static HttpNetworkSession* SpdyCreateSessionDeterministic(
SpdySessionDependencies* session_deps);
// NOTE: host_resolver must be ordered before http_auth_handler_factory.
scoped_ptr<MockHostResolverBase> host_resolver;
......@@ -363,75 +346,16 @@ class SpdySessionDependencies {
scoped_ptr<MockClientSocketFactory> socket_factory;
scoped_ptr<DeterministicMockClientSocketFactory> deterministic_socket_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 {
public:
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();
MockClientSocketFactory& socket_factory() { return socket_factory_; }
protected:
virtual ~SpdyURLRequestContext() {
delete http_transaction_factory_;
delete http_auth_handler_factory_;
delete cert_verifier_;
delete host_resolver_;
}
virtual ~SpdyURLRequestContext();
private:
MockClientSocketFactory socket_factory_;
......
......@@ -28,6 +28,7 @@
#include "googleurl/src/gurl.h"
#include "net/base/host_port_pair.h"
#include "net/base/host_resolver.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/base/test_root_certs.h"
#include "net/socket/tcp_client_socket.h"
......
......@@ -35,6 +35,8 @@ class AddressList;
// that can provide various responses useful for testing.
class TestServer {
public:
typedef std::pair<std::string, std::string> StringPair;
enum Type {
TYPE_FTP,
TYPE_HTTP,
......@@ -126,7 +128,6 @@ class TestServer {
const std::string& user,
const std::string& password) const;
typedef std::pair<std::string, std::string> StringPair;
static bool GetFilePathWithReplacements(
const std::string& original_path,
const std::vector<StringPair>& text_to_replace,
......
......@@ -12,6 +12,7 @@
#include "base/win/scoped_handle.h"
#include "googleurl/src/gurl.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/entry_impl.h"
......
......@@ -5,6 +5,7 @@
#include "net/url_request/view_cache_helper.h"
#include "base/pickle.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/disk_cache/disk_cache.h"
#include "net/http/http_cache.h"
......
......@@ -8,6 +8,7 @@
#include "base/scoped_temp_dir.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "testing/gtest/include/gtest/gtest.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