OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "net/base/trace_net_log_observer.h" | 5 #include "net/base/trace_net_log_observer.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "net/base/net_log.h" | 16 #include "net/base/net_log.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
| 22 // TraceLog category for NetLog events. |
| 23 const char kNetLogTracingCategory[] = TRACE_DISABLED_BY_DEFAULT("netlog"); |
| 24 |
22 class TracedValue : public base::debug::ConvertableToTraceFormat { | 25 class TracedValue : public base::debug::ConvertableToTraceFormat { |
23 public: | 26 public: |
24 explicit TracedValue(scoped_ptr<base::Value> value) : value_(value.Pass()) {} | 27 explicit TracedValue(scoped_ptr<base::Value> value) : value_(value.Pass()) {} |
25 | 28 |
26 private: | 29 private: |
27 ~TracedValue() override {} | 30 ~TracedValue() override {} |
28 | 31 |
29 void AppendAsTraceFormat(std::string* out) const override { | 32 void AppendAsTraceFormat(std::string* out) const override { |
30 if (value_) { | 33 if (value_) { |
31 std::string tmp; | 34 std::string tmp; |
(...skipping 16 matching lines...) Expand all Loading... |
48 TraceNetLogObserver::~TraceNetLogObserver() { | 51 TraceNetLogObserver::~TraceNetLogObserver() { |
49 DCHECK(!net_log_to_watch_); | 52 DCHECK(!net_log_to_watch_); |
50 DCHECK(!net_log()); | 53 DCHECK(!net_log()); |
51 } | 54 } |
52 | 55 |
53 void TraceNetLogObserver::OnAddEntry(const NetLog::Entry& entry) { | 56 void TraceNetLogObserver::OnAddEntry(const NetLog::Entry& entry) { |
54 scoped_ptr<base::Value> params(entry.ParametersToValue()); | 57 scoped_ptr<base::Value> params(entry.ParametersToValue()); |
55 switch (entry.phase()) { | 58 switch (entry.phase()) { |
56 case NetLog::PHASE_BEGIN: | 59 case NetLog::PHASE_BEGIN: |
57 TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( | 60 TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( |
58 "netlog", NetLog::EventTypeToString(entry.type()), entry.source().id, | 61 kNetLogTracingCategory, |
| 62 NetLog::EventTypeToString(entry.type()), entry.source().id, |
59 "source_type", NetLog::SourceTypeToString(entry.source().type), | 63 "source_type", NetLog::SourceTypeToString(entry.source().type), |
60 "params", scoped_refptr<base::debug::ConvertableToTraceFormat>( | 64 "params", scoped_refptr<base::debug::ConvertableToTraceFormat>( |
61 new TracedValue(params.Pass()))); | 65 new TracedValue(params.Pass()))); |
62 break; | 66 break; |
63 case NetLog::PHASE_END: | 67 case NetLog::PHASE_END: |
64 TRACE_EVENT_NESTABLE_ASYNC_END2( | 68 TRACE_EVENT_NESTABLE_ASYNC_END2( |
65 "netlog", NetLog::EventTypeToString(entry.type()), entry.source().id, | 69 kNetLogTracingCategory, |
| 70 NetLog::EventTypeToString(entry.type()), entry.source().id, |
66 "source_type", NetLog::SourceTypeToString(entry.source().type), | 71 "source_type", NetLog::SourceTypeToString(entry.source().type), |
67 "params", scoped_refptr<base::debug::ConvertableToTraceFormat>( | 72 "params", scoped_refptr<base::debug::ConvertableToTraceFormat>( |
68 new TracedValue(params.Pass()))); | 73 new TracedValue(params.Pass()))); |
69 break; | 74 break; |
70 case NetLog::PHASE_NONE: | 75 case NetLog::PHASE_NONE: |
71 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( | 76 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( |
72 "netlog", NetLog::EventTypeToString(entry.type()), entry.source().id, | 77 kNetLogTracingCategory, |
| 78 NetLog::EventTypeToString(entry.type()), entry.source().id, |
73 "source_type", NetLog::SourceTypeToString(entry.source().type), | 79 "source_type", NetLog::SourceTypeToString(entry.source().type), |
74 "params", scoped_refptr<base::debug::ConvertableToTraceFormat>( | 80 "params", scoped_refptr<base::debug::ConvertableToTraceFormat>( |
75 new TracedValue(params.Pass()))); | 81 new TracedValue(params.Pass()))); |
76 break; | 82 break; |
77 } | 83 } |
78 } | 84 } |
79 | 85 |
80 void TraceNetLogObserver::WatchForTraceStart(NetLog* netlog) { | 86 void TraceNetLogObserver::WatchForTraceStart(NetLog* netlog) { |
81 DCHECK(!net_log_to_watch_); | 87 DCHECK(!net_log_to_watch_); |
82 DCHECK(!net_log()); | 88 DCHECK(!net_log()); |
(...skipping 14 matching lines...) Expand all Loading... |
97 net_log_to_watch_->AddThreadSafeObserver(this, | 103 net_log_to_watch_->AddThreadSafeObserver(this, |
98 NetLog::LOG_STRIP_PRIVATE_DATA); | 104 NetLog::LOG_STRIP_PRIVATE_DATA); |
99 } | 105 } |
100 | 106 |
101 void TraceNetLogObserver::OnTraceLogDisabled() { | 107 void TraceNetLogObserver::OnTraceLogDisabled() { |
102 if (net_log()) | 108 if (net_log()) |
103 net_log()->RemoveThreadSafeObserver(this); | 109 net_log()->RemoveThreadSafeObserver(this); |
104 } | 110 } |
105 | 111 |
106 } // namespace net | 112 } // namespace net |
OLD | NEW |