diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/base/net_log_event_type_list.h | 18 | ||||
-rw-r--r-- | net/http/http_network_transaction.cc | 3 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_session.cc | 92 | ||||
-rw-r--r-- | net/spdy/spdy_session.h | 11 | ||||
-rw-r--r-- | net/spdy/spdy_stream.cc | 5 | ||||
-rw-r--r-- | net/spdy/spdy_stream.h | 6 | ||||
-rw-r--r-- | net/spdy/spdy_stream_unittest.cc | 3 |
8 files changed, 106 insertions, 34 deletions
diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h index 8fdcf80..86e6ffd 100644 --- a/net/base/net_log_event_type_list.h +++ b/net/base/net_log_event_type_list.h @@ -367,12 +367,30 @@ EVENT_TYPE(SPDY_TRANSACTION_READ_BODY) // SpdyStream // ------------------------------------------------------------------------ +// This event is sent for a SPDY SYN_STREAM. +// The following parameters are attached: +// { +// "flags": <The control frame flags> +// "headers": <The list of header:value pairs> +// "id": <The stream id> +// } +EVENT_TYPE(SPDY_STREAM_SYN_STREAM) + // Measures the time taken to send headers on a stream. EVENT_TYPE(SPDY_STREAM_SEND_HEADERS) // Measures the time taken to send the body (e.g. a POST) on a stream. EVENT_TYPE(SPDY_STREAM_SEND_BODY) +// This event is sent for a SPDY SYN_REPLY. +// The following parameters are attached: +// { +// "flags": <The control frame flags> +// "headers": <The list of header:value pairs> +// "id": <The stream id> +// } +EVENT_TYPE(SPDY_STREAM_SYN_REPLY) + // Measures the time taken to read headers on a stream. EVENT_TYPE(SPDY_STREAM_READ_HEADERS) diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index eeb9941..c43f110 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -1392,7 +1392,8 @@ int HttpNetworkTransaction::DoSpdySendRequest() { return error_code; } headers_valid_ = false; - spdy_stream_ = spdy_session->GetOrCreateStream(*request_, upload_data); + spdy_stream_ = spdy_session->GetOrCreateStream( + *request_, upload_data, net_log_); return spdy_stream_->SendRequest(upload_data, &response_, &io_callback_); } diff --git a/net/spdy/spdy_network_transaction.cc b/net/spdy/spdy_network_transaction.cc index 3ad1702..20d833d 100644 --- a/net/spdy/spdy_network_transaction.cc +++ b/net/spdy/spdy_network_transaction.cc @@ -256,7 +256,7 @@ int SpdyNetworkTransaction::DoSendRequest() { if (!upload_data) return error_code; } - stream_ = spdy_->GetOrCreateStream(*request_, upload_data); + stream_ = spdy_->GetOrCreateStream(*request_, upload_data, net_log_); // Release the reference to |spdy_| since we don't need it anymore. spdy_ = NULL; return stream_->SendRequest(upload_data, &response_, &io_callback_); diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index d80d874..4208d06 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -5,6 +5,7 @@ #include "net/spdy/spdy_session.h" #include "base/basictypes.h" +#include "base/linked_ptr.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/rand_util.h" @@ -12,6 +13,7 @@ #include "base/stl_util-inl.h" #include "base/string_util.h" #include "base/time.h" +#include "base/values.h" #include "net/base/connection_type_histograms.h" #include "net/base/load_flags.h" #include "net/base/net_log.h" @@ -181,6 +183,36 @@ void AdjustSocketBufferSizes(ClientSocket* socket) { socket->SetSendBufferSize(kSocketBufferSize); } +class NetLogSpdySynParameter : public NetLog::EventParameters { + public: + NetLogSpdySynParameter(const linked_ptr<spdy::SpdyHeaderBlock>& headers, + spdy::SpdyControlFlags flags, + spdy::SpdyStreamId id) + : headers_(headers), flags_(flags), id_(id) {} + + Value* ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + DictionaryValue* headers_dict = new DictionaryValue(); + for (spdy::SpdyHeaderBlock::const_iterator it = headers_->begin(); + it != headers_->end(); ++it) { + headers_dict->SetString(ASCIIToWide(it->first), it->second); + } + dict->SetInteger(L"flags", flags_); + dict->Set(L"headers", headers_dict); + dict->SetInteger(L"id", id_); + return dict; + } + + private: + ~NetLogSpdySynParameter() {} + + const linked_ptr<spdy::SpdyHeaderBlock> headers_; + spdy::SpdyControlFlags flags_; + spdy::SpdyStreamId id_; + + DISALLOW_COPY_AND_ASSIGN(NetLogSpdySynParameter); +}; + } // namespace // static @@ -292,7 +324,8 @@ net::Error SpdySession::Connect(const std::string& group_name, scoped_refptr<SpdyStream> SpdySession::GetOrCreateStream( const HttpRequestInfo& request, - const UploadDataStream* upload_data) { + const UploadDataStream* upload_data, + const BoundNetLog& stream_net_log) { const GURL& url = request.url; const std::string& path = url.PathForRequest(); @@ -332,9 +365,10 @@ scoped_refptr<SpdyStream> SpdySession::GetOrCreateStream( // Server will assign a stream id when the push stream arrives. Use 0 for // now. net_log_.AddEvent(NetLog::TYPE_SPDY_STREAM_ADOPTED_PUSH_STREAM, NULL); - SpdyStream* stream = new SpdyStream(this, 0, true, net_log_); + SpdyStream* stream = new SpdyStream(this, 0, true); stream->SetRequestInfo(request); stream->set_path(path); + stream->set_net_log(stream_net_log); it->second = stream; return it->second; } @@ -342,10 +376,11 @@ scoped_refptr<SpdyStream> SpdySession::GetOrCreateStream( const spdy::SpdyStreamId stream_id = GetNewStreamId(); // If we still don't have a stream, activate one now. - stream = new SpdyStream(this, stream_id, false, net_log_); + stream = new SpdyStream(this, stream_id, false); stream->SetRequestInfo(request); stream->set_priority(request.priority); stream->set_path(path); + stream->set_net_log(stream_net_log); ActivateStream(stream); UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyPriorityCount", @@ -358,8 +393,8 @@ scoped_refptr<SpdyStream> SpdySession::GetOrCreateStream( request.priority <= SPDY_PRIORITY_LOWEST); // Convert from HttpRequestHeaders to Spdy Headers. - spdy::SpdyHeaderBlock headers; - CreateSpdyHeadersFromHttpRequest(request, &headers); + linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); + CreateSpdyHeadersFromHttpRequest(request, headers.get()); spdy::SpdyControlFlags flags = spdy::CONTROL_FLAG_NONE; if (!request.upload_data || !upload_data->size()) @@ -368,7 +403,7 @@ scoped_refptr<SpdyStream> SpdySession::GetOrCreateStream( // Create a SYN_STREAM packet and add to the output queue. scoped_ptr<spdy::SpdySynStreamControlFrame> syn_frame( spdy_framer_.CreateSynStream(stream_id, 0, request.priority, flags, false, - &headers)); + headers.get())); QueueFrame(syn_frame.get(), request.priority, stream); static StatsCounter spdy_requests("spdy.requests"); @@ -378,7 +413,13 @@ scoped_refptr<SpdyStream> SpdySession::GetOrCreateStream( streams_initiated_count_++; LOG(INFO) << "SPDY SYN_STREAM HEADERS ----------------------------------"; - DumpSpdyHeaders(headers); + DumpSpdyHeaders(*headers); + + if (stream_net_log.HasListener()) { + stream_net_log.AddEvent( + NetLog::TYPE_SPDY_STREAM_SYN_STREAM, + new NetLogSpdySynParameter(headers, flags, stream_id)); + } return stream; } @@ -922,7 +963,7 @@ bool SpdySession::Respond(const spdy::SpdyHeaderBlock& headers, } void SpdySession::OnSyn(const spdy::SpdySynStreamControlFrame& frame, - const spdy::SpdyHeaderBlock& headers) { + const linked_ptr<spdy::SpdyHeaderBlock>& headers) { spdy::SpdyStreamId stream_id = frame.stream_id(); LOG(INFO) << "Spdy SynStream for stream " << stream_id; @@ -943,12 +984,12 @@ void SpdySession::OnSyn(const spdy::SpdySynStreamControlFrame& frame, LOG(INFO) << "SpdySession: Syn received for stream: " << stream_id; LOG(INFO) << "SPDY SYN RESPONSE HEADERS -----------------------"; - DumpSpdyHeaders(headers); + DumpSpdyHeaders(*headers); // TODO(mbelshe): DCHECK that this is a GET method? - const std::string& path = ContainsKey(headers, "path") ? - headers.find("path")->second : ""; + const std::string& path = ContainsKey(*headers, "path") ? + headers->find("path")->second : ""; // Verify that the response had a URL for us. DCHECK(!path.empty()); @@ -972,8 +1013,8 @@ void SpdySession::OnSyn(const spdy::SpdySynStreamControlFrame& frame, CHECK_EQ(0u, stream->stream_id()); stream->set_stream_id(stream_id); } else { - // TODO(mbelshe): can we figure out how to use a NetLog here? - stream = new SpdyStream(this, stream_id, true, BoundNetLog()); + // TODO(willchan): can we figure out how to use a NetLog here? + stream = new SpdyStream(this, stream_id, true); // A new HttpResponseInfo object needs to be generated so the call to // OnResponseReceived below has something to fill in. @@ -992,7 +1033,7 @@ void SpdySession::OnSyn(const spdy::SpdySynStreamControlFrame& frame, stream->set_path(path); - if (!Respond(headers, stream)) + if (!Respond(*headers, stream)) return; LOG(INFO) << "Got pushed stream for " << stream->path(); @@ -1002,7 +1043,7 @@ void SpdySession::OnSyn(const spdy::SpdySynStreamControlFrame& frame, } void SpdySession::OnSynReply(const spdy::SpdySynReplyControlFrame& frame, - const spdy::SpdyHeaderBlock& headers) { + const linked_ptr<spdy::SpdyHeaderBlock>& headers) { spdy::SpdyStreamId stream_id = frame.stream_id(); LOG(INFO) << "Spdy SynReply for stream " << stream_id; @@ -1014,14 +1055,14 @@ void SpdySession::OnSynReply(const spdy::SpdySynReplyControlFrame& frame, } LOG(INFO) << "SPDY SYN_REPLY RESPONSE HEADERS for stream: " << stream_id; - DumpSpdyHeaders(headers); + DumpSpdyHeaders(*headers); // We record content declared as being pushed so that we don't // request a duplicate stream which is already scheduled to be // sent to us. spdy::SpdyHeaderBlock::const_iterator it; - it = headers.find("x-associated-content"); - if (it != headers.end()) { + it = headers->find("x-associated-content"); + if (it != headers->end()) { const std::string& content = it->second; std::string::size_type start = 0; std::string::size_type end = 0; @@ -1048,14 +1089,23 @@ void SpdySession::OnSynReply(const spdy::SpdySynReplyControlFrame& frame, CHECK_EQ(stream->stream_id(), stream_id); CHECK(!stream->cancelled()); - Respond(headers, stream); + const BoundNetLog& log = stream->net_log(); + if (log.HasListener()) { + log.AddEvent( + NetLog::TYPE_SPDY_STREAM_SYN_REPLY, + new NetLogSpdySynParameter( + headers, static_cast<spdy::SpdyControlFlags>(frame.flags()), + stream_id)); + } + + Respond(*headers, stream); } void SpdySession::OnControl(const spdy::SpdyControlFrame* frame) { - spdy::SpdyHeaderBlock headers; + const linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); uint32 type = frame->type(); if (type == spdy::SYN_STREAM || type == spdy::SYN_REPLY) { - if (!spdy_framer_.ParseHeaderBlock(frame, &headers)) { + if (!spdy_framer_.ParseHeaderBlock(frame, headers.get())) { LOG(WARNING) << "Could not parse Spdy Control Frame Header"; // TODO(mbelshe): Error the session? return; diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h index 5382867..8ef2da0 100644 --- a/net/spdy/spdy_session.h +++ b/net/spdy/spdy_session.h @@ -11,6 +11,7 @@ #include <queue> #include <string> +#include "base/linked_ptr.h" #include "base/ref_counted.h" #include "net/base/io_buffer.h" #include "net/base/load_states.h" @@ -63,8 +64,10 @@ class SpdySession : public base::RefCounted<SpdySession>, // might also not have initiated the stream yet, but indicated it will via // X-Associated-Content. // Returns the new or existing stream. Never returns NULL. - scoped_refptr<SpdyStream> GetOrCreateStream(const HttpRequestInfo& request, - const UploadDataStream* upload_data); + scoped_refptr<SpdyStream> GetOrCreateStream( + const HttpRequestInfo& request, + const UploadDataStream* upload_data, + const BoundNetLog& stream_net_log); // Used by SpdySessionPool to initialize with a pre-existing SSL socket. void InitializeWithSSLSocket(ClientSocketHandle* connection); @@ -118,9 +121,9 @@ class SpdySession : public base::RefCounted<SpdySession>, // Control frame handlers. void OnSyn(const spdy::SpdySynStreamControlFrame& frame, - const spdy::SpdyHeaderBlock& headers); + const linked_ptr<spdy::SpdyHeaderBlock>& headers); void OnSynReply(const spdy::SpdySynReplyControlFrame& frame, - const spdy::SpdyHeaderBlock& headers); + const linked_ptr<spdy::SpdyHeaderBlock>& headers); void OnFin(const spdy::SpdyRstStreamControlFrame& frame); void OnGoAway(const spdy::SpdyGoAwayControlFrame& frame); void OnSettings(const spdy::SpdySettingsControlFrame& frame); diff --git a/net/spdy/spdy_stream.cc b/net/spdy/spdy_stream.cc index 547a1f0..74ad637 100644 --- a/net/spdy/spdy_stream.cc +++ b/net/spdy/spdy_stream.cc @@ -12,8 +12,8 @@ namespace net { -SpdyStream::SpdyStream(SpdySession* session, spdy::SpdyStreamId stream_id, - bool pushed, const BoundNetLog& log) +SpdyStream::SpdyStream( + SpdySession* session, spdy::SpdyStreamId stream_id, bool pushed) : stream_id_(stream_id), priority_(0), pushed_(pushed), @@ -30,7 +30,6 @@ SpdyStream::SpdyStream(SpdySession* session, spdy::SpdyStreamId stream_id, user_buffer_(NULL), user_buffer_len_(0), cancelled_(false), - net_log_(log), send_bytes_(0), recv_bytes_(0), histograms_recorded_(false), diff --git a/net/spdy/spdy_stream.h b/net/spdy/spdy_stream.h index 37f6900bf..bfd79d0 100644 --- a/net/spdy/spdy_stream.h +++ b/net/spdy/spdy_stream.h @@ -37,8 +37,7 @@ class UploadDataStream; class SpdyStream : public base::RefCounted<SpdyStream> { public: // SpdyStream constructor - SpdyStream(SpdySession* session, spdy::SpdyStreamId stream_id, bool pushed, - const BoundNetLog& log); + SpdyStream(SpdySession* session, spdy::SpdyStreamId stream_id, bool pushed); // Ideally I'd use two abstract classes as interfaces for these two sections, // but since we're ref counted, I can't make both abstract classes inherit @@ -90,6 +89,9 @@ class SpdyStream : public base::RefCounted<SpdyStream> { int priority() const { return priority_; } void set_priority(int priority) { priority_ = priority; } + const BoundNetLog& net_log() const { return net_log_; } + void set_net_log(const BoundNetLog& log) { net_log_ = log; } + const HttpResponseInfo* GetResponseInfo() const; const HttpRequestInfo* GetRequestInfo() const; void SetRequestInfo(const HttpRequestInfo& request); diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc index 64f3a8b..3da9da73 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -113,8 +113,7 @@ TEST_F(SpdyStreamTest, SendRequest) { TestCompletionCallback callback; HttpResponseInfo response; - scoped_refptr<SpdyStream> stream(new SpdyStream(session, 1, false, - BoundNetLog())); + scoped_refptr<SpdyStream> stream(new SpdyStream(session, 1, false)); stream->SetRequestInfo(request); EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(NULL, &response, &callback)); |