Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4326)

Unified Diff: chrome/browser/net/net_log_logger.cc

Issue 6025017: Adds the ability to load JSON log files to about:net-internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Put load log button on its own line Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/net/net_log_logger.h ('k') | chrome/browser/resources/net_internals/dataview.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/net_log_logger.cc
===================================================================
--- chrome/browser/net/net_log_logger.cc (revision 72508)
+++ chrome/browser/net/net_log_logger.cc (working copy)
@@ -4,11 +4,19 @@
#include "chrome/browser/net/net_log_logger.h"
+#include <stdio.h>
+
+#include "base/file_util.h"
#include "base/json/json_writer.h"
+#include "base/threading/thread_restrictions.h"
#include "base/values.h"
-NetLogLogger::NetLogLogger()
+NetLogLogger::NetLogLogger(const FilePath &log_path)
: ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES) {
+ if (!log_path.empty()) {
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ file_.Set(file_util::OpenFile(log_path, "w"));
+ }
}
NetLogLogger::~NetLogLogger() {}
@@ -21,8 +29,16 @@
scoped_ptr<Value> value(net::NetLog::EntryToDictionaryValue(type, time,
source, phase,
params, true));
+ // Don't pretty print, so each JSON value occupies a single line, with no
+ // breaks (Line breaks in any text field will be escaped). Using strings
+ // instead of integer identifiers allows logs from older versions to be
+ // loaded, though a little extra parsing has to be done when loading a log.
std::string json;
- base::JSONWriter::Write(value.get(), true, &json);
- VLOG(1) << json;
+ base::JSONWriter::Write(value.get(), false, &json);
+ if (!file_.get()) {
+ VLOG(1) << json;
+ } else {
+ fprintf(file_.get(), "%s\n", json.c_str());
+ }
}
« no previous file with comments | « chrome/browser/net/net_log_logger.h ('k') | chrome/browser/resources/net_internals/dataview.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698