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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Returns parameters for logging data transferred events. At a minum includes | 20 // Returns parameters for logging data transferred events. At a minum includes |
21 // the number of bytes transferred. If the capture mode allows logging byte | 21 // the number of bytes transferred. If the capture mode allows logging byte |
22 // contents and |byte_count| > 0, then will include the actual bytes. The | 22 // contents and |byte_count| > 0, then will include the actual bytes. The |
23 // bytes are hex-encoded, since base::StringValue only supports UTF-8. | 23 // bytes are hex-encoded, since base::StringValue only supports UTF-8. |
24 base::Value* BytesTransferredCallback(int byte_count, | 24 scoped_ptr<base::Value> BytesTransferredCallback( |
25 const char* bytes, | 25 int byte_count, |
26 NetLogCaptureMode capture_mode) { | 26 const char* bytes, |
27 base::DictionaryValue* dict = new base::DictionaryValue(); | 27 NetLogCaptureMode capture_mode) { |
| 28 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
28 dict->SetInteger("byte_count", byte_count); | 29 dict->SetInteger("byte_count", byte_count); |
29 if (capture_mode.include_socket_bytes() && byte_count > 0) | 30 if (capture_mode.include_socket_bytes() && byte_count > 0) |
30 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); | 31 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); |
31 return dict; | 32 return dict.Pass(); |
32 } | 33 } |
33 | 34 |
34 base::Value* SourceEventParametersCallback( | 35 scoped_ptr<base::Value> SourceEventParametersCallback( |
35 const NetLog::Source source, | 36 const NetLog::Source source, |
36 NetLogCaptureMode /* capture_mode */) { | 37 NetLogCaptureMode /* capture_mode */) { |
37 if (!source.IsValid()) | 38 if (!source.IsValid()) |
38 return NULL; | 39 return scoped_ptr<base::Value>(); |
39 base::DictionaryValue* event_params = new base::DictionaryValue(); | 40 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
40 source.AddToEventParameters(event_params); | 41 source.AddToEventParameters(event_params.get()); |
41 return event_params; | 42 return event_params.Pass(); |
42 } | 43 } |
43 | 44 |
44 base::Value* NetLogBoolCallback(const char* name, | 45 scoped_ptr<base::Value> NetLogBoolCallback( |
45 bool value, | 46 const char* name, |
46 NetLogCaptureMode /* capture_mode */) { | 47 bool value, |
47 base::DictionaryValue* event_params = new base::DictionaryValue(); | 48 NetLogCaptureMode /* capture_mode */) { |
| 49 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
48 event_params->SetBoolean(name, value); | 50 event_params->SetBoolean(name, value); |
49 return event_params; | 51 return event_params.Pass(); |
50 } | 52 } |
51 | 53 |
52 base::Value* NetLogIntegerCallback(const char* name, | 54 scoped_ptr<base::Value> NetLogIntegerCallback( |
53 int value, | 55 const char* name, |
54 NetLogCaptureMode /* capture_mode */) { | 56 int value, |
55 base::DictionaryValue* event_params = new base::DictionaryValue(); | 57 NetLogCaptureMode /* capture_mode */) { |
| 58 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
56 event_params->SetInteger(name, value); | 59 event_params->SetInteger(name, value); |
57 return event_params; | 60 return event_params.Pass(); |
58 } | 61 } |
59 | 62 |
60 base::Value* NetLogInt64Callback(const char* name, | 63 scoped_ptr<base::Value> NetLogInt64Callback( |
61 int64 value, | 64 const char* name, |
62 NetLogCaptureMode /* capture_mode */) { | 65 int64 value, |
63 base::DictionaryValue* event_params = new base::DictionaryValue(); | 66 NetLogCaptureMode /* capture_mode */) { |
| 67 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
64 event_params->SetString(name, base::Int64ToString(value)); | 68 event_params->SetString(name, base::Int64ToString(value)); |
65 return event_params; | 69 return event_params.Pass(); |
66 } | 70 } |
67 | 71 |
68 base::Value* NetLogStringCallback(const char* name, | 72 scoped_ptr<base::Value> NetLogStringCallback( |
69 const std::string* value, | 73 const char* name, |
70 NetLogCaptureMode /* capture_mode */) { | 74 const std::string* value, |
71 base::DictionaryValue* event_params = new base::DictionaryValue(); | 75 NetLogCaptureMode /* capture_mode */) { |
| 76 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
72 event_params->SetString(name, *value); | 77 event_params->SetString(name, *value); |
73 return event_params; | 78 return event_params.Pass(); |
74 } | 79 } |
75 | 80 |
76 base::Value* NetLogString16Callback(const char* name, | 81 scoped_ptr<base::Value> NetLogString16Callback( |
77 const base::string16* value, | 82 const char* name, |
78 NetLogCaptureMode /* capture_mode */) { | 83 const base::string16* value, |
79 base::DictionaryValue* event_params = new base::DictionaryValue(); | 84 NetLogCaptureMode /* capture_mode */) { |
| 85 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
80 event_params->SetString(name, *value); | 86 event_params->SetString(name, *value); |
81 return event_params; | 87 return event_params.Pass(); |
82 } | 88 } |
83 | 89 |
84 } // namespace | 90 } // namespace |
85 | 91 |
86 // LoadTimingInfo requires this be 0. | 92 // LoadTimingInfo requires this be 0. |
87 const uint32 NetLog::Source::kInvalidId = 0; | 93 const uint32 NetLog::Source::kInvalidId = 0; |
88 | 94 |
89 NetLog::Source::Source() : type(SOURCE_NONE), id(kInvalidId) { | 95 NetLog::Source::Source() : type(SOURCE_NONE), id(kInvalidId) { |
90 } | 96 } |
91 | 97 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 data_->parameters_callback->Run(capture_mode_)); | 156 data_->parameters_callback->Run(capture_mode_)); |
151 if (value) | 157 if (value) |
152 entry_dict->Set("params", value.Pass()); | 158 entry_dict->Set("params", value.Pass()); |
153 } | 159 } |
154 | 160 |
155 return entry_dict; | 161 return entry_dict; |
156 } | 162 } |
157 | 163 |
158 base::Value* NetLog::Entry::ParametersToValue() const { | 164 base::Value* NetLog::Entry::ParametersToValue() const { |
159 if (data_->parameters_callback) | 165 if (data_->parameters_callback) |
160 return data_->parameters_callback->Run(capture_mode_); | 166 return data_->parameters_callback->Run(capture_mode_).release(); |
161 return NULL; | 167 return NULL; |
162 } | 168 } |
163 | 169 |
164 NetLog::EntryData::EntryData(EventType type, | 170 NetLog::EntryData::EntryData(EventType type, |
165 Source source, | 171 Source source, |
166 EventPhase phase, | 172 EventPhase phase, |
167 base::TimeTicks time, | 173 base::TimeTicks time, |
168 const ParametersCallback* parameters_callback) | 174 const ParametersCallback* parameters_callback) |
169 : type(type), | 175 : type(type), |
170 source(source), | 176 source(source), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 #include "net/log/net_log_event_type_list.h" | 290 #include "net/log/net_log_event_type_list.h" |
285 #undef EVENT_TYPE | 291 #undef EVENT_TYPE |
286 default: | 292 default: |
287 NOTREACHED(); | 293 NOTREACHED(); |
288 return NULL; | 294 return NULL; |
289 } | 295 } |
290 } | 296 } |
291 | 297 |
292 // static | 298 // static |
293 base::Value* NetLog::GetEventTypesAsValue() { | 299 base::Value* NetLog::GetEventTypesAsValue() { |
294 base::DictionaryValue* dict = new base::DictionaryValue(); | 300 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
295 for (int i = 0; i < EVENT_COUNT; ++i) { | 301 for (int i = 0; i < EVENT_COUNT; ++i) { |
296 dict->SetInteger(EventTypeToString(static_cast<EventType>(i)), i); | 302 dict->SetInteger(EventTypeToString(static_cast<EventType>(i)), i); |
297 } | 303 } |
298 return dict; | 304 return dict.release(); |
299 } | 305 } |
300 | 306 |
301 // static | 307 // static |
302 const char* NetLog::SourceTypeToString(SourceType source) { | 308 const char* NetLog::SourceTypeToString(SourceType source) { |
303 switch (source) { | 309 switch (source) { |
304 #define SOURCE_TYPE(label) \ | 310 #define SOURCE_TYPE(label) \ |
305 case SOURCE_##label: \ | 311 case SOURCE_##label: \ |
306 return #label; | 312 return #label; |
307 #include "net/log/net_log_source_type_list.h" | 313 #include "net/log/net_log_source_type_list.h" |
308 #undef SOURCE_TYPE | 314 #undef SOURCE_TYPE |
309 default: | 315 default: |
310 NOTREACHED(); | 316 NOTREACHED(); |
311 return NULL; | 317 return NULL; |
312 } | 318 } |
313 } | 319 } |
314 | 320 |
315 // static | 321 // static |
316 base::Value* NetLog::GetSourceTypesAsValue() { | 322 base::Value* NetLog::GetSourceTypesAsValue() { |
317 base::DictionaryValue* dict = new base::DictionaryValue(); | 323 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
318 for (int i = 0; i < SOURCE_COUNT; ++i) { | 324 for (int i = 0; i < SOURCE_COUNT; ++i) { |
319 dict->SetInteger(SourceTypeToString(static_cast<SourceType>(i)), i); | 325 dict->SetInteger(SourceTypeToString(static_cast<SourceType>(i)), i); |
320 } | 326 } |
321 return dict; | 327 return dict.release(); |
322 } | 328 } |
323 | 329 |
324 // static | 330 // static |
325 const char* NetLog::EventPhaseToString(EventPhase phase) { | 331 const char* NetLog::EventPhaseToString(EventPhase phase) { |
326 switch (phase) { | 332 switch (phase) { |
327 case PHASE_BEGIN: | 333 case PHASE_BEGIN: |
328 return "PHASE_BEGIN"; | 334 return "PHASE_BEGIN"; |
329 case PHASE_END: | 335 case PHASE_END: |
330 return "PHASE_END"; | 336 return "PHASE_END"; |
331 case PHASE_NONE: | 337 case PHASE_NONE: |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 Liveness liveness = liveness_; | 484 Liveness liveness = liveness_; |
479 | 485 |
480 if (liveness == ALIVE) | 486 if (liveness == ALIVE) |
481 return; | 487 return; |
482 | 488 |
483 base::debug::Alias(&liveness); | 489 base::debug::Alias(&liveness); |
484 CHECK_EQ(ALIVE, liveness); | 490 CHECK_EQ(ALIVE, liveness); |
485 } | 491 } |
486 | 492 |
487 } // namespace net | 493 } // namespace net |
OLD | NEW |