diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-16 07:03:53 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-16 07:03:53 +0000 |
commit | 9e743cddfd631038fe6f1cdde050e18d61319ec6 (patch) | |
tree | 7ef974e43b23f570433fe819bcd07966165c517f /net/socket_stream | |
parent | 2e7aff66fe443c29b2fc14a776dca5512b0b4729 (diff) | |
download | chromium_src-9e743cddfd631038fe6f1cdde050e18d61319ec6.zip chromium_src-9e743cddfd631038fe6f1cdde050e18d61319ec6.tar.gz chromium_src-9e743cddfd631038fe6f1cdde050e18d61319ec6.tar.bz2 |
Generalize the net module's LoadLog facility from a passive container, to an event stream (NetLog).
This makes it possible to associate a single NetLog with a URLRequestContext, and then attach observers to that log to watch the stream of events.
This changelist attempts to do the most direct translation, so there will be subsequent iterations to clean up.
The user-visible behavior should remain unchanged.
BUG=37421
Review URL: http://codereview.chromium.org/848006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket_stream')
-rw-r--r-- | net/socket_stream/socket_stream.cc | 49 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.h | 13 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_unittest.cc | 11 |
3 files changed, 27 insertions, 46 deletions
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index 04c68b0..03d7a9f 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -62,9 +62,7 @@ SocketStream::SocketStream(const GURL& url, Delegate* delegate) throttle_( SocketStreamThrottle::GetSocketStreamThrottleForScheme( url.scheme())), - metrics_(new SocketStreamMetrics(url)), - ALLOW_THIS_IN_INITIALIZER_LIST( - request_tracker_node_(this)) { + metrics_(new SocketStreamMetrics(url)) { DCHECK(MessageLoop::current()) << "The current MessageLoop must exist"; DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << @@ -96,15 +94,16 @@ void SocketStream::set_context(URLRequestContext* context) { context_ = context; if (prev_context != context) { - if (prev_context) - prev_context->socket_stream_tracker()->Remove(this); + net_log_.AddEvent(NetLog::TYPE_REQUEST_ALIVE); + net_log_ = BoundNetLog(); + if (context) { - if (!load_log_) { - // Create the LoadLog -- we waited until now to create it so we know - // what constraints the URLRequestContext is enforcing on log levels. - load_log_ = context->socket_stream_tracker()->CreateLoadLog(); - } - context->socket_stream_tracker()->Add(this); + net_log_ = BoundNetLog::Make( + context->net_log(), + NetLog::SOURCE_SOCKET_STREAM); + + net_log_.BeginEventWithString(NetLog::TYPE_REQUEST_ALIVE, + url_.possibly_invalid_spec()); } } @@ -127,7 +126,7 @@ void SocketStream::Connect() { // Open a connection asynchronously, so that delegate won't be called // back before returning Connect(). next_state_ = STATE_RESOLVE_PROXY; - LoadLog::BeginEvent(load_log_, LoadLog::TYPE_SOCKET_STREAM_CONNECT); + net_log_.BeginEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT); MessageLoop::current()->PostTask( FROM_HERE, NewRunnableMethod(this, &SocketStream::DoLoop, OK)); @@ -213,7 +212,7 @@ void SocketStream::DetachDelegate() { if (!delegate_) return; delegate_ = NULL; - LoadLog::AddEvent(load_log_, LoadLog::TYPE_CANCELLED); + net_log_.AddEvent(NetLog::TYPE_CANCELLED); Close(); } @@ -263,7 +262,7 @@ int SocketStream::DidEstablishConnection() { next_state_ = STATE_READ_WRITE; metrics_->OnConnected(); - LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKET_STREAM_CONNECT); + net_log_.EndEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT); if (delegate_) delegate_->OnConnected(this, max_pending_send_allowed_); @@ -273,7 +272,7 @@ int SocketStream::DidEstablishConnection() { int SocketStream::DidReceiveData(int result) { DCHECK(read_buf_); DCHECK_GT(result, 0); - LoadLog::AddEvent(load_log_, LoadLog::TYPE_SOCKET_STREAM_RECEIVED); + net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_RECEIVED); int len = result; metrics_->OnRead(len); result = throttle_->OnRead(this, read_buf_->data(), len, &io_callback_); @@ -287,7 +286,7 @@ int SocketStream::DidReceiveData(int result) { int SocketStream::DidSendData(int result) { DCHECK_GT(result, 0); - LoadLog::AddEvent(load_log_, LoadLog::TYPE_SOCKET_STREAM_SENT); + net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_SENT); int len = result; metrics_->OnWrite(len); result = throttle_->OnWrite(this, current_write_buf_->data(), len, @@ -411,7 +410,7 @@ void SocketStream::DoLoop(int result) { // close the connection. if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { DCHECK_EQ(next_state_, STATE_CLOSE); - LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKET_STREAM_CONNECT); + net_log_.EndEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT); } } while (result != ERR_IO_PENDING); } @@ -426,7 +425,7 @@ int SocketStream::DoResolveProxy() { } return proxy_service()->ResolveProxy( - proxy_url_, &proxy_info_, &io_callback_, &pac_request_, load_log_); + proxy_url_, &proxy_info_, &io_callback_, &pac_request_, net_log_); } int SocketStream::DoResolveProxyComplete(int result) { @@ -485,7 +484,7 @@ int SocketStream::DoResolveHost() { DCHECK(host_resolver_.get()); resolver_.reset(new SingleRequestHostResolver(host_resolver_.get())); return resolver_->Resolve(resolve_info, &addresses_, &io_callback_, - load_log_); + net_log_); } int SocketStream::DoResolveHostComplete(int result) { @@ -506,7 +505,7 @@ int SocketStream::DoTcpConnect() { DCHECK(factory_); socket_.reset(factory_->CreateTCPClientSocket(addresses_)); metrics_->OnStartConnection(); - return socket_->Connect(&io_callback_, load_log_); + return socket_->Connect(&io_callback_, net_log_); } int SocketStream::DoTcpConnectComplete(int result) { @@ -722,7 +721,7 @@ int SocketStream::DoSOCKSConnect() { s = new SOCKSClientSocket(s, req_info, host_resolver_.get()); socket_.reset(s); metrics_->OnSOCKSProxy(); - return socket_->Connect(&io_callback_, load_log_); + return socket_->Connect(&io_callback_, net_log_); } int SocketStream::DoSOCKSConnectComplete(int result) { @@ -745,7 +744,7 @@ int SocketStream::DoSSLConnect() { socket_.release(), url_.HostNoBrackets(), ssl_config_)); next_state_ = STATE_SSL_CONNECT_COMPLETE; metrics_->OnSSLConnection(); - return socket_->Connect(&io_callback_, load_log_); + return socket_->Connect(&io_callback_, net_log_); } int SocketStream::DoSSLConnectComplete(int result) { @@ -949,10 +948,4 @@ ProxyService* SocketStream::proxy_service() const { return context_->proxy_service(); } -void SocketStream::GetInfoForTracker( - RequestTracker<SocketStream>::RecentRequestInfo* info) const { - info->original_url = url_; - info->load_log = load_log_; -} - } // namespace net diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index 038d7a5..e8b250e 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -17,12 +17,12 @@ #include "net/base/address_list.h" #include "net/base/completion_callback.h" #include "net/base/io_buffer.h" +#include "net/base/net_log.h" #include "net/http/http_auth.h" #include "net/http/http_auth_cache.h" #include "net/http/http_auth_handler.h" #include "net/proxy/proxy_service.h" #include "net/socket/tcp_client_socket.h" -#include "net/url_request/request_tracker.h" #include "net/url_request/url_request_context.h" namespace net { @@ -31,7 +31,6 @@ class AuthChallengeInfo; class ClientSocketFactory; class HostResolver; class HttpAuthHandlerFactory; -class LoadLog; class SSLConfigService; class SingleRequestHostResolver; class SocketStreamMetrics; @@ -109,7 +108,7 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { URLRequestContext* context() const { return context_.get(); } void set_context(URLRequestContext* context); - LoadLog* load_log() const { return load_log_; } + BoundNetLog* net_log() { return &net_log_; } // Opens the connection on the IO thread. // Once the connection is established, calls delegate's OnConnected. @@ -207,7 +206,6 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { }; typedef std::deque< scoped_refptr<IOBufferWithSize> > PendingDataQueue; - friend class RequestTracker<SocketStream>; friend class WebSocketThrottleTest; @@ -256,10 +254,7 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { SSLConfigService* ssl_config_service() const; ProxyService* proxy_service() const; - void GetInfoForTracker( - RequestTracker<SocketStream>::RecentRequestInfo* info) const; - - scoped_refptr<LoadLog> load_log_; + BoundNetLog net_log_; GURL url_; int max_pending_send_allowed_; @@ -322,8 +317,6 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { scoped_ptr<SocketStreamMetrics> metrics_; - RequestTracker<SocketStream>::Node request_tracker_node_; - DISALLOW_COPY_AND_ASSIGN(SocketStream); }; diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index f1b5c6e..b3bdbbe 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -6,9 +6,9 @@ #include <vector> #include "base/callback.h" -#include "net/base/load_log.h" -#include "net/base/load_log_unittest.h" #include "net/base/mock_host_resolver.h" +#include "net/base/net_log.h" +#include "net/base/net_log_unittest.h" #include "net/base/test_completion_callback.h" #include "net/socket/socket_test_util.h" #include "net/socket_stream/socket_stream.h" @@ -211,12 +211,7 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type); EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[2].event_type); - // The first and last entries of the LoadLog should be for - // SOCKET_STREAM_CONNECT. - EXPECT_TRUE(LogContainsBeginEvent( - *socket_stream->load_log(), 0, LoadLog::TYPE_SOCKET_STREAM_CONNECT)); - EXPECT_TRUE(LogContainsEndEvent( - *socket_stream->load_log(), -1, LoadLog::TYPE_SOCKET_STREAM_CONNECT)); + // TODO(eroman): Add back NetLogTest here... } } // namespace net |