summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 19:58:14 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 19:58:14 +0000
commit465aeb94531f3d73959412b2c8033005fb7c44d7 (patch)
tree39d71fab356d8816ac83b5bb819ce455027c3906 /chrome
parent26783d056f3639d6310c41d1f499d5a9b13bbf90 (diff)
downloadchromium_src-465aeb94531f3d73959412b2c8033005fb7c44d7.zip
chromium_src-465aeb94531f3d73959412b2c8033005fb7c44d7.tar.gz
chromium_src-465aeb94531f3d73959412b2c8033005fb7c44d7.tar.bz2
Add actual bytes sent/received to net-internals.
BUG=54745 TEST=manual Review URL: http://codereview.chromium.org/3582007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62627 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-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
9 files changed, 129 insertions, 8 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;
};