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

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

Issue 2554483002: netlog: Don't enable recording if the "netlog" tracing category is disabled. (Closed)
Patch Set: Address comment. Created 4 years 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 | « no previous file | net/log/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/log/trace_net_log_observer.h" 5 #include "net/log/trace_net_log_observer.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // startup tracing. 94 // startup tracing.
95 if (base::trace_event::TraceLog::GetInstance()->IsEnabled()) 95 if (base::trace_event::TraceLog::GetInstance()->IsEnabled())
96 OnTraceLogEnabled(); 96 OnTraceLogEnabled();
97 base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this); 97 base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this);
98 } 98 }
99 99
100 void TraceNetLogObserver::StopWatchForTraceStart() { 100 void TraceNetLogObserver::StopWatchForTraceStart() {
101 // Should only stop if is currently watching. 101 // Should only stop if is currently watching.
102 DCHECK(net_log_to_watch_); 102 DCHECK(net_log_to_watch_);
103 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this); 103 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this);
104 // net_log() != nullptr iff NetLog::DeprecatedAddObserver() has been called.
105 // This implies that if the netlog category wasn't enabled, then
106 // NetLog::DeprecatedRemoveObserver() will not get called, and there won't be
107 // a crash in NetLog::DeprecatedRemoveObserver().
104 if (net_log()) 108 if (net_log())
105 net_log()->DeprecatedRemoveObserver(this); 109 net_log()->DeprecatedRemoveObserver(this);
106 net_log_to_watch_ = NULL; 110 net_log_to_watch_ = nullptr;
107 } 111 }
108 112
109 void TraceNetLogObserver::OnTraceLogEnabled() { 113 void TraceNetLogObserver::OnTraceLogEnabled() {
114 bool enabled;
115 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kNetLogTracingCategory, &enabled);
116 if (!enabled)
117 return;
118
110 net_log_to_watch_->DeprecatedAddObserver(this, NetLogCaptureMode::Default()); 119 net_log_to_watch_->DeprecatedAddObserver(this, NetLogCaptureMode::Default());
111 } 120 }
112 121
113 void TraceNetLogObserver::OnTraceLogDisabled() { 122 void TraceNetLogObserver::OnTraceLogDisabled() {
114 if (net_log()) 123 if (net_log())
115 net_log()->DeprecatedRemoveObserver(this); 124 net_log()->DeprecatedRemoveObserver(this);
116 } 125 }
117 126
118 } // namespace net 127 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/log/trace_net_log_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698