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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/net/net_log_logger.h" 5 #include "chrome/browser/net/net_log_logger.h"
6 6
7 #include <stdio.h>
8
9 #include "base/file_util.h"
7 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/threading/thread_restrictions.h"
8 #include "base/values.h" 12 #include "base/values.h"
9 13
10 NetLogLogger::NetLogLogger() 14 NetLogLogger::NetLogLogger(const FilePath &log_path)
11 : ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES) { 15 : ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES) {
16 if (!log_path.empty()) {
17 base::ThreadRestrictions::ScopedAllowIO allow_io;
18 file_.Set(file_util::OpenFile(log_path, "w"));
19 }
12 } 20 }
13 21
14 NetLogLogger::~NetLogLogger() {} 22 NetLogLogger::~NetLogLogger() {}
15 23
16 void NetLogLogger::OnAddEntry(net::NetLog::EventType type, 24 void NetLogLogger::OnAddEntry(net::NetLog::EventType type,
17 const base::TimeTicks& time, 25 const base::TimeTicks& time,
18 const net::NetLog::Source& source, 26 const net::NetLog::Source& source,
19 net::NetLog::EventPhase phase, 27 net::NetLog::EventPhase phase,
20 net::NetLog::EventParameters* params) { 28 net::NetLog::EventParameters* params) {
21 scoped_ptr<Value> value(net::NetLog::EntryToDictionaryValue(type, time, 29 scoped_ptr<Value> value(net::NetLog::EntryToDictionaryValue(type, time,
22 source, phase, 30 source, phase,
23 params, true)); 31 params, true));
32 // Don't pretty print, so each JSON value occupies a single line, with no
33 // breaks (Line breaks in any text field will be escaped). Using strings
34 // instead of integer identifiers allows logs from older versions to be
35 // loaded, though a little extra parsing has to be done when loading a log.
24 std::string json; 36 std::string json;
25 base::JSONWriter::Write(value.get(), true, &json); 37 base::JSONWriter::Write(value.get(), false, &json);
26 VLOG(1) << json; 38 if (!file_.get()) {
39 VLOG(1) << json;
40 } else {
41 fprintf(file_.get(), "%s\n", json.c_str());
42 }
27 } 43 }
28 44
OLDNEW
« 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