| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "net/log/net_log.h" | 17 #include "net/log/net_log.h" |
| 18 #include "net/log/net_log_event_type.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // TraceLog category for NetLog events. | 24 // TraceLog category for NetLog events. |
| 24 const char kNetLogTracingCategory[] = "netlog"; | 25 const char kNetLogTracingCategory[] = "netlog"; |
| 25 | 26 |
| 26 class TracedValue : public base::trace_event::ConvertableToTraceFormat { | 27 class TracedValue : public base::trace_event::ConvertableToTraceFormat { |
| 27 public: | 28 public: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 51 } | 52 } |
| 52 | 53 |
| 53 TraceNetLogObserver::~TraceNetLogObserver() { | 54 TraceNetLogObserver::~TraceNetLogObserver() { |
| 54 DCHECK(!net_log_to_watch_); | 55 DCHECK(!net_log_to_watch_); |
| 55 DCHECK(!net_log()); | 56 DCHECK(!net_log()); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void TraceNetLogObserver::OnAddEntry(const NetLog::Entry& entry) { | 59 void TraceNetLogObserver::OnAddEntry(const NetLog::Entry& entry) { |
| 59 std::unique_ptr<base::Value> params(entry.ParametersToValue()); | 60 std::unique_ptr<base::Value> params(entry.ParametersToValue()); |
| 60 switch (entry.phase()) { | 61 switch (entry.phase()) { |
| 61 case NetLog::PHASE_BEGIN: | 62 case NetLogEventPhase::BEGIN: |
| 62 TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( | 63 TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( |
| 63 kNetLogTracingCategory, NetLog::EventTypeToString(entry.type()), | 64 kNetLogTracingCategory, NetLog::EventTypeToString(entry.type()), |
| 64 entry.source().id, "source_type", | 65 entry.source().id, "source_type", |
| 65 NetLog::SourceTypeToString(entry.source().type), "params", | 66 NetLog::SourceTypeToString(entry.source().type), "params", |
| 66 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>( | 67 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>( |
| 67 new TracedValue(std::move(params)))); | 68 new TracedValue(std::move(params)))); |
| 68 break; | 69 break; |
| 69 case NetLog::PHASE_END: | 70 case NetLogEventPhase::END: |
| 70 TRACE_EVENT_NESTABLE_ASYNC_END2( | 71 TRACE_EVENT_NESTABLE_ASYNC_END2( |
| 71 kNetLogTracingCategory, NetLog::EventTypeToString(entry.type()), | 72 kNetLogTracingCategory, NetLog::EventTypeToString(entry.type()), |
| 72 entry.source().id, "source_type", | 73 entry.source().id, "source_type", |
| 73 NetLog::SourceTypeToString(entry.source().type), "params", | 74 NetLog::SourceTypeToString(entry.source().type), "params", |
| 74 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>( | 75 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>( |
| 75 new TracedValue(std::move(params)))); | 76 new TracedValue(std::move(params)))); |
| 76 break; | 77 break; |
| 77 case NetLog::PHASE_NONE: | 78 case NetLogEventPhase::NONE: |
| 78 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( | 79 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( |
| 79 kNetLogTracingCategory, NetLog::EventTypeToString(entry.type()), | 80 kNetLogTracingCategory, NetLog::EventTypeToString(entry.type()), |
| 80 entry.source().id, "source_type", | 81 entry.source().id, "source_type", |
| 81 NetLog::SourceTypeToString(entry.source().type), "params", | 82 NetLog::SourceTypeToString(entry.source().type), "params", |
| 82 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>( | 83 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>( |
| 83 new TracedValue(std::move(params)))); | 84 new TracedValue(std::move(params)))); |
| 84 break; | 85 break; |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 104 void TraceNetLogObserver::OnTraceLogEnabled() { | 105 void TraceNetLogObserver::OnTraceLogEnabled() { |
| 105 net_log_to_watch_->DeprecatedAddObserver(this, NetLogCaptureMode::Default()); | 106 net_log_to_watch_->DeprecatedAddObserver(this, NetLogCaptureMode::Default()); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void TraceNetLogObserver::OnTraceLogDisabled() { | 109 void TraceNetLogObserver::OnTraceLogDisabled() { |
| 109 if (net_log()) | 110 if (net_log()) |
| 110 net_log()->DeprecatedRemoveObserver(this); | 111 net_log()->DeprecatedRemoveObserver(this); |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace net | 114 } // namespace net |
| OLD | NEW |