| 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 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 *out += tmp; | 33 *out += tmp; |
| 34 } else { | 34 } else { |
| 35 *out += "\"\""; | 35 *out += "\"\""; |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 scoped_ptr<base::Value> value_; | 40 scoped_ptr<base::Value> value_; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // TraceLog category for NetLog events. |
| 44 const char kNetLogTracingCategory[] = "disabled-by-default-netlog"; |
| 45 |
| 43 } // namespace | 46 } // namespace |
| 44 | 47 |
| 45 TraceNetLogObserver::TraceNetLogObserver() : net_log_to_watch_(NULL) { | 48 TraceNetLogObserver::TraceNetLogObserver() : net_log_to_watch_(NULL) { |
| 46 } | 49 } |
| 47 | 50 |
| 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 |