diff options
Diffstat (limited to 'net')
33 files changed, 315 insertions, 187 deletions
diff --git a/net/base/net_log.cc b/net/base/net_log.cc index 02b6bbd..ace4a53 100644 --- a/net/base/net_log.cc +++ b/net/base/net_log.cc @@ -97,4 +97,15 @@ Value* NetLogStringParameter::ToValue() const { return dict; } +Value* NetLogSourceParameter::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + + DictionaryValue* source_dict = new DictionaryValue(); + source_dict->SetInteger(L"type", static_cast<int>(value_.type)); + source_dict->SetInteger(L"id", static_cast<int>(value_.id)); + + dict->Set(ASCIIToWide(name_), source_dict); + return dict; +} + } // namespace net diff --git a/net/base/net_log.h b/net/base/net_log.h index 619b57b..a9d24f8 100644 --- a/net/base/net_log.h +++ b/net/base/net_log.h @@ -53,7 +53,7 @@ class NetLog { // The "source" identifies the entity that generated the log message. enum SourceType { -#define SOURCE_TYPE(label) SOURCE_ ## label, +#define SOURCE_TYPE(label, value) SOURCE_ ## label = value, #include "net/base/net_log_source_type_list.h" #undef SOURCE_TYPE }; @@ -206,6 +206,25 @@ class NetLogIntegerParameter : public NetLog::EventParameters { const int value_; }; +// NetLogSourceParameter is a subclass of EventParameters that encapsulates a +// single NetLog::Source parameter. +class NetLogSourceParameter : public NetLog::EventParameters { + public: + // |name| must be a string literal. + NetLogSourceParameter(const char* name, const NetLog::Source& value) + : name_(name), value_(value) {} + + const NetLog::Source& value() const { + return value_; + } + + virtual Value* ToValue() const; + + private: + const char* name_; + const NetLog::Source value_; +}; + } // namespace net #endif // NET_BASE_NET_LOG_H_ diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h index 531a019..709a130 100644 --- a/net/base/net_log_event_type_list.h +++ b/net/base/net_log_event_type_list.h @@ -13,12 +13,7 @@ // log context around it.) EVENT_TYPE(CANCELLED) -// TODO(eroman): remove the remaining consumers of this. -EVENT_TYPE(TODO_STRING) - // Marks the creation/destruction of a request (URLRequest or SocketStream). -// In the begin phase of this event, the message will contain a string which -// is the URL. EVENT_TYPE(REQUEST_ALIVE) // ------------------------------------------------------------------------ @@ -154,8 +149,18 @@ EVENT_TYPE(TCP_CONNECT) // } EVENT_TYPE(TCP_CONNECT_ATTEMPT) -// Marks the destruction of a TCP socket. -EVENT_TYPE(TCP_SOCKET_DONE) +// Marks the begin/end of a socket (TCP/SOCKS/SSL). +EVENT_TYPE(SOCKET_ALIVE) + +// This event is logged to the socket stream whenever the socket is +// acquired/released via a ClientSocketHandle. +// +// The BEGIN phase contains the following parameters: +// +// { +// "source_dependency": <Source identifier for the controlling entity> +// } +EVENT_TYPE(SOCKET_IN_USE) // The start/end of a SOCKS connect(). EVENT_TYPE(SOCKS_CONNECT) @@ -228,6 +233,23 @@ EVENT_TYPE(SOCKET_BYTES_RECEIVED) // The start/end of a ConnectJob. EVENT_TYPE(SOCKET_POOL_CONNECT_JOB) +// The start/end of the ConnectJob::Connect(). +// +// The BEGIN phase has these parameters: +// +// { +// "group_name": <The group name for the socket request.> +// } +EVENT_TYPE(SOCKET_POOL_CONNECT_JOB_CONNECT) + +// This event is logged whenever the ConnectJob gets a new socket +// association. The event parameters point to that socket: +// +// { +// "source_dependency": <The source identifier for the new socket.> +// } +EVENT_TYPE(CONNECT_JOB_SET_SOCKET) + // Whether the connect job timed out. EVENT_TYPE(SOCKET_POOL_CONNECT_JOB_TIMED_OUT) @@ -262,25 +284,23 @@ EVENT_TYPE(TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET) // A backup socket is created due to slow connect EVENT_TYPE(SOCKET_BACKUP_CREATED) -// A backup socket is created due to slow connect -EVENT_TYPE(SOCKET_BACKUP_TIMER_EXTENDED) - -// Identifies the NetLog::Source() for a ConnectJob. The begin event -// is sent to the request that triggered the ConnectJob, the end event -// is sent to the request that received the connected socket. Because of -// late binding, they may not be the same. Therefore the ID for the -// ConnectJob NetLog is sent in both events. The event parameters are: +// This event is sent when a connect job is eventually bound to a request +// (because of late binding and socket backup jobs, we don't assign the job to +// a request until it has completed). +// +// The event parameters are: // { -// "source_id": <ID of the connect job that was bound to this source> +// "source_dependency": <Source identifer for the connect job we are +// bound to> // } -EVENT_TYPE(SOCKET_POOL_CONNECT_JOB_ID) +EVENT_TYPE(SOCKET_POOL_BOUND_TO_CONNECT_JOB) // Identifies the NetLog::Source() for the Socket assigned to the pending // request. The event parameters are: // { -// "source_id": <ID of the socket that was bound to this source> +// "source_dependency": <Source identifier for the socket we acquired> // } -EVENT_TYPE(SOCKET_POOL_SOCKET_ID) +EVENT_TYPE(SOCKET_POOL_BOUND_TO_SOCKET) // ------------------------------------------------------------------------ // URLRequest diff --git a/net/base/net_log_source_type_list.h b/net/base/net_log_source_type_list.h index 9d29826..6664c2d 100644 --- a/net/base/net_log_source_type_list.h +++ b/net/base/net_log_source_type_list.h @@ -5,11 +5,13 @@ // NOTE: No header guards are used, since this file is intended to be expanded // directly within a block where the SOURCE_TYPE macro is defined. -SOURCE_TYPE(NONE) -SOURCE_TYPE(URL_REQUEST) -SOURCE_TYPE(SOCKET_STREAM) -SOURCE_TYPE(INIT_PROXY_RESOLVER) -SOURCE_TYPE(CONNECT_JOB) -SOURCE_TYPE(SOCKET) -SOURCE_TYPE(SPDY_SESSION) +SOURCE_TYPE(NONE, -1) +SOURCE_TYPE(URL_REQUEST, 0) +SOURCE_TYPE(SOCKET_STREAM, 1) +SOURCE_TYPE(INIT_PROXY_RESOLVER, 2) +SOURCE_TYPE(CONNECT_JOB, 3) +SOURCE_TYPE(SOCKET, 4) +SOURCE_TYPE(SPDY_SESSION, 5) + +SOURCE_TYPE(COUNT, 6) // Always keep this as the last entry. diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 964d1b9..bffd97a 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -236,6 +236,7 @@ HttpCache::HttpCache(NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, + NetLog* net_log, BackendFactory* backend_factory) : backend_factory_(backend_factory), temp_backend_(NULL), @@ -243,7 +244,8 @@ HttpCache::HttpCache(NetworkChangeNotifier* network_change_notifier, mode_(NORMAL), network_layer_(HttpNetworkLayer::CreateFactory( network_change_notifier, host_resolver, proxy_service, - ssl_config_service, http_auth_handler_factory)), + ssl_config_service, http_auth_handler_factory, + net_log)), ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), enable_range_support_(true) { } diff --git a/net/http/http_cache.h b/net/http/http_cache.h index a55763b..79c2134 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -16,6 +16,7 @@ #include <list> #include <set> +#include <string> #include "base/basictypes.h" #include "base/file_path.h" @@ -43,6 +44,7 @@ class HttpNetworkSession; struct HttpRequestInfo; class HttpResponseInfo; class IOBuffer; +class NetLog; class NetworkChangeNotifier; class ProxyService; class SSLConfigService; @@ -114,6 +116,7 @@ class HttpCache : public HttpTransactionFactory, HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, + NetLog* net_log, BackendFactory* backend_factory); // The disk cache is initialized lazily (by CreateTransaction) in this case. diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc index 87422d4..f661fde 100644 --- a/net/http/http_network_layer.cc +++ b/net/http/http_network_layer.cc @@ -25,13 +25,15 @@ HttpTransactionFactory* HttpNetworkLayer::CreateFactory( HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, - HttpAuthHandlerFactory* http_auth_handler_factory) { + HttpAuthHandlerFactory* http_auth_handler_factory, + NetLog* net_log) { DCHECK(proxy_service); return new HttpNetworkLayer(ClientSocketFactory::GetDefaultFactory(), network_change_notifier, host_resolver, proxy_service, ssl_config_service, - http_auth_handler_factory); + http_auth_handler_factory, + net_log); } // static @@ -51,7 +53,8 @@ HttpNetworkLayer::HttpNetworkLayer( HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, - HttpAuthHandlerFactory* http_auth_handler_factory) + HttpAuthHandlerFactory* http_auth_handler_factory, + NetLog* net_log) : socket_factory_(socket_factory), network_change_notifier_(network_change_notifier), host_resolver_(host_resolver), @@ -60,6 +63,7 @@ HttpNetworkLayer::HttpNetworkLayer( session_(NULL), spdy_session_pool_(NULL), http_auth_handler_factory_(http_auth_handler_factory), + net_log_(net_log), suspended_(false) { DCHECK(proxy_service_); DCHECK(ssl_config_service_.get()); @@ -72,6 +76,7 @@ HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) session_(session), spdy_session_pool_(session->spdy_session_pool()), http_auth_handler_factory_(NULL), + net_log_(NULL), suspended_(false) { DCHECK(session_.get()); } @@ -108,13 +113,15 @@ HttpNetworkSession* HttpNetworkLayer::GetSession() { session_ = new HttpNetworkSession( network_change_notifier_, host_resolver_, proxy_service_, socket_factory_, ssl_config_service_, spdy_pool, - http_auth_handler_factory_); + http_auth_handler_factory_, + net_log_); // These were just temps for lazy-initializing HttpNetworkSession. network_change_notifier_ = NULL; host_resolver_ = NULL; proxy_service_ = NULL; socket_factory_ = NULL; http_auth_handler_factory_ = NULL; + net_log_ = NULL; } return session_; } diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h index 2d4130d..a045798 100644 --- a/net/http/http_network_layer.h +++ b/net/http/http_network_layer.h @@ -17,6 +17,7 @@ class ClientSocketFactory; class HostResolver; class HttpAuthHandlerFactory; class HttpNetworkSession; +class NetLog; class NetworkChangeNotifier; class ProxyInfo; class ProxyService; @@ -31,7 +32,8 @@ class HttpNetworkLayer : public HttpTransactionFactory { NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, - HttpAuthHandlerFactory* http_auth_handler_factory); + HttpAuthHandlerFactory* http_auth_handler_factory, + NetLog* net_log); // Construct a HttpNetworkLayer with an existing HttpNetworkSession which // contains a valid ProxyService. explicit HttpNetworkLayer(HttpNetworkSession* session); @@ -44,7 +46,8 @@ class HttpNetworkLayer : public HttpTransactionFactory { HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, - HttpAuthHandlerFactory* http_auth_handler_factory); + HttpAuthHandlerFactory* http_auth_handler_factory, + NetLog* net_log); // Create a transaction factory that instantiate a network layer over an // existing network session. Network session contains some valuable // information (e.g. authentication data) that we want to share across @@ -85,6 +88,7 @@ class HttpNetworkLayer : public HttpTransactionFactory { scoped_refptr<SpdySessionPool> spdy_session_pool_; HttpAuthHandlerFactory* http_auth_handler_factory_; + NetLog* net_log_; bool suspended_; static bool force_spdy_; diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc index 697fe98..780ab68 100644 --- a/net/http/http_network_layer_unittest.cc +++ b/net/http/http_network_layer_unittest.cc @@ -18,7 +18,7 @@ class HttpNetworkLayerTest : public PlatformTest { TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { net::HttpNetworkLayer factory( NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), - new net::SSLConfigServiceDefaults, NULL); + new net::SSLConfigServiceDefaults, NULL, NULL); scoped_ptr<net::HttpTransaction> trans; int rv = factory.CreateTransaction(&trans); @@ -29,7 +29,7 @@ TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { TEST_F(HttpNetworkLayerTest, Suspend) { net::HttpNetworkLayer factory( NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), - new net::SSLConfigServiceDefaults, NULL); + new net::SSLConfigServiceDefaults, NULL, NULL); scoped_ptr<net::HttpTransaction> trans; int rv = factory.CreateTransaction(&trans); @@ -71,7 +71,7 @@ TEST_F(HttpNetworkLayerTest, GET) { new net::MockHostResolver, net::ProxyService::CreateNull(), new net::SSLConfigServiceDefaults, - NULL); + NULL, NULL); TestCompletionCallback callback; diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc index dddb223..4301a76 100644 --- a/net/http/http_network_session.cc +++ b/net/http/http_network_session.cc @@ -42,7 +42,8 @@ HttpNetworkSession::HttpNetworkSession( ClientSocketFactory* client_socket_factory, SSLConfigService* ssl_config_service, SpdySessionPool* spdy_session_pool, - HttpAuthHandlerFactory* http_auth_handler_factory) + HttpAuthHandlerFactory* http_auth_handler_factory, + NetLog* net_log) : network_change_notifier_(network_change_notifier), // TODO(vandebo) when we've completely converted to pools, the base TCP // pool name should get changed to TCP instead of Transport. @@ -53,13 +54,15 @@ HttpNetworkSession::HttpNetworkSession( socks_pool_histograms_(new ClientSocketPoolHistograms("SOCK")), tcp_socket_pool_(new TCPClientSocketPool( g_max_sockets, g_max_sockets_per_group, tcp_pool_histograms_, - host_resolver, client_socket_factory, network_change_notifier_)), + host_resolver, client_socket_factory, network_change_notifier_, + net_log)), socket_factory_(client_socket_factory), host_resolver_(host_resolver), proxy_service_(proxy_service), ssl_config_service_(ssl_config_service), spdy_session_pool_(spdy_session_pool), - http_auth_handler_factory_(http_auth_handler_factory) { + http_auth_handler_factory_(http_auth_handler_factory), + net_log_(net_log) { DCHECK(proxy_service); DCHECK(ssl_config_service); } @@ -81,7 +84,8 @@ HttpNetworkSession::GetSocketPoolForHTTPProxy(const HostPortPair& http_proxy) { new TCPClientSocketPool( g_max_sockets_per_proxy_server, g_max_sockets_per_group, http_proxy_pool_histograms_, host_resolver_, socket_factory_, - network_change_notifier_))); + network_change_notifier_, + net_log_))); return ret.first->second; } @@ -104,8 +108,9 @@ HttpNetworkSession::GetSocketPoolForSOCKSProxy( g_max_sockets_per_group, tcp_for_socks_pool_histograms_, host_resolver_, socket_factory_, - network_change_notifier_), - network_change_notifier_))); + network_change_notifier_, + net_log_), + network_change_notifier_, net_log_))); return ret.first->second; } @@ -144,7 +149,8 @@ void HttpNetworkSession::ReplaceTCPSocketPool() { tcp_pool_histograms_, host_resolver_, socket_factory_, - network_change_notifier_); + network_change_notifier_, + net_log_); } } // namespace net diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index 5495c4b..64d302d 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -38,7 +38,8 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { ClientSocketFactory* client_socket_factory, SSLConfigService* ssl_config_service, SpdySessionPool* spdy_session_pool, - HttpAuthHandlerFactory* http_auth_handler_factory); + HttpAuthHandlerFactory* http_auth_handler_factory, + NetLog* net_log); HttpAuthCache* auth_cache() { return &auth_cache_; } SSLClientAuthCache* ssl_client_auth_cache() { @@ -123,6 +124,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { scoped_refptr<SSLConfigService> ssl_config_service_; scoped_refptr<SpdySessionPool> spdy_session_pool_; HttpAuthHandlerFactory* http_auth_handler_factory_; + NetLog* net_log_; SpdySettingsStorage spdy_settings_; }; diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 79d176f..f0c111a 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -114,7 +114,8 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { &session_deps->socket_factory, session_deps->ssl_config_service, session_deps->spdy_session_pool, - session_deps->http_auth_handler_factory.get()); + session_deps->http_auth_handler_factory.get(), + NULL); } class HttpNetworkTransactionTest : public PlatformTest { @@ -237,9 +238,9 @@ std::string MockGetHostName() { template<typename EmulatedClientSocketPool> class CaptureGroupNameSocketPool : public EmulatedClientSocketPool { public: - CaptureGroupNameSocketPool(HttpNetworkSession* session) + explicit CaptureGroupNameSocketPool(HttpNetworkSession* session) : EmulatedClientSocketPool(0, 0, NULL, session->host_resolver(), NULL, - NULL) {} + NULL, NULL) {} const std::string last_group_name_received() const { return last_group_name_; } @@ -5589,7 +5590,7 @@ TEST_F(HttpNetworkTransactionTest, ResolveCanonicalName) { class TLSDecompressionFailureSocketDataProvider : public SocketDataProvider { public: - TLSDecompressionFailureSocketDataProvider(bool fail_all) + explicit TLSDecompressionFailureSocketDataProvider(bool fail_all) : fail_all_(fail_all) { } diff --git a/net/proxy/proxy_script_fetcher_unittest.cc b/net/proxy/proxy_script_fetcher_unittest.cc index 3a1f707..5d147b1 100644 --- a/net/proxy/proxy_script_fetcher_unittest.cc +++ b/net/proxy/proxy_script_fetcher_unittest.cc @@ -40,7 +40,7 @@ class RequestContext : public URLRequestContext { new net::HttpCache( net::HttpNetworkLayer::CreateFactory( NULL, host_resolver_, proxy_service_, ssl_config_service_, - NULL), + NULL, NULL), net::HttpCache::DefaultBackend::InMemory(0)); } diff --git a/net/socket/client_socket_handle.cc b/net/socket/client_socket_handle.cc index 5964239..4f61a68 100644 --- a/net/socket/client_socket_handle.cc +++ b/net/socket/client_socket_handle.cc @@ -33,6 +33,7 @@ void ClientSocketHandle::ResetInternal(bool cancel) { if (socket_.get()) { // Because of http://crbug.com/37810 we may not have a pool, but have // just a raw socket. + socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE, NULL); if (pool_) // If we've still got a socket, release it back to the ClientSocketPool so // it can be deleted or reused. @@ -92,6 +93,15 @@ void ClientSocketHandle::HandleInitCompletion(int result) { NOTREACHED(); break; } + + // Broadcast that the socket has been acquired. + // TODO(eroman): This logging is not complete, in particular set_socket() and + // release() socket. It ends up working though, since those methods are being + // used to layer sockets (and the destination sources are the same). + DCHECK(socket_.get()); + socket_->NetLog().BeginEvent( + NetLog::TYPE_SOCKET_IN_USE, + new NetLogSourceParameter("source_dependency", requesting_source_)); } } // namespace net diff --git a/net/socket/client_socket_handle.h b/net/socket/client_socket_handle.h index f750c7b..4b36e58 100644 --- a/net/socket/client_socket_handle.h +++ b/net/socket/client_socket_handle.h @@ -14,6 +14,7 @@ #include "net/base/completion_callback.h" #include "net/base/load_states.h" #include "net/base/net_errors.h" +#include "net/base/net_log.h" #include "net/base/request_priority.h" #include "net/socket/client_socket.h" #include "net/socket/client_socket_pool.h" @@ -144,6 +145,8 @@ class ClientSocketHandle { base::TimeTicks init_time_; base::TimeDelta setup_time_; + NetLog::Source requesting_source_; + DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); }; @@ -155,6 +158,8 @@ int ClientSocketHandle::Init(const std::string& group_name, CompletionCallback* callback, const scoped_refptr<PoolType>& pool, const BoundNetLog& net_log) { + requesting_source_ = net_log.source(); + CHECK(!group_name.empty()); // Note that this will result in a link error if the SocketParams has not been // registered for the PoolType via REGISTER_SOCKET_PARAMS_FOR_POOL (defined in diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc index 99011be..ddaa430 100644 --- a/net/socket/client_socket_pool_base.cc +++ b/net/socket/client_socket_pool_base.cc @@ -42,42 +42,46 @@ ConnectJob::ConnectJob(const std::string& group_name, idle_(true) { DCHECK(!group_name.empty()); DCHECK(delegate); + net_log.BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); } ConnectJob::~ConnectJob() { - if (delegate_ && !idle_) { - // If the delegate was not NULLed, then NotifyDelegateOfCompletion has - // not been called yet. If we've started then we are cancelling. - net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); - net_log_.EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); - } + net_log().EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); } int ConnectJob::Connect() { if (timeout_duration_ != base::TimeDelta()) timer_.Start(timeout_duration_, this, &ConnectJob::OnTimeout); - net_log_.BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, - new NetLogStringParameter("group_name", group_name_)); idle_ = false; + LogConnectStart(); + int rv = ConnectInternal(); if (rv != ERR_IO_PENDING) { + LogConnectCompletion(rv); delegate_ = NULL; - net_log_.EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); } return rv; } +void ConnectJob::set_socket(ClientSocket* socket) { + if (socket) { + net_log().AddEvent(NetLog::TYPE_CONNECT_JOB_SET_SOCKET, + new NetLogSourceParameter("source_dependency", + socket->NetLog().source())); + } + socket_.reset(socket); +} + void ConnectJob::NotifyDelegateOfCompletion(int rv) { // The delegate will delete |this|. Delegate *delegate = delegate_; delegate_ = NULL; - net_log_.EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL); - + LogConnectCompletion(rv); delegate->OnConnectJobComplete(rv, this); } @@ -86,6 +90,18 @@ void ConnectJob::ResetTimer(base::TimeDelta remaining_time) { timer_.Start(remaining_time, this, &ConnectJob::OnTimeout); } +void ConnectJob::LogConnectStart() { + net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT, + new NetLogStringParameter("group_name", group_name_)); +} + +void ConnectJob::LogConnectCompletion(int net_error) { + scoped_refptr<NetLog::EventParameters> params; + if (net_error != OK) + params = new NetLogIntegerParameter("net_error", net_error); + net_log().EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT, params); +} + void ConnectJob::OnTimeout() { // Make sure the socket is NULL before calling into |delegate|. set_socket(NULL); @@ -236,21 +252,12 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal( } // We couldn't find a socket to reuse, so allocate and connect a new one. - BoundNetLog job_net_log = BoundNetLog::Make( - request->net_log().net_log(), NetLog::SOURCE_CONNECT_JOB); - request->net_log().BeginEvent( - NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, - new NetLogIntegerParameter("source_id", job_net_log.source().id)); - scoped_ptr<ConnectJob> connect_job( - connect_job_factory_->NewConnectJob(group_name, *request, this, - job_net_log)); + connect_job_factory_->NewConnectJob(group_name, *request, this)); int rv = connect_job->Connect(); if (rv == OK) { - request->net_log().EndEvent( - NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, - new NetLogIntegerParameter("source_id", job_net_log.source().id)); + LogBoundConnectJobToRequest(connect_job->net_log().source(), request); HandOutSocket(connect_job->ReleaseSocket(), false /* not reused */, handle, base::TimeDelta(), &group, request->net_log()); } else if (rv == ERR_IO_PENDING) { @@ -260,8 +267,7 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal( if (group.IsEmpty() && !group.backup_job && backup_jobs_enabled_) { group.backup_job = connect_job_factory_->NewConnectJob(group_name, *request, - this, - job_net_log); + this); StartBackupSocketTimer(group_name); } @@ -270,9 +276,7 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal( ConnectJob* job = connect_job.release(); group.jobs.insert(job); } else { - request->net_log().EndEvent( - NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, - new NetLogIntegerParameter("source_id", job_net_log.source().id)); + LogBoundConnectJobToRequest(connect_job->net_log().source(), request); if (group.IsEmpty()) group_map_.erase(group_name); } @@ -280,6 +284,14 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal( return rv; } +// static +void ClientSocketPoolBaseHelper::LogBoundConnectJobToRequest( + const NetLog::Source& connect_job_source, const Request* request) { + request->net_log().AddEvent( + NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, + new NetLogSourceParameter("source_dependency", connect_job_source)); +} + void ClientSocketPoolBaseHelper::StartBackupSocketTimer( const std::string& group_name) { CHECK(ContainsKey(group_map_, group_name)); @@ -312,8 +324,6 @@ void ClientSocketPoolBaseHelper::OnBackupSocketTimerFired( if (ReachedMaxSocketsLimit() || !group.HasAvailableSocketSlot(max_sockets_per_group_) || (*group.jobs.begin())->GetLoadState() == LOAD_STATE_RESOLVING_HOST) { - group.backup_job->net_log().AddEvent( - NetLog::TYPE_SOCKET_BACKUP_TIMER_EXTENDED, NULL); StartBackupSocketTimer(group_name); return; } @@ -583,13 +593,11 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete( if (!group.pending_requests.empty()) { scoped_ptr<const Request> r(RemoveRequestFromQueue( group.pending_requests.begin(), &group.pending_requests)); - r->net_log().EndEvent( - NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, - new NetLogIntegerParameter("source_id", job_log.source().id)); - r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); + LogBoundConnectJobToRequest(job_log.source(), r.get()); HandOutSocket( socket.release(), false /* unused socket */, r->handle(), base::TimeDelta(), &group, r->net_log()); + r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); r->callback()->Run(result); } else { AddIdleSocket(socket.release(), false /* unused socket */, &group); @@ -600,10 +608,9 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete( if (!group.pending_requests.empty()) { scoped_ptr<const Request> r(RemoveRequestFromQueue( group.pending_requests.begin(), &group.pending_requests)); - r->net_log().EndEvent( - NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, - new NetLogIntegerParameter("source_id", job_log.source().id)); - r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); + LogBoundConnectJobToRequest(job_log.source(), r.get()); + r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, + new NetLogIntegerParameter("net_error", result)); r->callback()->Run(result); } MaybeOnAvailableSocketSlot(group_name); @@ -667,7 +674,11 @@ void ClientSocketPoolBaseHelper::ProcessPendingRequest( if (rv != ERR_IO_PENDING) { scoped_ptr<const Request> r(RemoveRequestFromQueue( group->pending_requests.begin(), &group->pending_requests)); - r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); + + scoped_refptr<NetLog::EventParameters> params; + if (rv != OK) + params = new NetLogIntegerParameter("net_error", rv); + r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, params); r->callback()->Run(rv); if (rv != OK) { // |group| may be invalid after the callback, we need to search @@ -696,9 +707,9 @@ void ClientSocketPoolBaseHelper::HandOutSocket( "idle_ms", static_cast<int>(idle_time.InMilliseconds()))); } - net_log.AddEvent(NetLog::TYPE_SOCKET_POOL_SOCKET_ID, - new NetLogIntegerParameter( - "source_id", socket->NetLog().source().id)); + net_log.AddEvent(NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, + new NetLogSourceParameter( + "source_dependency", socket->NetLog().source())); handed_out_socket_count_++; group->active_socket_count++; diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h index db408a2..470c120 100644 --- a/net/socket/client_socket_pool_base.h +++ b/net/socket/client_socket_pool_base.h @@ -91,7 +91,7 @@ class ConnectJob { virtual LoadState GetLoadState() const = 0; protected: - void set_socket(ClientSocket* socket) { socket_.reset(socket); } + void set_socket(ClientSocket* socket); ClientSocket* socket() { return socket_.get(); } void NotifyDelegateOfCompletion(int rv); void ResetTimer(base::TimeDelta remainingTime); @@ -99,6 +99,9 @@ class ConnectJob { private: virtual int ConnectInternal() = 0; + void LogConnectStart(); + void LogConnectCompletion(int net_error); + // Alerts the delegate that the ConnectJob has timed out. void OnTimeout(); @@ -158,8 +161,7 @@ class ClientSocketPoolBaseHelper virtual ConnectJob* NewConnectJob( const std::string& group_name, const Request& request, - ConnectJob::Delegate* delegate, - const BoundNetLog& net_log) const = 0; + ConnectJob::Delegate* delegate) const = 0; virtual base::TimeDelta ConnectionTimeout() const = 0; @@ -231,7 +233,7 @@ class ClientSocketPoolBaseHelper return connect_job_factory_->ConnectionTimeout(); } - void enable_backup_jobs() { backup_jobs_enabled_ = true; }; + void enable_backup_jobs() { backup_jobs_enabled_ = true; } private: friend class base::RefCounted<ClientSocketPoolBaseHelper>; @@ -387,6 +389,9 @@ class ClientSocketPoolBaseHelper int RequestSocketInternal(const std::string& group_name, const Request* request); + static void LogBoundConnectJobToRequest( + const NetLog::Source& connect_job_source, const Request* request); + // Set a timer to create a backup socket if it takes too long to create one. void StartBackupSocketTimer(const std::string& group_name); @@ -486,8 +491,7 @@ class ClientSocketPoolBase { virtual ConnectJob* NewConnectJob( const std::string& group_name, const Request& request, - ConnectJob::Delegate* delegate, - const BoundNetLog& net_log) const = 0; + ConnectJob::Delegate* delegate) const = 0; virtual base::TimeDelta ConnectionTimeout() const = 0; @@ -580,7 +584,7 @@ class ClientSocketPoolBase { return histograms_; } - void enable_backup_jobs() { helper_->enable_backup_jobs(); }; + void enable_backup_jobs() { helper_->enable_backup_jobs(); } private: // This adaptor class exists to bridge the @@ -602,11 +606,10 @@ class ClientSocketPoolBase { virtual ConnectJob* NewConnectJob( const std::string& group_name, const internal::ClientSocketPoolBaseHelper::Request& request, - ConnectJob::Delegate* delegate, - const BoundNetLog& net_log) const { + ConnectJob::Delegate* delegate) const { const Request* casted_request = static_cast<const Request*>(&request); return connect_job_factory_->NewConnectJob( - group_name, *casted_request, delegate, net_log); + group_name, *casted_request, delegate); } virtual base::TimeDelta ConnectionTimeout() const { diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index b33da2e..bf0f96e 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -46,8 +46,8 @@ class MockClientSocket : public ClientSocket { IOBuffer* /* buf */, int /* len */, CompletionCallback* /* callback */) { return ERR_UNEXPECTED; } - virtual bool SetReceiveBufferSize(int32 size) { return true; }; - virtual bool SetSendBufferSize(int32 size) { return true; }; + virtual bool SetReceiveBufferSize(int32 size) { return true; } + virtual bool SetSendBufferSize(int32 size) { return true; } // ClientSocket methods: @@ -122,8 +122,9 @@ class TestConnectJob : public ConnectJob { base::TimeDelta timeout_duration, ConnectJob::Delegate* delegate, MockClientSocketFactory* client_socket_factory, - const BoundNetLog& net_log) - : ConnectJob(group_name, timeout_duration, delegate, net_log), + NetLog* net_log) + : ConnectJob(group_name, timeout_duration, delegate, + BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), job_type_(job_type), client_socket_factory_(client_socket_factory), method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), @@ -255,15 +256,14 @@ class TestConnectJobFactory virtual ConnectJob* NewConnectJob( const std::string& group_name, const TestClientSocketPoolBase::Request& request, - ConnectJob::Delegate* delegate, - const BoundNetLog& net_log) const { + ConnectJob::Delegate* delegate) const { return new TestConnectJob(job_type_, group_name, request, timeout_duration_, delegate, client_socket_factory_, - net_log); + NULL); } virtual base::TimeDelta ConnectionTimeout() const { @@ -484,14 +484,14 @@ TEST_F(ClientSocketPoolBaseTest, ConnectJob_NoTimeoutOnSynchronousCompletion) { base::TimeDelta::FromMicroseconds(1), &delegate, &client_socket_factory_, - BoundNetLog())); + NULL)); EXPECT_EQ(OK, job->Connect()); } TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { TestConnectJobDelegate delegate; ClientSocketHandle ignored; - CapturingBoundNetLog log(CapturingNetLog::kUnbounded); + CapturingNetLog log(CapturingNetLog::kUnbounded); TestClientSocketPoolBase::Request request( &ignored, NULL, kDefaultPriority, NULL, BoundNetLog()); @@ -503,19 +503,26 @@ TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { base::TimeDelta::FromMicroseconds(1), &delegate, &client_socket_factory_, - log.bound()); + &log); ASSERT_EQ(ERR_IO_PENDING, job->Connect()); PlatformThread::Sleep(1); EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); - EXPECT_EQ(3u, log.entries().size()); + EXPECT_EQ(6u, log.entries().size()); EXPECT_TRUE(LogContainsBeginEvent( log.entries(), 0, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); + EXPECT_TRUE(LogContainsBeginEvent( + log.entries(), 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); + EXPECT_TRUE(LogContainsEvent( + log.entries(), 2, NetLog::TYPE_CONNECT_JOB_SET_SOCKET, + NetLog::PHASE_NONE)); EXPECT_TRUE(LogContainsEvent( - log.entries(), 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT, + log.entries(), 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT, NetLog::PHASE_NONE)); EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 2, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); + log.entries(), 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_CONNECT)); + EXPECT_TRUE(LogContainsEndEvent( + log.entries(), 5, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); } TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { @@ -531,22 +538,17 @@ TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { EXPECT_TRUE(handle.socket()); handle.Reset(); - EXPECT_EQ(7u, log.entries().size()); + EXPECT_EQ(4u, log.entries().size()); EXPECT_TRUE(LogContainsBeginEvent( log.entries(), 0, NetLog::TYPE_SOCKET_POOL)); - EXPECT_TRUE(LogContainsBeginEvent( - log.entries(), 1, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID)); - EXPECT_TRUE(LogContainsBeginEvent( - log.entries(), 2, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); - EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); - EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 4, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID)); EXPECT_TRUE(LogContainsEvent( - log.entries(), 5, NetLog::TYPE_SOCKET_POOL_SOCKET_ID, + log.entries(), 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, + NetLog::PHASE_NONE)); + EXPECT_TRUE(LogContainsEvent( + log.entries(), 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, NetLog::PHASE_NONE)); EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 6, NetLog::TYPE_SOCKET_POOL)); + log.entries(), 3, NetLog::TYPE_SOCKET_POOL)); } TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { @@ -560,14 +562,14 @@ TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_, log.bound())); - EXPECT_EQ(6u, log.entries().size()); + EXPECT_EQ(3u, log.entries().size()); EXPECT_TRUE(LogContainsBeginEvent( log.entries(), 0, NetLog::TYPE_SOCKET_POOL)); - EXPECT_TRUE(LogContainsBeginEvent( - log.entries(), 2, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); + EXPECT_TRUE(LogContainsEvent( + log.entries(), 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, + NetLog::PHASE_NONE)); EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); - EXPECT_TRUE(LogContainsEndEvent(log.entries(), 5, NetLog::TYPE_SOCKET_POOL)); + log.entries(), 2, NetLog::TYPE_SOCKET_POOL)); } TEST_F(ClientSocketPoolBaseTest, TotalLimit) { @@ -1205,15 +1207,17 @@ TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { EXPECT_TRUE(req.handle()->socket()); req.handle()->Reset(); - EXPECT_EQ(7u, log.entries().size()); + EXPECT_EQ(4u, log.entries().size()); EXPECT_TRUE(LogContainsBeginEvent( log.entries(), 0, NetLog::TYPE_SOCKET_POOL)); - EXPECT_TRUE(LogContainsBeginEvent( - log.entries(), 2, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); - EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); + EXPECT_TRUE(LogContainsEvent( + log.entries(), 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, + NetLog::PHASE_NONE)); + EXPECT_TRUE(LogContainsEvent( + log.entries(), 2, NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, + NetLog::PHASE_NONE)); EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 5, NetLog::TYPE_SOCKET_POOL)); + log.entries(), 3, NetLog::TYPE_SOCKET_POOL)); } TEST_F(ClientSocketPoolBaseTest, @@ -1229,15 +1233,14 @@ TEST_F(ClientSocketPoolBaseTest, EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult()); - EXPECT_EQ(6u, log.entries().size()); + EXPECT_EQ(3u, log.entries().size()); EXPECT_TRUE(LogContainsBeginEvent( log.entries(), 0, NetLog::TYPE_SOCKET_POOL)); - EXPECT_TRUE(LogContainsBeginEvent( - log.entries(), 2, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); - EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 3, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB)); + EXPECT_TRUE(LogContainsEvent( + log.entries(), 1, NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB, + NetLog::PHASE_NONE)); EXPECT_TRUE(LogContainsEndEvent( - log.entries(), 5, NetLog::TYPE_SOCKET_POOL)); + log.entries(), 2, NetLog::TYPE_SOCKET_POOL)); } TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) { diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc index 452ce25..4c446ab 100644 --- a/net/socket/socks_client_socket_pool.cc +++ b/net/socket/socks_client_socket_pool.cc @@ -26,13 +26,15 @@ SOCKSConnectJob::SOCKSConnectJob( const scoped_refptr<TCPClientSocketPool>& tcp_pool, const scoped_refptr<HostResolver>& host_resolver, Delegate* delegate, - const BoundNetLog& net_log) - : ConnectJob(group_name, timeout_duration, delegate, net_log), + NetLog* net_log) + : ConnectJob(group_name, timeout_duration, delegate, + BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), socks_params_(socks_params), tcp_pool_(tcp_pool), resolver_(host_resolver), ALLOW_THIS_IN_INITIALIZER_LIST( - callback_(this, &SOCKSConnectJob::OnIOComplete)) {} + callback_(this, &SOCKSConnectJob::OnIOComplete)) { +} SOCKSConnectJob::~SOCKSConnectJob() { // We don't worry about cancelling the tcp socket since the destructor in @@ -144,10 +146,9 @@ int SOCKSConnectJob::DoSOCKSConnectComplete(int result) { ConnectJob* SOCKSClientSocketPool::SOCKSConnectJobFactory::NewConnectJob( const std::string& group_name, const PoolBase::Request& request, - ConnectJob::Delegate* delegate, - const BoundNetLog& net_log) const { + ConnectJob::Delegate* delegate) const { return new SOCKSConnectJob(group_name, request.params(), ConnectionTimeout(), - tcp_pool_, host_resolver_, delegate, net_log); + tcp_pool_, host_resolver_, delegate, net_log_); } base::TimeDelta @@ -162,11 +163,12 @@ SOCKSClientSocketPool::SOCKSClientSocketPool( const scoped_refptr<ClientSocketPoolHistograms>& histograms, const scoped_refptr<HostResolver>& host_resolver, const scoped_refptr<TCPClientSocketPool>& tcp_pool, - NetworkChangeNotifier* network_change_notifier) + NetworkChangeNotifier* network_change_notifier, + NetLog* net_log) : base_(max_sockets, max_sockets_per_group, histograms, base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), - new SOCKSConnectJobFactory(tcp_pool, host_resolver), + new SOCKSConnectJobFactory(tcp_pool, host_resolver, net_log), network_change_notifier) {} SOCKSClientSocketPool::~SOCKSClientSocketPool() {} diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h index ea162245..bd975ba 100644 --- a/net/socket/socks_client_socket_pool.h +++ b/net/socket/socks_client_socket_pool.h @@ -41,7 +41,7 @@ class SOCKSSocketParams { const TCPSocketParams& tcp_params() const { return tcp_params_; } const HostResolver::RequestInfo& destination() const { return destination_; } - bool is_socks_v5() const { return socks_v5_; }; + bool is_socks_v5() const { return socks_v5_; } private: // The tcp connection must point toward the proxy server. @@ -61,7 +61,7 @@ class SOCKSConnectJob : public ConnectJob { const scoped_refptr<TCPClientSocketPool>& tcp_pool, const scoped_refptr<HostResolver> &host_resolver, Delegate* delegate, - const BoundNetLog& net_log); + NetLog* net_log); virtual ~SOCKSConnectJob(); // ConnectJob methods. @@ -111,7 +111,8 @@ class SOCKSClientSocketPool : public ClientSocketPool { const scoped_refptr<ClientSocketPoolHistograms>& histograms, const scoped_refptr<HostResolver>& host_resolver, const scoped_refptr<TCPClientSocketPool>& tcp_pool, - NetworkChangeNotifier* network_change_notifier); + NetworkChangeNotifier* network_change_notifier, + NetLog* net_log); // ClientSocketPool methods: virtual int RequestSocket(const std::string& group_name, @@ -155,9 +156,11 @@ class SOCKSClientSocketPool : public ClientSocketPool { class SOCKSConnectJobFactory : public PoolBase::ConnectJobFactory { public: SOCKSConnectJobFactory(const scoped_refptr<TCPClientSocketPool>& tcp_pool, - HostResolver* host_resolver) + HostResolver* host_resolver, + NetLog* net_log) : tcp_pool_(tcp_pool), - host_resolver_(host_resolver) {} + host_resolver_(host_resolver), + net_log_(net_log) {} virtual ~SOCKSConnectJobFactory() {} @@ -165,14 +168,14 @@ class SOCKSClientSocketPool : public ClientSocketPool { virtual ConnectJob* NewConnectJob( const std::string& group_name, const PoolBase::Request& request, - ConnectJob::Delegate* delegate, - const BoundNetLog& net_log) const; + ConnectJob::Delegate* delegate) const; virtual base::TimeDelta ConnectionTimeout() const; private: const scoped_refptr<TCPClientSocketPool> tcp_pool_; const scoped_refptr<HostResolver> host_resolver_; + NetLog* net_log_; DISALLOW_COPY_AND_ASSIGN(SOCKSConnectJobFactory); }; diff --git a/net/socket/socks_client_socket_pool_unittest.cc b/net/socket/socks_client_socket_pool_unittest.cc index 27cb027..33bc146 100644 --- a/net/socket/socks_client_socket_pool_unittest.cc +++ b/net/socket/socks_client_socket_pool_unittest.cc @@ -87,7 +87,7 @@ class MockTCPClientSocketPool : public TCPClientSocketPool { ClientSocketFactory* socket_factory, NetworkChangeNotifier* network_change_notifier) : TCPClientSocketPool(max_sockets, max_sockets_per_group, histograms, - NULL, NULL, network_change_notifier), + NULL, NULL, network_change_notifier, NULL), client_socket_factory_(socket_factory), release_count_(0), cancel_count_(0) {} @@ -180,7 +180,7 @@ class SOCKSClientSocketPoolTest : public ClientSocketPoolTest { socks_histograms_(new ClientSocketPoolHistograms("SOCKSUnitTest")), pool_(new SOCKSClientSocketPool( kMaxSockets, kMaxSocketsPerGroup, socks_histograms_, NULL, - tcp_socket_pool_, &socks_notifier_)) { + tcp_socket_pool_, &socks_notifier_, NULL)) { } int StartRequest(const std::string& group_name, RequestPriority priority) { diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc index 415cb83..7eec8fa 100644 --- a/net/socket/ssl_client_socket_unittest.cc +++ b/net/socket/ssl_client_socket_unittest.cc @@ -84,7 +84,7 @@ TEST_F(SSLClientSocketTest, Connect) { rv = sock->Connect(&callback); EXPECT_TRUE(net::LogContainsBeginEvent( - log.entries(), 4, net::NetLog::TYPE_SSL_CONNECT)); + log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); if (rv != net::OK) { ASSERT_EQ(net::ERR_IO_PENDING, rv); EXPECT_FALSE(sock->IsConnected()); @@ -128,7 +128,7 @@ TEST_F(SSLClientSocketTest, ConnectExpired) { rv = sock->Connect(&callback); EXPECT_TRUE(net::LogContainsBeginEvent( - log.entries(), 4, net::NetLog::TYPE_SSL_CONNECT)); + log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); if (rv != net::OK) { ASSERT_EQ(net::ERR_IO_PENDING, rv); EXPECT_FALSE(sock->IsConnected()); @@ -174,7 +174,7 @@ TEST_F(SSLClientSocketTest, ConnectMismatched) { rv = sock->Connect(&callback); EXPECT_TRUE(net::LogContainsBeginEvent( - log.entries(), 4, net::NetLog::TYPE_SSL_CONNECT)); + log.entries(), 5, net::NetLog::TYPE_SSL_CONNECT)); if (rv != net::ERR_CERT_COMMON_NAME_INVALID) { ASSERT_EQ(net::ERR_IO_PENDING, rv); EXPECT_FALSE(sock->IsConnected()); diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc index 93f2333..81c3ccd 100644 --- a/net/socket/tcp_client_socket_libevent.cc +++ b/net/socket/tcp_client_socket_libevent.cc @@ -110,11 +110,12 @@ TCPClientSocketLibevent::TCPClientSocketLibevent(const AddressList& addresses, next_connect_state_(CONNECT_STATE_NONE), connect_os_error_(0), net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { + net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, NULL); } TCPClientSocketLibevent::~TCPClientSocketLibevent() { Disconnect(); - net_log_.AddEvent(NetLog::TYPE_TCP_SOCKET_DONE, NULL); + net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE, NULL); } int TCPClientSocketLibevent::Connect(CompletionCallback* callback) { diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc index 833b36e..0f2c079 100644 --- a/net/socket/tcp_client_socket_pool.cc +++ b/net/socket/tcp_client_socket_pool.cc @@ -29,7 +29,7 @@ namespace net { // timeout. Even worse, the per-connect timeout threshold varies greatly // between systems (anywhere from 20 seconds to 190 seconds). // See comment #12 at http://crbug.com/23364 for specifics. -static const int kTCPConnectJobTimeoutInSeconds = 240; // 4 minutes. +static const int kTCPConnectJobTimeoutInSeconds = 240; // 4 minutes. TCPConnectJob::TCPConnectJob( const std::string& group_name, @@ -38,8 +38,9 @@ TCPConnectJob::TCPConnectJob( ClientSocketFactory* client_socket_factory, HostResolver* host_resolver, Delegate* delegate, - const BoundNetLog& net_log) - : ConnectJob(group_name, timeout_duration, delegate, net_log), + NetLog* net_log) + : ConnectJob(group_name, timeout_duration, delegate, + BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), params_(params), client_socket_factory_(client_socket_factory), ALLOW_THIS_IN_INITIALIZER_LIST( @@ -160,11 +161,10 @@ int TCPConnectJob::DoTCPConnectComplete(int result) { ConnectJob* TCPClientSocketPool::TCPConnectJobFactory::NewConnectJob( const std::string& group_name, const PoolBase::Request& request, - ConnectJob::Delegate* delegate, - const BoundNetLog& net_log) const { + ConnectJob::Delegate* delegate) const { return new TCPConnectJob(group_name, request.params(), ConnectionTimeout(), client_socket_factory_, host_resolver_, delegate, - net_log); + net_log_); } base::TimeDelta @@ -178,11 +178,13 @@ TCPClientSocketPool::TCPClientSocketPool( const scoped_refptr<ClientSocketPoolHistograms>& histograms, HostResolver* host_resolver, ClientSocketFactory* client_socket_factory, - NetworkChangeNotifier* network_change_notifier) + NetworkChangeNotifier* network_change_notifier, + NetLog* net_log) : base_(max_sockets, max_sockets_per_group, histograms, base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), - new TCPConnectJobFactory(client_socket_factory, host_resolver), + new TCPConnectJobFactory(client_socket_factory, + host_resolver, net_log), network_change_notifier) { base_.enable_backup_jobs(); } diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h index 355bd2a..ea2ef70 100644 --- a/net/socket/tcp_client_socket_pool.h +++ b/net/socket/tcp_client_socket_pool.h @@ -64,7 +64,7 @@ class TCPConnectJob : public ConnectJob { ClientSocketFactory* client_socket_factory, HostResolver* host_resolver, Delegate* delegate, - const BoundNetLog& net_log); + NetLog* net_log); virtual ~TCPConnectJob(); // ConnectJob methods. @@ -118,7 +118,8 @@ class TCPClientSocketPool : public ClientSocketPool { const scoped_refptr<ClientSocketPoolHistograms>& histograms, HostResolver* host_resolver, ClientSocketFactory* client_socket_factory, - NetworkChangeNotifier* network_change_notifier); + NetworkChangeNotifier* network_change_notifier, + NetLog* net_log); // ClientSocketPool methods: @@ -164,9 +165,11 @@ class TCPClientSocketPool : public ClientSocketPool { : public PoolBase::ConnectJobFactory { public: TCPConnectJobFactory(ClientSocketFactory* client_socket_factory, - HostResolver* host_resolver) + HostResolver* host_resolver, + NetLog* net_log) : client_socket_factory_(client_socket_factory), - host_resolver_(host_resolver) {} + host_resolver_(host_resolver), + net_log_(net_log) {} virtual ~TCPConnectJobFactory() {} @@ -175,14 +178,14 @@ class TCPClientSocketPool : public ClientSocketPool { virtual ConnectJob* NewConnectJob( const std::string& group_name, const PoolBase::Request& request, - ConnectJob::Delegate* delegate, - const BoundNetLog& net_log) const; + ConnectJob::Delegate* delegate) const; virtual base::TimeDelta ConnectionTimeout() const; private: ClientSocketFactory* const client_socket_factory_; const scoped_refptr<HostResolver> host_resolver_; + NetLog* net_log_; DISALLOW_COPY_AND_ASSIGN(TCPConnectJobFactory); }; diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc index e0dc09f..25e7fdd 100644 --- a/net/socket/tcp_client_socket_pool_unittest.cc +++ b/net/socket/tcp_client_socket_pool_unittest.cc @@ -272,7 +272,8 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { histograms_, host_resolver_, &client_socket_factory_, - ¬ifier_)) { + ¬ifier_, + NULL)) { } int StartRequest(const std::string& group_name, RequestPriority priority) { @@ -746,6 +747,7 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) { histograms_, host_resolver_, &client_socket_factory_, + NULL, NULL); } } diff --git a/net/socket/tcp_client_socket_unittest.cc b/net/socket/tcp_client_socket_unittest.cc index 0c16010..a2b584a 100644 --- a/net/socket/tcp_client_socket_unittest.cc +++ b/net/socket/tcp_client_socket_unittest.cc @@ -102,12 +102,11 @@ TEST_F(TCPClientSocketTest, Connect) { int rv = sock_->Connect(&callback); EXPECT_TRUE(net::LogContainsBeginEvent( - net_log_.entries(), 0, net::NetLog::TYPE_TCP_CONNECT)); + net_log_.entries(), 0, net::NetLog::TYPE_SOCKET_ALIVE)); + EXPECT_TRUE(net::LogContainsBeginEvent( + net_log_.entries(), 1, net::NetLog::TYPE_TCP_CONNECT)); if (rv != OK) { ASSERT_EQ(rv, ERR_IO_PENDING); - EXPECT_FALSE(net::LogContainsEndEvent( - net_log_.entries(), -1, net::NetLog::TYPE_TCP_CONNECT)); - rv = callback.WaitForResult(); EXPECT_EQ(rv, OK); } diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc index c663992..b25d07f 100644 --- a/net/socket/tcp_client_socket_win.cc +++ b/net/socket/tcp_client_socket_win.cc @@ -267,12 +267,13 @@ TCPClientSocketWin::TCPClientSocketWin(const AddressList& addresses, next_connect_state_(CONNECT_STATE_NONE), connect_os_error_(0), net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { + net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, NULL); EnsureWinsockInit(); } TCPClientSocketWin::~TCPClientSocketWin() { Disconnect(); - net_log_.AddEvent(NetLog::TYPE_TCP_SOCKET_DONE, NULL); + net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE, NULL); } int TCPClientSocketWin::Connect(CompletionCallback* callback) { diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index add273b..e8278a5 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -87,7 +87,8 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { &session_deps->socket_factory, session_deps->ssl_config_service, session_deps->spdy_session_pool, - session_deps->http_auth_handler_factory.get()); + session_deps->http_auth_handler_factory.get(), + NULL); } // Chop a frame into an array of MockWrites. diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc index ab7b12c..d022232 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -55,6 +55,7 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { &session_deps->socket_factory, session_deps->ssl_config_service, session_deps->spdy_session_pool, + NULL, NULL); } diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc index 3da9da73..84db904 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -78,7 +78,8 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { &session_deps->socket_factory, session_deps->ssl_config_service, session_deps->spdy_session_pool, - session_deps->http_auth_handler_factory.get()); + session_deps->http_auth_handler_factory.get(), + NULL); } class SpdyStreamTest : public testing::Test { diff --git a/net/tools/fetch/fetch_client.cc b/net/tools/fetch/fetch_client.cc index 5da7756..f939c2d 100644 --- a/net/tools/fetch/fetch_client.cc +++ b/net/tools/fetch/fetch_client.cc @@ -146,11 +146,13 @@ int main(int argc, char**argv) { factory = new net::HttpCache(NULL, host_resolver, proxy_service, ssl_config_service, http_auth_handler_factory.get(), + NULL, net::HttpCache::DefaultBackend::InMemory(0)); } else { factory = new net::HttpNetworkLayer( net::ClientSocketFactory::GetDefaultFactory(), NULL, host_resolver, - proxy_service, ssl_config_service, http_auth_handler_factory.get()); + proxy_service, ssl_config_service, http_auth_handler_factory.get(), + NULL); } { diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index 6f41e93..3546832 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -165,7 +165,8 @@ class TestURLRequestContext : public URLRequestContext { net::HttpNetworkLayer::CreateFactory(NULL, host_resolver_, proxy_service_, ssl_config_service_, - http_auth_handler_factory_), + http_auth_handler_factory_, + NULL), net::HttpCache::DefaultBackend::InMemory(0)); // In-memory cookie store. cookie_store_ = new net::CookieMonster(NULL, NULL); |