Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_basic_stream.h" | 5 #include "net/http/http_basic_stream.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | |
| 7 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 8 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 9 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 10 #include "net/http/http_request_headers.h" | 11 #include "net/http/http_request_headers.h" |
| 11 #include "net/http/http_request_info.h" | 12 #include "net/http/http_request_info.h" |
| 12 #include "net/http/http_stream_parser.h" | 13 #include "net/http/http_stream_parser.h" |
| 13 #include "net/http/http_util.h" | 14 #include "net/http/http_util.h" |
| 14 #include "net/socket/client_socket_handle.h" | 15 #include "net/socket/client_socket_handle.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 19 // static | |
| 20 std::string HttpBasicStream::g_warm_connection_field_trial_group_; | |
| 21 | |
| 18 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, | 22 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, |
| 19 HttpStreamParser* parser, | 23 HttpStreamParser* parser, |
| 20 bool using_proxy) | 24 bool using_proxy) |
| 21 : read_buf_(new GrowableIOBuffer()), | 25 : read_buf_(new GrowableIOBuffer()), |
| 22 parser_(parser), | 26 parser_(parser), |
| 23 connection_(connection), | 27 connection_(connection), |
| 24 using_proxy_(using_proxy), | 28 using_proxy_(using_proxy), |
| 25 request_info_(NULL) { | 29 request_info_(NULL) { |
| 26 } | 30 } |
| 27 | 31 |
| 28 HttpBasicStream::~HttpBasicStream() {} | 32 HttpBasicStream::~HttpBasicStream() {} |
| 29 | 33 |
| 30 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, | 34 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, |
| 31 const BoundNetLog& net_log, | 35 const BoundNetLog& net_log, |
| 32 CompletionCallback* callback) { | 36 CompletionCallback* callback) { |
| 33 DCHECK(!parser_.get()); | 37 DCHECK(!parser_.get()); |
| 34 request_info_ = request_info; | 38 request_info_ = request_info; |
| 35 parser_.reset(new HttpStreamParser(connection_.get(), request_info, | 39 parser_.reset(new HttpStreamParser(connection_.get(), request_info, |
| 36 read_buf_, net_log)); | 40 read_buf_, net_log)); |
| 41 bytes_read_offset_ = connection_->socket()->NumBytesRead(); | |
| 37 return OK; | 42 return OK; |
| 38 } | 43 } |
| 39 | 44 |
| 40 | 45 |
| 41 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, | 46 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, |
| 42 UploadDataStream* request_body, | 47 UploadDataStream* request_body, |
| 43 HttpResponseInfo* response, | 48 HttpResponseInfo* response, |
| 44 CompletionCallback* callback) { | 49 CompletionCallback* callback) { |
| 45 DCHECK(parser_.get()); | 50 DCHECK(parser_.get()); |
| 46 DCHECK(request_info_); | 51 DCHECK(request_info_); |
| 47 const std::string path = using_proxy_ ? | 52 const std::string path = using_proxy_ ? |
| 48 HttpUtil::SpecForRequest(request_info_->url) : | 53 HttpUtil::SpecForRequest(request_info_->url) : |
| 49 HttpUtil::PathForRequest(request_info_->url); | 54 HttpUtil::PathForRequest(request_info_->url); |
| 50 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", | 55 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", |
| 51 request_info_->method.c_str(), | 56 request_info_->method.c_str(), |
| 52 path.c_str()); | 57 path.c_str()); |
| 58 response_ = response; | |
| 53 return parser_->SendRequest(request_line_, headers, request_body, response, | 59 return parser_->SendRequest(request_line_, headers, request_body, response, |
| 54 callback); | 60 callback); |
| 55 } | 61 } |
| 56 | 62 |
| 57 uint64 HttpBasicStream::GetUploadProgress() const { | 63 uint64 HttpBasicStream::GetUploadProgress() const { |
| 58 return parser_->GetUploadProgress(); | 64 return parser_->GetUploadProgress(); |
| 59 } | 65 } |
| 60 | 66 |
| 61 int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) { | 67 int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) { |
| 62 return parser_->ReadResponseHeaders(callback); | 68 return parser_->ReadResponseHeaders(callback); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 | 118 |
| 113 void HttpBasicStream::GetSSLCertRequestInfo( | 119 void HttpBasicStream::GetSSLCertRequestInfo( |
| 114 SSLCertRequestInfo* cert_request_info) { | 120 SSLCertRequestInfo* cert_request_info) { |
| 115 parser_->GetSSLCertRequestInfo(cert_request_info); | 121 parser_->GetSSLCertRequestInfo(cert_request_info); |
| 116 } | 122 } |
| 117 | 123 |
| 118 bool HttpBasicStream::IsSpdyHttpStream() const { | 124 bool HttpBasicStream::IsSpdyHttpStream() const { |
| 119 return false; | 125 return false; |
| 120 } | 126 } |
| 121 | 127 |
| 128 void HttpBasicStream::LogNumRttVsBytesMetrics() const { | |
| 129 int64 total_bytes_read = connection_->socket()->NumBytesRead(); | |
| 130 int64 bytes_received = total_bytes_read - bytes_read_offset_; | |
| 131 int64 num_kb = bytes_received / 1024; | |
| 132 double rtt = connection_->socket()->GetConnectTimeMicros() / 1000; | |
| 133 | |
| 134 if (num_kb < 1024 && rtt > 0) { // Ignore responses > 1MB | |
| 135 base::TimeDelta duration = base::Time::Now() - | |
| 136 response_->request_time; | |
| 137 double num_rtt = static_cast<double>(duration.InMilliseconds()) / rtt; | |
| 138 int64 num_rtt_scaled = (4 * num_rtt); | |
| 139 | |
| 140 // Integer representation of <num_kb, num_rtt_scaled> tuple. | |
| 141 int val = 1024 * num_rtt_scaled + num_kb; | |
|
Mike Belshe
2011/06/10 18:11:42
I think this is ridiculous still. I see that you'
Gagan
2011/06/12 20:11:44
Done.
| |
| 142 | |
| 143 std::string histogram = "Net.RTT_vs_KB_"; | |
| 144 histogram.append(g_warm_connection_field_trial_group_); | |
|
Mike Belshe
2011/06/10 18:11:42
OK - I see, g_warm_connection_field_trial_group is
Gagan
2011/06/12 20:11:44
Done.
| |
| 145 HISTOGRAM_CUSTOM_COUNTS(histogram, val, 4096, 3048000, 1000); | |
| 146 LOG(ERROR) << request_line_ | |
| 147 << "\nrtt = " << rtt << "\tnum_rtt = " << num_rtt | |
| 148 << "\tnum_kb = " << num_kb << "\tval = " << val | |
| 149 << "\ttotal bytes = " << total_bytes_read; | |
| 150 } | |
| 151 } | |
| 152 | |
| 122 } // namespace net | 153 } // namespace net |
| OLD | NEW |