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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « net/base/trace_net_log_observer.h ('k') | net/base/trace_net_log_observer_unittest.cc » ('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 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/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.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. 22 // TraceLog category for NetLog events.
23 const char kNetLogTracingCategory[] = TRACE_DISABLED_BY_DEFAULT("netlog"); 23 const char kNetLogTracingCategory[] = TRACE_DISABLED_BY_DEFAULT("netlog");
24 24
25 class TracedValue : public base::debug::ConvertableToTraceFormat { 25 class TracedValue : public base::trace_event::ConvertableToTraceFormat {
26 public: 26 public:
27 explicit TracedValue(scoped_ptr<base::Value> value) : value_(value.Pass()) {} 27 explicit TracedValue(scoped_ptr<base::Value> value) : value_(value.Pass()) {}
28 28
29 private: 29 private:
30 ~TracedValue() override {} 30 ~TracedValue() override {}
31 31
32 void AppendAsTraceFormat(std::string* out) const override { 32 void AppendAsTraceFormat(std::string* out) const override {
33 if (value_) { 33 if (value_) {
34 std::string tmp; 34 std::string tmp;
35 base::JSONWriter::Write(value_.get(), &tmp); 35 base::JSONWriter::Write(value_.get(), &tmp);
(...skipping 15 matching lines...) Expand all
51 TraceNetLogObserver::~TraceNetLogObserver() { 51 TraceNetLogObserver::~TraceNetLogObserver() {
52 DCHECK(!net_log_to_watch_); 52 DCHECK(!net_log_to_watch_);
53 DCHECK(!net_log()); 53 DCHECK(!net_log());
54 } 54 }
55 55
56 void TraceNetLogObserver::OnAddEntry(const NetLog::Entry& entry) { 56 void TraceNetLogObserver::OnAddEntry(const NetLog::Entry& entry) {
57 scoped_ptr<base::Value> params(entry.ParametersToValue()); 57 scoped_ptr<base::Value> params(entry.ParametersToValue());
58 switch (entry.phase()) { 58 switch (entry.phase()) {
59 case NetLog::PHASE_BEGIN: 59 case NetLog::PHASE_BEGIN:
60 TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( 60 TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(
61 kNetLogTracingCategory, 61 kNetLogTracingCategory, NetLog::EventTypeToString(entry.type()),
62 NetLog::EventTypeToString(entry.type()), entry.source().id, 62 entry.source().id, "source_type",
63 "source_type", NetLog::SourceTypeToString(entry.source().type), 63 NetLog::SourceTypeToString(entry.source().type), "params",
64 "params", scoped_refptr<base::debug::ConvertableToTraceFormat>( 64 scoped_refptr<base::trace_event::ConvertableToTraceFormat>(
65 new TracedValue(params.Pass()))); 65 new TracedValue(params.Pass())));
66 break; 66 break;
67 case NetLog::PHASE_END: 67 case NetLog::PHASE_END:
68 TRACE_EVENT_NESTABLE_ASYNC_END2( 68 TRACE_EVENT_NESTABLE_ASYNC_END2(
69 kNetLogTracingCategory, 69 kNetLogTracingCategory, NetLog::EventTypeToString(entry.type()),
70 NetLog::EventTypeToString(entry.type()), entry.source().id, 70 entry.source().id, "source_type",
71 "source_type", NetLog::SourceTypeToString(entry.source().type), 71 NetLog::SourceTypeToString(entry.source().type), "params",
72 "params", scoped_refptr<base::debug::ConvertableToTraceFormat>( 72 scoped_refptr<base::trace_event::ConvertableToTraceFormat>(
73 new TracedValue(params.Pass()))); 73 new TracedValue(params.Pass())));
74 break; 74 break;
75 case NetLog::PHASE_NONE: 75 case NetLog::PHASE_NONE:
76 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( 76 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2(
77 kNetLogTracingCategory, 77 kNetLogTracingCategory, NetLog::EventTypeToString(entry.type()),
78 NetLog::EventTypeToString(entry.type()), entry.source().id, 78 entry.source().id, "source_type",
79 "source_type", NetLog::SourceTypeToString(entry.source().type), 79 NetLog::SourceTypeToString(entry.source().type), "params",
80 "params", scoped_refptr<base::debug::ConvertableToTraceFormat>( 80 scoped_refptr<base::trace_event::ConvertableToTraceFormat>(
81 new TracedValue(params.Pass()))); 81 new TracedValue(params.Pass())));
82 break; 82 break;
83 } 83 }
84 } 84 }
85 85
86 void TraceNetLogObserver::WatchForTraceStart(NetLog* netlog) { 86 void TraceNetLogObserver::WatchForTraceStart(NetLog* netlog) {
87 DCHECK(!net_log_to_watch_); 87 DCHECK(!net_log_to_watch_);
88 DCHECK(!net_log()); 88 DCHECK(!net_log());
89 net_log_to_watch_ = netlog; 89 net_log_to_watch_ = netlog;
90 base::debug::TraceLog::GetInstance()->AddEnabledStateObserver(this); 90 base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this);
91 } 91 }
92 92
93 void TraceNetLogObserver::StopWatchForTraceStart() { 93 void TraceNetLogObserver::StopWatchForTraceStart() {
94 // Should only stop if is currently watching. 94 // Should only stop if is currently watching.
95 DCHECK(net_log_to_watch_); 95 DCHECK(net_log_to_watch_);
96 base::debug::TraceLog::GetInstance()->RemoveEnabledStateObserver(this); 96 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this);
97 if (net_log()) 97 if (net_log())
98 net_log()->RemoveThreadSafeObserver(this); 98 net_log()->RemoveThreadSafeObserver(this);
99 net_log_to_watch_ = NULL; 99 net_log_to_watch_ = NULL;
100 } 100 }
101 101
102 void TraceNetLogObserver::OnTraceLogEnabled() { 102 void TraceNetLogObserver::OnTraceLogEnabled() {
103 net_log_to_watch_->AddThreadSafeObserver(this, 103 net_log_to_watch_->AddThreadSafeObserver(this,
104 NetLog::LOG_STRIP_PRIVATE_DATA); 104 NetLog::LOG_STRIP_PRIVATE_DATA);
105 } 105 }
106 106
107 void TraceNetLogObserver::OnTraceLogDisabled() { 107 void TraceNetLogObserver::OnTraceLogDisabled() {
108 if (net_log()) 108 if (net_log())
109 net_log()->RemoveThreadSafeObserver(this); 109 net_log()->RemoveThreadSafeObserver(this);
110 } 110 }
111 111
112 } // namespace net 112 } // namespace net
OLDNEW
« no previous file with comments | « net/base/trace_net_log_observer.h ('k') | net/base/trace_net_log_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698