OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/net_log.h" | 5 #include "net/log/net_log.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Returns parameters for logging data transferred events. At a minimum includes | 22 // Returns parameters for logging data transferred events. At a minimum includes |
23 // the number of bytes transferred. If the capture mode allows logging byte | 23 // the number of bytes transferred. If the capture mode allows logging byte |
24 // contents and |byte_count| > 0, then will include the actual bytes. The | 24 // contents and |byte_count| > 0, then will include the actual bytes. The |
25 // bytes are hex-encoded, since base::StringValue only supports UTF-8. | 25 // bytes are hex-encoded, since base::StringValue only supports UTF-8. |
26 scoped_ptr<base::Value> BytesTransferredCallback( | 26 std::unique_ptr<base::Value> BytesTransferredCallback( |
27 int byte_count, | 27 int byte_count, |
28 const char* bytes, | 28 const char* bytes, |
29 NetLogCaptureMode capture_mode) { | 29 NetLogCaptureMode capture_mode) { |
30 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 30 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
31 dict->SetInteger("byte_count", byte_count); | 31 dict->SetInteger("byte_count", byte_count); |
32 if (capture_mode.include_socket_bytes() && byte_count > 0) | 32 if (capture_mode.include_socket_bytes() && byte_count > 0) |
33 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); | 33 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); |
34 return std::move(dict); | 34 return std::move(dict); |
35 } | 35 } |
36 | 36 |
37 scoped_ptr<base::Value> SourceEventParametersCallback( | 37 std::unique_ptr<base::Value> SourceEventParametersCallback( |
38 const NetLog::Source source, | 38 const NetLog::Source source, |
39 NetLogCaptureMode /* capture_mode */) { | 39 NetLogCaptureMode /* capture_mode */) { |
40 if (!source.IsValid()) | 40 if (!source.IsValid()) |
41 return scoped_ptr<base::Value>(); | 41 return std::unique_ptr<base::Value>(); |
42 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 42 std::unique_ptr<base::DictionaryValue> event_params( |
| 43 new base::DictionaryValue()); |
43 source.AddToEventParameters(event_params.get()); | 44 source.AddToEventParameters(event_params.get()); |
44 return std::move(event_params); | 45 return std::move(event_params); |
45 } | 46 } |
46 | 47 |
47 scoped_ptr<base::Value> NetLogBoolCallback( | 48 std::unique_ptr<base::Value> NetLogBoolCallback( |
48 const char* name, | 49 const char* name, |
49 bool value, | 50 bool value, |
50 NetLogCaptureMode /* capture_mode */) { | 51 NetLogCaptureMode /* capture_mode */) { |
51 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 52 std::unique_ptr<base::DictionaryValue> event_params( |
| 53 new base::DictionaryValue()); |
52 event_params->SetBoolean(name, value); | 54 event_params->SetBoolean(name, value); |
53 return std::move(event_params); | 55 return std::move(event_params); |
54 } | 56 } |
55 | 57 |
56 scoped_ptr<base::Value> NetLogIntCallback( | 58 std::unique_ptr<base::Value> NetLogIntCallback( |
57 const char* name, | 59 const char* name, |
58 int value, | 60 int value, |
59 NetLogCaptureMode /* capture_mode */) { | 61 NetLogCaptureMode /* capture_mode */) { |
60 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 62 std::unique_ptr<base::DictionaryValue> event_params( |
| 63 new base::DictionaryValue()); |
61 event_params->SetInteger(name, value); | 64 event_params->SetInteger(name, value); |
62 return std::move(event_params); | 65 return std::move(event_params); |
63 } | 66 } |
64 | 67 |
65 scoped_ptr<base::Value> NetLogInt64Callback( | 68 std::unique_ptr<base::Value> NetLogInt64Callback( |
66 const char* name, | 69 const char* name, |
67 int64_t value, | 70 int64_t value, |
68 NetLogCaptureMode /* capture_mode */) { | 71 NetLogCaptureMode /* capture_mode */) { |
69 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 72 std::unique_ptr<base::DictionaryValue> event_params( |
| 73 new base::DictionaryValue()); |
70 event_params->SetString(name, base::Int64ToString(value)); | 74 event_params->SetString(name, base::Int64ToString(value)); |
71 return std::move(event_params); | 75 return std::move(event_params); |
72 } | 76 } |
73 | 77 |
74 scoped_ptr<base::Value> NetLogStringCallback( | 78 std::unique_ptr<base::Value> NetLogStringCallback( |
75 const char* name, | 79 const char* name, |
76 const std::string* value, | 80 const std::string* value, |
77 NetLogCaptureMode /* capture_mode */) { | 81 NetLogCaptureMode /* capture_mode */) { |
78 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 82 std::unique_ptr<base::DictionaryValue> event_params( |
| 83 new base::DictionaryValue()); |
79 event_params->SetString(name, *value); | 84 event_params->SetString(name, *value); |
80 return std::move(event_params); | 85 return std::move(event_params); |
81 } | 86 } |
82 | 87 |
83 scoped_ptr<base::Value> NetLogString16Callback( | 88 std::unique_ptr<base::Value> NetLogString16Callback( |
84 const char* name, | 89 const char* name, |
85 const base::string16* value, | 90 const base::string16* value, |
86 NetLogCaptureMode /* capture_mode */) { | 91 NetLogCaptureMode /* capture_mode */) { |
87 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 92 std::unique_ptr<base::DictionaryValue> event_params( |
| 93 new base::DictionaryValue()); |
88 event_params->SetString(name, *value); | 94 event_params->SetString(name, *value); |
89 return std::move(event_params); | 95 return std::move(event_params); |
90 } | 96 } |
91 | 97 |
92 } // namespace | 98 } // namespace |
93 | 99 |
94 // LoadTimingInfo requires this be 0. | 100 // LoadTimingInfo requires this be 0. |
95 const uint32_t NetLog::Source::kInvalidId = 0; | 101 const uint32_t NetLog::Source::kInvalidId = 0; |
96 | 102 |
97 NetLog::Source::Source() : type(SOURCE_NONE), id(kInvalidId) { | 103 NetLog::Source::Source() : type(SOURCE_NONE), id(kInvalidId) { |
98 } | 104 } |
99 | 105 |
100 NetLog::Source::Source(SourceType type, uint32_t id) : type(type), id(id) {} | 106 NetLog::Source::Source(SourceType type, uint32_t id) : type(type), id(id) {} |
101 | 107 |
102 bool NetLog::Source::IsValid() const { | 108 bool NetLog::Source::IsValid() const { |
103 return id != kInvalidId; | 109 return id != kInvalidId; |
104 } | 110 } |
105 | 111 |
106 void NetLog::Source::AddToEventParameters( | 112 void NetLog::Source::AddToEventParameters( |
107 base::DictionaryValue* event_params) const { | 113 base::DictionaryValue* event_params) const { |
108 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 114 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
109 dict->SetInteger("type", static_cast<int>(type)); | 115 dict->SetInteger("type", static_cast<int>(type)); |
110 dict->SetInteger("id", static_cast<int>(id)); | 116 dict->SetInteger("id", static_cast<int>(id)); |
111 event_params->Set("source_dependency", std::move(dict)); | 117 event_params->Set("source_dependency", std::move(dict)); |
112 } | 118 } |
113 | 119 |
114 NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const { | 120 NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const { |
115 return base::Bind(&SourceEventParametersCallback, *this); | 121 return base::Bind(&SourceEventParametersCallback, *this); |
116 } | 122 } |
117 | 123 |
118 // static | 124 // static |
(...skipping 11 matching lines...) Expand all Loading... |
130 return false; | 136 return false; |
131 } | 137 } |
132 | 138 |
133 DCHECK_GE(source_id, 0); | 139 DCHECK_GE(source_id, 0); |
134 DCHECK_LT(source_type, NetLog::SOURCE_COUNT); | 140 DCHECK_LT(source_type, NetLog::SOURCE_COUNT); |
135 *source = Source(static_cast<SourceType>(source_type), source_id); | 141 *source = Source(static_cast<SourceType>(source_type), source_id); |
136 return true; | 142 return true; |
137 } | 143 } |
138 | 144 |
139 base::Value* NetLog::Entry::ToValue() const { | 145 base::Value* NetLog::Entry::ToValue() const { |
140 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); | 146 std::unique_ptr<base::DictionaryValue> entry_dict( |
| 147 new base::DictionaryValue()); |
141 | 148 |
142 entry_dict->SetString("time", TickCountToString(data_->time)); | 149 entry_dict->SetString("time", TickCountToString(data_->time)); |
143 | 150 |
144 // Set the entry source. | 151 // Set the entry source. |
145 scoped_ptr<base::DictionaryValue> source_dict(new base::DictionaryValue()); | 152 std::unique_ptr<base::DictionaryValue> source_dict( |
| 153 new base::DictionaryValue()); |
146 source_dict->SetInteger("id", data_->source.id); | 154 source_dict->SetInteger("id", data_->source.id); |
147 source_dict->SetInteger("type", static_cast<int>(data_->source.type)); | 155 source_dict->SetInteger("type", static_cast<int>(data_->source.type)); |
148 entry_dict->Set("source", std::move(source_dict)); | 156 entry_dict->Set("source", std::move(source_dict)); |
149 | 157 |
150 // Set the event info. | 158 // Set the event info. |
151 entry_dict->SetInteger("type", static_cast<int>(data_->type)); | 159 entry_dict->SetInteger("type", static_cast<int>(data_->type)); |
152 entry_dict->SetInteger("phase", static_cast<int>(data_->phase)); | 160 entry_dict->SetInteger("phase", static_cast<int>(data_->phase)); |
153 | 161 |
154 // Set the event-specific parameters. | 162 // Set the event-specific parameters. |
155 if (data_->parameters_callback) { | 163 if (data_->parameters_callback) { |
156 scoped_ptr<base::Value> value( | 164 std::unique_ptr<base::Value> value( |
157 data_->parameters_callback->Run(capture_mode_)); | 165 data_->parameters_callback->Run(capture_mode_)); |
158 if (value) | 166 if (value) |
159 entry_dict->Set("params", std::move(value)); | 167 entry_dict->Set("params", std::move(value)); |
160 } | 168 } |
161 | 169 |
162 return entry_dict.release(); | 170 return entry_dict.release(); |
163 } | 171 } |
164 | 172 |
165 scoped_ptr<base::Value> NetLog::Entry::ParametersToValue() const { | 173 std::unique_ptr<base::Value> NetLog::Entry::ParametersToValue() const { |
166 if (data_->parameters_callback) | 174 if (data_->parameters_callback) |
167 return data_->parameters_callback->Run(capture_mode_); | 175 return data_->parameters_callback->Run(capture_mode_); |
168 return nullptr; | 176 return nullptr; |
169 } | 177 } |
170 | 178 |
171 NetLog::EntryData::EntryData(EventType type, | 179 NetLog::EntryData::EntryData(EventType type, |
172 Source source, | 180 Source source, |
173 EventPhase phase, | 181 EventPhase phase, |
174 base::TimeTicks time, | 182 base::TimeTicks time, |
175 const ParametersCallback* parameters_callback) | 183 const ParametersCallback* parameters_callback) |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 #include "net/log/net_log_event_type_list.h" | 299 #include "net/log/net_log_event_type_list.h" |
292 #undef EVENT_TYPE | 300 #undef EVENT_TYPE |
293 default: | 301 default: |
294 NOTREACHED(); | 302 NOTREACHED(); |
295 return NULL; | 303 return NULL; |
296 } | 304 } |
297 } | 305 } |
298 | 306 |
299 // static | 307 // static |
300 base::Value* NetLog::GetEventTypesAsValue() { | 308 base::Value* NetLog::GetEventTypesAsValue() { |
301 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 309 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
302 for (int i = 0; i < EVENT_COUNT; ++i) { | 310 for (int i = 0; i < EVENT_COUNT; ++i) { |
303 dict->SetInteger(EventTypeToString(static_cast<EventType>(i)), i); | 311 dict->SetInteger(EventTypeToString(static_cast<EventType>(i)), i); |
304 } | 312 } |
305 return dict.release(); | 313 return dict.release(); |
306 } | 314 } |
307 | 315 |
308 // static | 316 // static |
309 const char* NetLog::SourceTypeToString(SourceType source) { | 317 const char* NetLog::SourceTypeToString(SourceType source) { |
310 switch (source) { | 318 switch (source) { |
311 #define SOURCE_TYPE(label) \ | 319 #define SOURCE_TYPE(label) \ |
312 case SOURCE_##label: \ | 320 case SOURCE_##label: \ |
313 return #label; | 321 return #label; |
314 #include "net/log/net_log_source_type_list.h" | 322 #include "net/log/net_log_source_type_list.h" |
315 #undef SOURCE_TYPE | 323 #undef SOURCE_TYPE |
316 default: | 324 default: |
317 NOTREACHED(); | 325 NOTREACHED(); |
318 return NULL; | 326 return NULL; |
319 } | 327 } |
320 } | 328 } |
321 | 329 |
322 // static | 330 // static |
323 base::Value* NetLog::GetSourceTypesAsValue() { | 331 base::Value* NetLog::GetSourceTypesAsValue() { |
324 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 332 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
325 for (int i = 0; i < SOURCE_COUNT; ++i) { | 333 for (int i = 0; i < SOURCE_COUNT; ++i) { |
326 dict->SetInteger(SourceTypeToString(static_cast<SourceType>(i)), i); | 334 dict->SetInteger(SourceTypeToString(static_cast<SourceType>(i)), i); |
327 } | 335 } |
328 return dict.release(); | 336 return dict.release(); |
329 } | 337 } |
330 | 338 |
331 // static | 339 // static |
332 const char* NetLog::EventPhaseToString(EventPhase phase) { | 340 const char* NetLog::EventPhaseToString(EventPhase phase) { |
333 switch (phase) { | 341 switch (phase) { |
334 case PHASE_BEGIN: | 342 case PHASE_BEGIN: |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 Liveness liveness = liveness_; | 492 Liveness liveness = liveness_; |
485 | 493 |
486 if (liveness == ALIVE) | 494 if (liveness == ALIVE) |
487 return; | 495 return; |
488 | 496 |
489 base::debug::Alias(&liveness); | 497 base::debug::Alias(&liveness); |
490 CHECK_EQ(ALIVE, liveness); | 498 CHECK_EQ(ALIVE, liveness); |
491 } | 499 } |
492 | 500 |
493 } // namespace net | 501 } // namespace net |
OLD | NEW |