| 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/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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>( | 83 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>( |
| 84 new TracedValue(std::move(params)))); | 84 new TracedValue(std::move(params)))); |
| 85 break; | 85 break; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 void TraceNetLogObserver::WatchForTraceStart(NetLog* netlog) { | 89 void TraceNetLogObserver::WatchForTraceStart(NetLog* netlog) { |
| 90 DCHECK(!net_log_to_watch_); | 90 DCHECK(!net_log_to_watch_); |
| 91 DCHECK(!net_log()); | 91 DCHECK(!net_log()); |
| 92 net_log_to_watch_ = netlog; | 92 net_log_to_watch_ = netlog; |
| 93 // Tracing can start before the observer is even created, for instance for |
| 94 // startup tracing. |
| 95 if (base::trace_event::TraceLog::GetInstance()->IsEnabled()) |
| 96 OnTraceLogEnabled(); |
| 93 base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this); | 97 base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this); |
| 94 } | 98 } |
| 95 | 99 |
| 96 void TraceNetLogObserver::StopWatchForTraceStart() { | 100 void TraceNetLogObserver::StopWatchForTraceStart() { |
| 97 // Should only stop if is currently watching. | 101 // Should only stop if is currently watching. |
| 98 DCHECK(net_log_to_watch_); | 102 DCHECK(net_log_to_watch_); |
| 99 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this); | 103 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this); |
| 100 if (net_log()) | 104 if (net_log()) |
| 101 net_log()->DeprecatedRemoveObserver(this); | 105 net_log()->DeprecatedRemoveObserver(this); |
| 102 net_log_to_watch_ = NULL; | 106 net_log_to_watch_ = NULL; |
| 103 } | 107 } |
| 104 | 108 |
| 105 void TraceNetLogObserver::OnTraceLogEnabled() { | 109 void TraceNetLogObserver::OnTraceLogEnabled() { |
| 106 net_log_to_watch_->DeprecatedAddObserver(this, NetLogCaptureMode::Default()); | 110 net_log_to_watch_->DeprecatedAddObserver(this, NetLogCaptureMode::Default()); |
| 107 } | 111 } |
| 108 | 112 |
| 109 void TraceNetLogObserver::OnTraceLogDisabled() { | 113 void TraceNetLogObserver::OnTraceLogDisabled() { |
| 110 if (net_log()) | 114 if (net_log()) |
| 111 net_log()->DeprecatedRemoveObserver(this); | 115 net_log()->DeprecatedRemoveObserver(this); |
| 112 } | 116 } |
| 113 | 117 |
| 114 } // namespace net | 118 } // namespace net |
| OLD | NEW |