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

Side by Side Diff: net/base/trace_net_log_observer.cc

Issue 468083004: Use NESTABLE_ASYNC APIs to get NetLog data into Tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/base/trace_net_log_observer.h"
6
7 #include <stdio.h>
8
9 #include "base/debug/trace_event.h"
10 #include "base/json/json_writer.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13
14
mmenke 2014/08/15 20:42:54 nit: Remove extra blank line.
xunjieli 2014/08/15 21:55:15 Done. Oops. Thanks!
15 namespace net {
16
17 namespace {
18
19 class TracedValue : public base::debug::ConvertableToTraceFormat {
20 public:
21 TracedValue(scoped_ptr<base::Value> value) : value_(value.Pass()) {}
22 protected:
mmenke 2014/08/15 20:42:53 nit: Blank line before protected (And private, sa
xunjieli 2014/08/15 21:55:16 Done for all my files. Thanks!
23 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE {
24 if (value_) {
25 std::string tmp;
26 base::JSONWriter::Write(value_.get(), &tmp);
27 *out += tmp;
28 } else {
29 *out += "\"\"";
30 }
31 }
32
33 virtual ~TracedValue() {}
xunjieli 2014/08/15 20:01:18 Not very familiar with ref counted pointers, shoul
mmenke 2014/08/15 20:42:53 Don't think so, just make it protected, as you're
mmenke 2014/08/15 20:42:53 nit: Destructor and constructor should go before
xunjieli 2014/08/15 21:55:16 Done. Thanks!
34 private:
35 scoped_ptr<base::Value> value_;
36 };
37 } // namespace
mmenke 2014/08/15 20:42:53 nit: Two spaces between comment and code.
mmenke 2014/08/15 20:42:53 nit: Blank line before closing the namespace.
xunjieli 2014/08/15 21:55:15 Done.
38
39 TraceNetLogObserver::TraceNetLogObserver()
40 : log_level_(NetLog::LOG_STRIP_PRIVATE_DATA) {
41 }
42
43 TraceNetLogObserver::~TraceNetLogObserver() {
44 }
45
46 void TraceNetLogObserver::set_log_level(NetLog::LogLevel log_level) {
47 DCHECK(!net_log());
mmenke 2014/08/15 20:42:53 This behavior should be mentioned in the header fi
xunjieli 2014/08/15 21:55:15 Acknowledged. I have removed this setter since it
48 log_level_ = log_level;
49 }
50
51 void TraceNetLogObserver::StartObserving(NetLog* net_log) {
52 net_log->AddThreadSafeObserver(this, log_level_);
53 }
54
55 void TraceNetLogObserver::StopObserving() {
56 net_log()->RemoveThreadSafeObserver(this);
57 }
58
59 void TraceNetLogObserver::OnAddEntry(const NetLog::Entry& entry) {
60 if (log_level_ == NetLog::LOG_NONE) {
mmenke 2014/08/15 20:42:53 not needed. The NetLog is responsible for dealing
xunjieli 2014/08/15 21:55:15 Done.
61 return;
62 }
63 scoped_ptr<base::Value> value(entry.ToValue());
64 switch(entry.phase()) {
65 case (NetLog::PHASE_BEGIN):
66 TRACE_EVENT_NET_LOG_BEGIN(
67 "netlog", NetLog::EventTypeToString(entry.type()), entry.source().id,
xunjieli 2014/08/15 20:10:03 Nat, if I understand correctly, the tracing catego
68 "value", scoped_refptr<base::debug::ConvertableToTraceFormat>(
69 new TracedValue(value.Pass())));
70 break;
71 case (NetLog::PHASE_END):
72 TRACE_EVENT_NET_LOG_END(
73 "netlog", NetLog::EventTypeToString(entry.type()), entry.source().id,
74 "value", scoped_refptr<base::debug::ConvertableToTraceFormat>(
75 new TracedValue(value.Pass())));
76 break;
77 case (NetLog::PHASE_NONE):
78 TRACE_EVENT_NET_LOG_INSTANT(
79 "netlog", NetLog::EventTypeToString(entry.type()), entry.source().id,
80 "value", scoped_refptr<base::debug::ConvertableToTraceFormat>(
81 new TracedValue(value.Pass())));
82 break;
83 default:
mmenke 2014/08/15 20:42:53 NOTREACHED()?
xunjieli 2014/08/15 21:55:15 Done.
84 break;
85 }
86 }
87
88 void TraceNetLogObserver::WatchForTraceStart(NetLog* net_log) {
89 net_log_ = net_log;
90 base::debug::TraceLog::GetInstance()->AddEnabledStateObserver(this);
91 }
92
93 void TraceNetLogObserver::StopWatchForTraceStart() {
94 if (!net_log_) {
95 // We should only stop if we are currently watching.
mmenke 2014/08/15 20:42:53 nit: Don't use we in comment, because it's ambigu
xunjieli 2014/08/15 21:55:15 Done. Thanks!
96 DCHECK(false);
97 }
mmenke 2014/08/15 20:42:53 This should just be DCHECK(net_log_)
xunjieli 2014/08/15 21:55:15 Done. I see. That's convenient.
98 base::debug::TraceLog::GetInstance()->RemoveEnabledStateObserver(this);
99 net_log()->RemoveThreadSafeObserver(this);
mmenke 2014/08/15 20:42:53 This crashes if we're not watching a net_log. Sho
mmenke 2014/08/15 20:42:54 net_log() vs net_log_ can be confusing, maybe rena
xunjieli 2014/08/15 21:55:15 Done.Yes, that's indeed very confusing. Thanks for
100 }
101
102 void TraceNetLogObserver::OnTraceLogEnabled() {
103 StartObserving(net_log_);
104 }
105
106 void TraceNetLogObserver::OnTraceLogDisabled() {
107 StopObserving();
108 }
109
110 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698