summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/debugger/devtools_netlog_observer.cc2
-rw-r--r--chrome/browser/dom_ui/net_internals_ui.cc35
-rw-r--r--chrome/browser/net/chrome_net_log.cc8
-rw-r--r--chrome/browser/net/chrome_net_log.h4
-rw-r--r--chrome/browser/net/net_log_logger.cc2
-rw-r--r--chrome/browser/resources/net_internals/dataview.js17
-rw-r--r--chrome/browser/resources/net_internals/index.html10
-rw-r--r--chrome/browser/resources/net_internals/logviewpainter.js48
-rw-r--r--chrome/browser/resources/net_internals/main.js11
-rw-r--r--net/base/capturing_net_log.h2
-rw-r--r--net/base/forwarding_net_log.cc2
-rw-r--r--net/base/net_log.cc6
-rw-r--r--net/base/net_log.h10
-rw-r--r--net/base/net_log_event_type_list.h8
-rw-r--r--net/http/http_network_transaction.cc6
-rw-r--r--net/http/http_proxy_client_socket.cc4
-rw-r--r--net/proxy/proxy_service.cc4
-rw-r--r--net/socket/client_socket.cc51
-rw-r--r--net/socket/client_socket.h8
-rw-r--r--net/socket/tcp_client_socket_libevent.cc16
-rw-r--r--net/socket/tcp_client_socket_pool.cc4
-rw-r--r--net/socket/tcp_client_socket_win.cc16
-rw-r--r--net/spdy/spdy_proxy_client_socket.cc4
-rw-r--r--net/spdy/spdy_session.cc10
-rw-r--r--net/url_request/url_request.cc2
25 files changed, 242 insertions, 48 deletions
diff --git a/chrome/browser/debugger/devtools_netlog_observer.cc b/chrome/browser/debugger/devtools_netlog_observer.cc
index fa80e43..a9113b4 100644
--- a/chrome/browser/debugger/devtools_netlog_observer.cc
+++ b/chrome/browser/debugger/devtools_netlog_observer.cc
@@ -17,7 +17,7 @@ const size_t kMaxNumEntries = 1000;
DevToolsNetLogObserver* DevToolsNetLogObserver::instance_ = NULL;
DevToolsNetLogObserver::DevToolsNetLogObserver(ChromeNetLog* chrome_net_log)
- : ChromeNetLog::Observer(net::NetLog::LOG_ALL),
+ : ChromeNetLog::Observer(net::NetLog::LOG_ALL_BUT_BYTES),
chrome_net_log_(chrome_net_log) {
chrome_net_log_->AddObserver(this);
}
diff --git a/chrome/browser/dom_ui/net_internals_ui.cc b/chrome/browser/dom_ui/net_internals_ui.cc
index 93e1262..6502b70 100644
--- a/chrome/browser/dom_ui/net_internals_ui.cc
+++ b/chrome/browser/dom_ui/net_internals_ui.cc
@@ -210,6 +210,8 @@ class NetInternalsMessageHandler::IOThreadImpl
void OnGetServiceProviders(const ListValue* list);
#endif
+ void OnSetLogLevel(const ListValue* list);
+
// ChromeNetLog::Observer implementation:
virtual void OnAddEntry(net::NetLog::EventType type,
const base::TimeTicks& time,
@@ -403,6 +405,10 @@ void NetInternalsMessageHandler::RegisterMessages() {
"getServiceProviders",
proxy_->CreateCallback(&IOThreadImpl::OnGetServiceProviders));
#endif
+
+ dom_ui_->RegisterMessageCallback(
+ "setLogLevel",
+ proxy_->CreateCallback(&IOThreadImpl::OnSetLogLevel));
}
void NetInternalsMessageHandler::CallJavascriptFunction(
@@ -426,7 +432,7 @@ NetInternalsMessageHandler::IOThreadImpl::IOThreadImpl(
const base::WeakPtr<NetInternalsMessageHandler>& handler,
IOThread* io_thread,
URLRequestContextGetter* context_getter)
- : Observer(net::NetLog::LOG_ALL),
+ : Observer(net::NetLog::LOG_ALL_BUT_BYTES),
handler_(handler),
io_thread_(io_thread),
context_getter_(context_getter),
@@ -559,6 +565,18 @@ void NetInternalsMessageHandler::IOThreadImpl::OnRendererReady(
CallJavascriptFunction(L"g_browser.receivedLogSourceTypeConstants", dict);
}
+ // Tell the javascript about the relationship between LogLevel enums and their
+ // symbolic names.
+ {
+ DictionaryValue* dict = new DictionaryValue();
+
+ dict->SetInteger("LOG_ALL", net::NetLog::LOG_ALL);
+ dict->SetInteger("LOG_ALL_BUT_BYTES", net::NetLog::LOG_ALL_BUT_BYTES);
+ dict->SetInteger("LOG_BASIC", net::NetLog::LOG_BASIC);
+
+ CallJavascriptFunction(L"g_browser.receivedLogLevelConstants", dict);
+ }
+
// Tell the javascript about the relationship between address family enums and
// their symbolic names.
{
@@ -890,6 +908,21 @@ void NetInternalsMessageHandler::IOThreadImpl::OnGetServiceProviders(
}
#endif
+void NetInternalsMessageHandler::IOThreadImpl::OnSetLogLevel(
+ const ListValue* list) {
+ int log_level;
+ std::string log_level_string;
+ if (!list->GetString(0, &log_level_string) ||
+ !base::StringToInt(log_level_string, &log_level)) {
+ NOTREACHED();
+ return;
+ }
+
+ DCHECK_GE(log_level, net::NetLog::LOG_ALL);
+ DCHECK_LE(log_level, net::NetLog::LOG_BASIC);
+ set_log_level(static_cast<net::NetLog::LogLevel>(log_level));
+}
+
void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry(
net::NetLog::EventType type,
const base::TimeTicks& time,
diff --git a/chrome/browser/net/chrome_net_log.cc b/chrome/browser/net/chrome_net_log.cc
index 92daba0..b6ef86e 100644
--- a/chrome/browser/net/chrome_net_log.cc
+++ b/chrome/browser/net/chrome_net_log.cc
@@ -17,6 +17,14 @@
ChromeNetLog::Observer::Observer(LogLevel log_level) : log_level_(log_level) {}
+net::NetLog::LogLevel ChromeNetLog::Observer::log_level() const {
+ return log_level_;
+}
+
+void ChromeNetLog::Observer::set_log_level(net::NetLog::LogLevel log_level) {
+ log_level_ = log_level;
+}
+
ChromeNetLog::ChromeNetLog()
: next_id_(1),
passive_collector_(new PassiveLogCollector),
diff --git a/chrome/browser/net/chrome_net_log.h b/chrome/browser/net/chrome_net_log.h
index 24183bf..aac09e6 100644
--- a/chrome/browser/net/chrome_net_log.h
+++ b/chrome/browser/net/chrome_net_log.h
@@ -44,7 +44,9 @@ class ChromeNetLog : public net::NetLog {
const Source& source,
EventPhase phase,
EventParameters* params) = 0;
- LogLevel log_level() const { return log_level_; }
+ LogLevel log_level() const;
+ protected:
+ void set_log_level(LogLevel log_level);
private:
LogLevel log_level_;
DISALLOW_COPY_AND_ASSIGN(Observer);
diff --git a/chrome/browser/net/net_log_logger.cc b/chrome/browser/net/net_log_logger.cc
index 4f5021f..5db7657 100644
--- a/chrome/browser/net/net_log_logger.cc
+++ b/chrome/browser/net/net_log_logger.cc
@@ -7,7 +7,7 @@
#include "base/json/json_writer.h"
#include "base/values.h"
-NetLogLogger::NetLogLogger() : Observer(net::NetLog::LOG_ALL) {}
+NetLogLogger::NetLogLogger() : Observer(net::NetLog::LOG_ALL_BUT_BYTES) {}
NetLogLogger::~NetLogLogger() {}
diff --git a/chrome/browser/resources/net_internals/dataview.js b/chrome/browser/resources/net_internals/dataview.js
index 2138a83..38dc5a3 100644
--- a/chrome/browser/resources/net_internals/dataview.js
+++ b/chrome/browser/resources/net_internals/dataview.js
@@ -16,6 +16,7 @@ function DataView(mainBoxId,
outputTextBoxId,
exportTextButtonId,
securityStrippingCheckboxId,
+ byteLoggingCheckboxId,
passivelyCapturedCountId,
activelyCapturedCountId,
deleteAllId) {
@@ -25,6 +26,10 @@ function DataView(mainBoxId,
this.securityStrippingCheckbox_ =
document.getElementById(securityStrippingCheckboxId);
+ var byteLoggingCheckbox = document.getElementById(byteLoggingCheckboxId);
+ byteLoggingCheckbox.onclick =
+ this.onSetByteLogging_.bind(this, byteLoggingCheckbox);
+
var exportTextButton = document.getElementById(exportTextButtonId);
exportTextButton.onclick = this.onExportToText_.bind(this);
@@ -76,6 +81,18 @@ DataView.prototype.updateEventCounts_ = function() {
};
/**
+ * Depending on the value of the checkbox, enables or disables logging of
+ * actual bytes transferred.
+ */
+DataView.prototype.onSetByteLogging_ = function(byteLoggingCheckbox) {
+ if (byteLoggingCheckbox.checked) {
+ g_browser.setLogLevel(LogLevelType.LOG_ALL);
+ } else {
+ g_browser.setLogLevel(LogLevelType.LOG_ALL_BUT_BYTES);
+ }
+};
+
+/**
* If not already waiting for results from all updates, triggers all
* updates and starts waiting for them to complete.
*/
diff --git a/chrome/browser/resources/net_internals/index.html b/chrome/browser/resources/net_internals/index.html
index 483d932..d146242 100644
--- a/chrome/browser/resources/net_internals/index.html
+++ b/chrome/browser/resources/net_internals/index.html
@@ -191,9 +191,8 @@ found in the LICENSE file.
<td valign=top>
<h2>Dump data</h2>
<div style="margin: 8px">
- <p>
- <input id=securityStrippingCheckbox type=checkbox checked=yes>
- Strip private information (cookies and credentials).
+ <p><input id=securityStrippingCheckbox type=checkbox checked=yes>
+ Strip private information (cookies and credentials).
</p>
<p>
<a href="javascript:displayHelpForBugDump()">
@@ -217,7 +216,10 @@ found in the LICENSE file.
<td align=right id=activelyCapturedCount></td>
</tr>
</table>
- <input type=button value="Delete all" id=dataViewDeleteAll />
+ <p><input type=button value="Delete all" id=dataViewDeleteAll /></p>
+ <p><input id=byteLoggingCheckbox type=checkbox>
+ Log actual bytes sent/received.
+ </p>
</div>
</td>
diff --git a/chrome/browser/resources/net_internals/logviewpainter.js b/chrome/browser/resources/net_internals/logviewpainter.js
index d82a027..3d6d7e1 100644
--- a/chrome/browser/resources/net_internals/logviewpainter.js
+++ b/chrome/browser/resources/net_internals/logviewpainter.js
@@ -136,6 +136,47 @@ PrintSourceEntriesAsText = function(sourceEntries, doSecurityStripping) {
return tablePrinter.toText(0);
}
+/**
+ * |hexString| must be a string of hexadecimal characters with no whitespace,
+ * whose length is a multiple of two. Returns a string spanning multiple lines,
+ * with the hexadecimal characters from |hexString| on the left, in groups of
+ * two, and their corresponding ASCII characters on the right.
+ *
+ * |asciiCharsPerLine| specifies how many ASCII characters will be put on each
+ * line of the output string.
+ */
+function formatHexString(hexString, asciiCharsPerLine) {
+ // Number of transferred bytes in a line of output. Length of a
+ // line is roughly 4 times larger.
+ var hexCharsPerLine = 2 * asciiCharsPerLine;
+ var out = [];
+ for (var i = 0; i < hexString.length; i += hexCharsPerLine) {
+ var hexLine = '';
+ var asciiLine = '';
+ for (var j = i; j < i + hexCharsPerLine && j < hexString.length; j += 2) {
+ var hex = hexString.substr(j, 2);
+ hexLine += hex + ' ';
+ var charCode = parseInt(hex, 16);
+ // For ASCII codes 32 though 126, display the corresponding
+ // characters. Use a space for nulls, and a period for
+ // everything else.
+ if (charCode >= 0x20 && charCode <= 0x7E) {
+ asciiLine += String.fromCharCode(charCode);
+ } else if (charCode == 0x00) {
+ asciiLine += ' ';
+ } else {
+ asciiLine += '.';
+ }
+ }
+
+ // Max sure the ASCII text on last line of output lines up with previous
+ // lines.
+ hexLine += makeRepeatedString(' ', 3 * asciiCharsPerLine - hexLine.length);
+ out.push(' ' + hexLine + ' ' + asciiLine);
+ }
+ return out.join('\n');
+}
+
function getTextForExtraParams(entry, doSecurityStripping) {
// Format the extra parameters (use a custom formatter for certain types,
// but default to displaying as JSON).
@@ -160,6 +201,13 @@ function getTextForExtraParams(entry, doSecurityStripping) {
continue;
}
var value = entry.params[k];
+ // For transferred bytes, display the bytes in hex and ASCII.
+ if (k == 'hex_encoded_bytes') {
+ out.push(' --> ' + k + ' =');
+ out.push(formatHexString(value, 20));
+ continue;
+ }
+
var paramStr = ' --> ' + k + ' = ' + JSON.stringify(value);
// Append the symbolic name for certain constants. (This relies
diff --git a/chrome/browser/resources/net_internals/main.js b/chrome/browser/resources/net_internals/main.js
index 1702085..e71fade 100644
--- a/chrome/browser/resources/net_internals/main.js
+++ b/chrome/browser/resources/net_internals/main.js
@@ -9,6 +9,7 @@ var LogEventType = null;
var LogEventPhase = null;
var ClientInfo = null;
var LogSourceType = null;
+var LogLevelType = null;
var NetError = null;
var LoadFlag = null;
var AddressFamily = null;
@@ -73,6 +74,7 @@ function onLoaded() {
// captured data.
var dataView = new DataView("dataTabContent", "exportedDataText",
"exportToText", "securityStrippingCheckbox",
+ "byteLoggingCheckbox",
"passivelyCapturedCount",
"activelyCapturedCount",
"dataViewDeleteAll");
@@ -296,6 +298,10 @@ BrowserBridge.prototype.enableIPv6 = function() {
chrome.send('enableIPv6');
};
+BrowserBridge.prototype.setLogLevel = function(logLevel) {
+ chrome.send('setLogLevel', ['' + logLevel]);
+}
+
//------------------------------------------------------------------------------
// Messages received from the browser
//------------------------------------------------------------------------------
@@ -333,6 +339,11 @@ function(constantsMap) {
LogSourceType = constantsMap;
};
+BrowserBridge.prototype.receivedLogLevelConstants =
+function(constantsMap) {
+ LogLevelType = constantsMap;
+};
+
BrowserBridge.prototype.receivedLoadFlagConstants = function(constantsMap) {
LoadFlag = constantsMap;
};
diff --git a/net/base/capturing_net_log.h b/net/base/capturing_net_log.h
index 6e0f620..ff7cf16 100644
--- a/net/base/capturing_net_log.h
+++ b/net/base/capturing_net_log.h
@@ -52,7 +52,7 @@ class CapturingNetLog : public NetLog {
EventPhase phase,
EventParameters* extra_parameters);
virtual uint32 NextID();
- virtual LogLevel GetLogLevel() const { return LOG_ALL; }
+ virtual LogLevel GetLogLevel() const { return LOG_ALL_BUT_BYTES; }
// Returns the list of all entries in the log.
const EntryList& entries() const { return entries_; }
diff --git a/net/base/forwarding_net_log.cc b/net/base/forwarding_net_log.cc
index efe6eff..7cfd6a9 100644
--- a/net/base/forwarding_net_log.cc
+++ b/net/base/forwarding_net_log.cc
@@ -89,7 +89,7 @@ uint32 ForwardingNetLog::NextID() {
NetLog::LogLevel ForwardingNetLog::GetLogLevel() const {
// Can't forward a synchronous API.
CHECK(false) << "Not supported";
- return LOG_ALL;
+ return LOG_ALL_BUT_BYTES;
}
} // namespace net
diff --git a/net/base/net_log.cc b/net/base/net_log.cc
index f9f31c7..1499d72 100644
--- a/net/base/net_log.cc
+++ b/net/base/net_log.cc
@@ -131,10 +131,14 @@ NetLog::LogLevel BoundNetLog::GetLogLevel() const {
return NetLog::LOG_BASIC;
}
-bool BoundNetLog::IsLoggingAll() const {
+bool BoundNetLog::IsLoggingBytes() const {
return GetLogLevel() == NetLog::LOG_ALL;
}
+bool BoundNetLog::IsLoggingAllEvents() const {
+ return GetLogLevel() <= NetLog::LOG_ALL_BUT_BYTES;
+}
+
void BoundNetLog::AddEvent(
NetLog::EventType event_type,
const scoped_refptr<NetLog::EventParameters>& params) const {
diff --git a/net/base/net_log.h b/net/base/net_log.h
index f240105..aa0b70e5 100644
--- a/net/base/net_log.h
+++ b/net/base/net_log.h
@@ -98,8 +98,13 @@ class NetLog {
// Specifies the granularity of events that should be emitted to the log.
enum LogLevel {
// Log everything possible, even if it is slow and memory expensive.
+ // Includes logging of transferred bytes.
LOG_ALL,
+ // Log all events, but do not include the actual transferred bytes as
+ // parameters for bytes sent/received events.
+ LOG_ALL_BUT_BYTES,
+
// Only log events which are cheap, and don't consume much memory.
LOG_BASIC,
};
@@ -194,7 +199,10 @@ class BoundNetLog {
NetLog::LogLevel GetLogLevel() const;
// Returns true if the log level is LOG_ALL.
- bool IsLoggingAll() const;
+ bool IsLoggingBytes() const;
+
+ // Returns true if the log level is LOG_ALL or LOG_ALL_BUT_BYTES.
+ bool IsLoggingAllEvents() const;
// Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care
// of creating a unique source ID, and handles the case of NULL net_log.
diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h
index b0b4d4b..398f7c1 100644
--- a/net/base/net_log_event_type_list.h
+++ b/net/base/net_log_event_type_list.h
@@ -347,14 +347,18 @@ EVENT_TYPE(SSL_NSS_ERROR)
// The specified number of bytes were sent on the socket.
// The following parameters are attached:
// {
-// "num_bytes": <Number of bytes that were just sent>
+// "byte_count": <Number of bytes that were just sent>,
+// "hex_encoded_bytes": <The exact bytes sent, as a hexadecimal string.
+// Only present when byte logging is enabled>
// }
EVENT_TYPE(SOCKET_BYTES_SENT)
// The specified number of bytes were received on the socket.
// The following parameters are attached:
// {
-// "num_bytes": <Number of bytes that were just sent>
+// "byte_count": <Number of bytes that were just received>,
+// "hex_encoded_bytes": <The exact bytes received, as a hexadecimal string.
+// Only present when byte logging is enabled>
// }
EVENT_TYPE(SOCKET_BYTES_RECEIVED)
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index f4c12d0..7d43117 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -723,7 +723,7 @@ int HttpNetworkTransaction::DoSendRequest() {
if (session_->network_delegate())
session_->network_delegate()->OnSendHttpRequest(&request_headers);
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
new NetLogHttpRequestParameter(request_line, request_headers));
@@ -731,7 +731,7 @@ int HttpNetworkTransaction::DoSendRequest() {
request_headers_ = request_line + request_headers.ToString();
} else {
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
new NetLogHttpRequestParameter(request_->url.spec(),
@@ -826,7 +826,7 @@ int HttpNetworkTransaction::DoReadHeadersComplete(int result) {
return rv;
}
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
new NetLogHttpResponseParameter(response_.headers));
diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc
index ddefe8e..2da59b7 100644
--- a/net/http/http_proxy_client_socket.cc
+++ b/net/http/http_proxy_client_socket.cc
@@ -331,7 +331,7 @@ int HttpProxyClientSocket::DoSendRequest() {
HttpRequestHeaders request_headers;
BuildTunnelRequest(request_, authorization_headers, endpoint_,
&request_line, &request_headers);
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
new NetLogHttpRequestParameter(
@@ -369,7 +369,7 @@ int HttpProxyClientSocket::DoReadHeadersComplete(int result) {
if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0))
return ERR_TUNNEL_CONNECTION_FAILED;
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
new NetLogHttpResponseParameter(response_.headers));
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index 632e63b..644daad 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -692,8 +692,8 @@ int ProxyService::DidFinishResolvingProxy(ProxyInfo* result,
const BoundNetLog& net_log) {
// Log the result of the proxy resolution.
if (result_code == OK) {
- // When full logging is enabled, dump the proxy list.
- if (net_log.IsLoggingAll()) {
+ // When logging all events is enabled, dump the proxy list.
+ if (net_log.IsLoggingAllEvents()) {
net_log.AddEvent(
NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
new NetLogStringParameter("pac_string", result->ToPacString()));
diff --git a/net/socket/client_socket.cc b/net/socket/client_socket.cc
index 8be3ae1..6f38eae 100644
--- a/net/socket/client_socket.cc
+++ b/net/socket/client_socket.cc
@@ -6,9 +6,47 @@
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
+#include "base/string_number_conversions.h"
+#include "base/values.h"
namespace net {
+namespace {
+
+// Parameters for SOCKET_BYTES_RECEIVED and SOCKET_BYTES_SENT events.
+// Includes bytes transferred and, if |bytes| is not NULL, the bytes themselves.
+class NetLogBytesTransferredParameter : public NetLog::EventParameters {
+ public:
+ NetLogBytesTransferredParameter(int byte_count, const char* bytes);
+
+ virtual Value* ToValue() const;
+
+ private:
+ const int byte_count_;
+ std::string hex_encoded_bytes_;
+ bool has_bytes_;
+};
+
+NetLogBytesTransferredParameter::NetLogBytesTransferredParameter(
+ int byte_count, const char* transferred_bytes)
+ : byte_count_(byte_count),
+ has_bytes_(false) {
+ if (transferred_bytes) {
+ hex_encoded_bytes_ = base::HexEncode(transferred_bytes, byte_count);
+ has_bytes_ = true;
+ }
+}
+
+Value* NetLogBytesTransferredParameter::ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger("byte_count", byte_count_);
+ if (has_bytes_)
+ dict->SetString("hex_encoded_bytes", hex_encoded_bytes_);
+ return dict;
+}
+
+} // namespace
+
ClientSocket::UseHistory::UseHistory()
: was_ever_connected_(false),
was_used_to_convey_data_(false),
@@ -98,4 +136,17 @@ bool ClientSocket::UseHistory::was_used_to_convey_data() const {
return was_used_to_convey_data_;
}
+void ClientSocket::LogByteTransfer(const BoundNetLog& net_log,
+ NetLog::EventType event_type,
+ int byte_count,
+ char* bytes) const {
+ scoped_refptr<NetLog::EventParameters> params;
+ if (net_log.IsLoggingBytes()) {
+ params = new NetLogBytesTransferredParameter(byte_count, bytes);
+ } else {
+ params = new NetLogBytesTransferredParameter(byte_count, NULL);
+ }
+ net_log.AddEvent(event_type, params);
+}
+
} // namespace net
diff --git a/net/socket/client_socket.h b/net/socket/client_socket.h
index f44f1f1..b4173c0 100644
--- a/net/socket/client_socket.h
+++ b/net/socket/client_socket.h
@@ -6,12 +6,12 @@
#define NET_SOCKET_CLIENT_SOCKET_H_
#pragma once
+#include "net/base/net_log.h"
#include "net/socket/socket.h"
namespace net {
class AddressList;
-class BoundNetLog;
class ClientSocket : public Socket {
public:
@@ -106,6 +106,12 @@ class ClientSocket : public Socket {
bool subresource_speculation_;
DISALLOW_COPY_AND_ASSIGN(UseHistory);
};
+
+ // Logs a SOCKET_BYTES_RECEIVED or SOCKET_BYTES_SENT event to the NetLog.
+ // Determines whether to log the received bytes or not, based on the current
+ // logging level.
+ void LogByteTransfer(const BoundNetLog& net_log, NetLog::EventType event_type,
+ int byte_count, char* bytes) const;
};
} // namespace net
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index 86d6afe9..f896ac6 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -332,8 +332,8 @@ int TCPClientSocketLibevent::Read(IOBuffer* buf,
read_bytes.Add(nread);
if (nread > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
- new NetLogIntegerParameter("num_bytes", nread));
+ LogByteTransfer(
+ net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, nread, buf->data());
return nread;
}
if (errno != EAGAIN && errno != EWOULDBLOCK) {
@@ -371,8 +371,8 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf,
write_bytes.Add(nwrite);
if (nwrite > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_SENT,
- new NetLogIntegerParameter("num_bytes", nwrite));
+ LogByteTransfer(
+ net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, nwrite, buf->data());
return nwrite;
}
if (errno != EAGAIN && errno != EWOULDBLOCK)
@@ -491,8 +491,8 @@ void TCPClientSocketLibevent::DidCompleteRead() {
read_bytes.Add(bytes_transferred);
if (bytes_transferred > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
- new NetLogIntegerParameter("num_bytes", result));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, result,
+ read_buf_->data());
} else {
result = MapPosixError(errno);
}
@@ -518,8 +518,8 @@ void TCPClientSocketLibevent::DidCompleteWrite() {
write_bytes.Add(bytes_transferred);
if (bytes_transferred > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_SENT,
- new NetLogIntegerParameter("num_bytes", result));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, result,
+ write_buf_->data());
} else {
result = MapPosixError(errno);
}
diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc
index 820f58e..5f1f43f 100644
--- a/net/socket/tcp_client_socket_pool.cc
+++ b/net/socket/tcp_client_socket_pool.cc
@@ -218,7 +218,7 @@ int TCPClientSocketPool::RequestSocket(
const scoped_refptr<TCPSocketParams>* casted_params =
static_cast<const scoped_refptr<TCPSocketParams>*>(params);
- if (net_log.IsLoggingAll()) {
+ if (net_log.IsLoggingAllEvents()) {
// TODO(eroman): Split out the host and port parameters.
net_log.AddEvent(
NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET,
@@ -239,7 +239,7 @@ void TCPClientSocketPool::RequestSockets(
const scoped_refptr<TCPSocketParams>* casted_params =
static_cast<const scoped_refptr<TCPSocketParams>*>(params);
- if (net_log.IsLoggingAll()) {
+ if (net_log.IsLoggingAllEvents()) {
// TODO(eroman): Split out the host and port parameters.
net_log.AddEvent(
NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKETS,
diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc
index 9bbb034..fc6ca27 100644
--- a/net/socket/tcp_client_socket_win.cc
+++ b/net/socket/tcp_client_socket_win.cc
@@ -568,8 +568,8 @@ int TCPClientSocketWin::Read(IOBuffer* buf,
read_bytes.Add(num);
if (num > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
- new NetLogIntegerParameter("num_bytes", num));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, num,
+ core_->read_buffer_.buf);
return static_cast<int>(num);
}
} else {
@@ -620,8 +620,8 @@ int TCPClientSocketWin::Write(IOBuffer* buf,
write_bytes.Add(rv);
if (rv > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_SENT,
- new NetLogIntegerParameter("num_bytes", rv));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, rv,
+ core_->write_buffer_.buf);
return rv;
}
} else {
@@ -781,8 +781,8 @@ void TCPClientSocketWin::DidCompleteRead() {
read_bytes.Add(num_bytes);
if (num_bytes > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
- new NetLogIntegerParameter("num_bytes", num_bytes));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, num_bytes,
+ core_->read_buffer_.buf);
}
DoReadCallback(ok ? num_bytes : MapWinsockError(WSAGetLastError()));
}
@@ -812,8 +812,8 @@ void TCPClientSocketWin::DidCompleteWrite() {
write_bytes.Add(num_bytes);
if (num_bytes > 0)
use_history_.set_was_used_to_convey_data();
- net_log_.AddEvent(NetLog::TYPE_SOCKET_BYTES_SENT,
- new NetLogIntegerParameter("num_bytes", rv));
+ LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes,
+ core_->write_buffer_.buf);
}
}
core_->write_iobuffer_ = NULL;
diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc
index d36b6306..9973f86 100644
--- a/net/spdy/spdy_proxy_client_socket.cc
+++ b/net/spdy/spdy_proxy_client_socket.cc
@@ -302,7 +302,7 @@ int SpdyProxyClientSocket::DoSendRequest() {
HttpRequestHeaders request_headers;
BuildTunnelRequest(request_, authorization_headers, endpoint_, &request_line,
&request_headers);
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
new NetLogHttpRequestParameter(
@@ -341,7 +341,7 @@ int SpdyProxyClientSocket::DoReadReplyComplete(int result) {
return ERR_TUNNEL_CONNECTION_FAILED;
next_state_ = STATE_OPEN;
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
new NetLogHttpResponseParameter(response_.headers));
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index 3967a81..b6e1529 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -456,7 +456,7 @@ int SpdySession::WriteSynStream(
spdy_requests.Increment();
streams_initiated_count_++;
- if (net_log().IsLoggingAll()) {
+ if (net_log().IsLoggingAllEvents()) {
net_log().AddEvent(
NetLog::TYPE_SPDY_SESSION_SYN_STREAM,
new NetLogSpdySynParameter(headers, flags, stream_id));
@@ -502,7 +502,7 @@ int SpdySession::WriteStreamData(spdy::SpdyStreamId stream_id,
stream->DecreaseSendWindowSize(len);
}
- if (net_log().IsLoggingAll())
+ if (net_log().IsLoggingAllEvents())
net_log().AddEvent(NetLog::TYPE_SPDY_SESSION_SEND_DATA,
new NetLogSpdyDataParameter(stream_id, len, flags));
@@ -959,7 +959,7 @@ void SpdySession::OnError(spdy::SpdyFramer* framer) {
void SpdySession::OnStreamFrameData(spdy::SpdyStreamId stream_id,
const char* data,
size_t len) {
- if (net_log().IsLoggingAll())
+ if (net_log().IsLoggingAllEvents())
net_log().AddEvent(NetLog::TYPE_SPDY_SESSION_RECV_DATA,
new NetLogSpdyDataParameter(stream_id, len, spdy::SpdyDataFlags()));
@@ -992,7 +992,7 @@ void SpdySession::OnSyn(const spdy::SpdySynStreamControlFrame& frame,
spdy::SpdyStreamId stream_id = frame.stream_id();
spdy::SpdyStreamId associated_stream_id = frame.associated_stream_id();
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
NetLog::TYPE_SPDY_SESSION_PUSHED_SYN_STREAM,
new NetLogSpdySynParameter(
@@ -1090,7 +1090,7 @@ void SpdySession::OnSynReply(const spdy::SpdySynReplyControlFrame& frame,
}
stream->set_response_received();
- if (net_log().IsLoggingAll()) {
+ if (net_log().IsLoggingAllEvents()) {
net_log().AddEvent(
NetLog::TYPE_SPDY_SESSION_SYN_REPLY,
new NetLogSpdySynParameter(
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index ee52e0a..c3ce979 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -490,7 +490,7 @@ void URLRequest::OrphanJob() {
}
int URLRequest::Redirect(const GURL& location, int http_status_code) {
- if (net_log_.IsLoggingAll()) {
+ if (net_log_.IsLoggingAllEvents()) {
net_log_.AddEvent(
net::NetLog::TYPE_URL_REQUEST_REDIRECTED,
new net::NetLogStringParameter(