| 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> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 15 | 17 |
| 16 namespace net { | 18 namespace net { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 // Returns parameters for logging data transferred events. At a minimum includes | 22 // Returns parameters for logging data transferred events. At a minimum includes |
| 21 // 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 |
| 22 // 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 |
| 23 // bytes are hex-encoded, since base::StringValue only supports UTF-8. | 25 // bytes are hex-encoded, since base::StringValue only supports UTF-8. |
| 24 scoped_ptr<base::Value> BytesTransferredCallback( | 26 scoped_ptr<base::Value> BytesTransferredCallback( |
| 25 int byte_count, | 27 int byte_count, |
| 26 const char* bytes, | 28 const char* bytes, |
| 27 NetLogCaptureMode capture_mode) { | 29 NetLogCaptureMode capture_mode) { |
| 28 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 30 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 29 dict->SetInteger("byte_count", byte_count); | 31 dict->SetInteger("byte_count", byte_count); |
| 30 if (capture_mode.include_socket_bytes() && byte_count > 0) | 32 if (capture_mode.include_socket_bytes() && byte_count > 0) |
| 31 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); | 33 dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count)); |
| 32 return dict.Pass(); | 34 return std::move(dict); |
| 33 } | 35 } |
| 34 | 36 |
| 35 scoped_ptr<base::Value> SourceEventParametersCallback( | 37 scoped_ptr<base::Value> SourceEventParametersCallback( |
| 36 const NetLog::Source source, | 38 const NetLog::Source source, |
| 37 NetLogCaptureMode /* capture_mode */) { | 39 NetLogCaptureMode /* capture_mode */) { |
| 38 if (!source.IsValid()) | 40 if (!source.IsValid()) |
| 39 return scoped_ptr<base::Value>(); | 41 return scoped_ptr<base::Value>(); |
| 40 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 42 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
| 41 source.AddToEventParameters(event_params.get()); | 43 source.AddToEventParameters(event_params.get()); |
| 42 return event_params.Pass(); | 44 return std::move(event_params); |
| 43 } | 45 } |
| 44 | 46 |
| 45 scoped_ptr<base::Value> NetLogBoolCallback( | 47 scoped_ptr<base::Value> NetLogBoolCallback( |
| 46 const char* name, | 48 const char* name, |
| 47 bool value, | 49 bool value, |
| 48 NetLogCaptureMode /* capture_mode */) { | 50 NetLogCaptureMode /* capture_mode */) { |
| 49 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 51 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
| 50 event_params->SetBoolean(name, value); | 52 event_params->SetBoolean(name, value); |
| 51 return event_params.Pass(); | 53 return std::move(event_params); |
| 52 } | 54 } |
| 53 | 55 |
| 54 scoped_ptr<base::Value> NetLogIntCallback( | 56 scoped_ptr<base::Value> NetLogIntCallback( |
| 55 const char* name, | 57 const char* name, |
| 56 int value, | 58 int value, |
| 57 NetLogCaptureMode /* capture_mode */) { | 59 NetLogCaptureMode /* capture_mode */) { |
| 58 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 60 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
| 59 event_params->SetInteger(name, value); | 61 event_params->SetInteger(name, value); |
| 60 return event_params.Pass(); | 62 return std::move(event_params); |
| 61 } | 63 } |
| 62 | 64 |
| 63 scoped_ptr<base::Value> NetLogInt64Callback( | 65 scoped_ptr<base::Value> NetLogInt64Callback( |
| 64 const char* name, | 66 const char* name, |
| 65 int64_t value, | 67 int64_t value, |
| 66 NetLogCaptureMode /* capture_mode */) { | 68 NetLogCaptureMode /* capture_mode */) { |
| 67 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 69 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
| 68 event_params->SetString(name, base::Int64ToString(value)); | 70 event_params->SetString(name, base::Int64ToString(value)); |
| 69 return event_params.Pass(); | 71 return std::move(event_params); |
| 70 } | 72 } |
| 71 | 73 |
| 72 scoped_ptr<base::Value> NetLogStringCallback( | 74 scoped_ptr<base::Value> NetLogStringCallback( |
| 73 const char* name, | 75 const char* name, |
| 74 const std::string* value, | 76 const std::string* value, |
| 75 NetLogCaptureMode /* capture_mode */) { | 77 NetLogCaptureMode /* capture_mode */) { |
| 76 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 78 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
| 77 event_params->SetString(name, *value); | 79 event_params->SetString(name, *value); |
| 78 return event_params.Pass(); | 80 return std::move(event_params); |
| 79 } | 81 } |
| 80 | 82 |
| 81 scoped_ptr<base::Value> NetLogString16Callback( | 83 scoped_ptr<base::Value> NetLogString16Callback( |
| 82 const char* name, | 84 const char* name, |
| 83 const base::string16* value, | 85 const base::string16* value, |
| 84 NetLogCaptureMode /* capture_mode */) { | 86 NetLogCaptureMode /* capture_mode */) { |
| 85 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 87 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
| 86 event_params->SetString(name, *value); | 88 event_params->SetString(name, *value); |
| 87 return event_params.Pass(); | 89 return std::move(event_params); |
| 88 } | 90 } |
| 89 | 91 |
| 90 } // namespace | 92 } // namespace |
| 91 | 93 |
| 92 // LoadTimingInfo requires this be 0. | 94 // LoadTimingInfo requires this be 0. |
| 93 const uint32_t NetLog::Source::kInvalidId = 0; | 95 const uint32_t NetLog::Source::kInvalidId = 0; |
| 94 | 96 |
| 95 NetLog::Source::Source() : type(SOURCE_NONE), id(kInvalidId) { | 97 NetLog::Source::Source() : type(SOURCE_NONE), id(kInvalidId) { |
| 96 } | 98 } |
| 97 | 99 |
| 98 NetLog::Source::Source(SourceType type, uint32_t id) : type(type), id(id) {} | 100 NetLog::Source::Source(SourceType type, uint32_t id) : type(type), id(id) {} |
| 99 | 101 |
| 100 bool NetLog::Source::IsValid() const { | 102 bool NetLog::Source::IsValid() const { |
| 101 return id != kInvalidId; | 103 return id != kInvalidId; |
| 102 } | 104 } |
| 103 | 105 |
| 104 void NetLog::Source::AddToEventParameters( | 106 void NetLog::Source::AddToEventParameters( |
| 105 base::DictionaryValue* event_params) const { | 107 base::DictionaryValue* event_params) const { |
| 106 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 108 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 107 dict->SetInteger("type", static_cast<int>(type)); | 109 dict->SetInteger("type", static_cast<int>(type)); |
| 108 dict->SetInteger("id", static_cast<int>(id)); | 110 dict->SetInteger("id", static_cast<int>(id)); |
| 109 event_params->Set("source_dependency", dict.Pass()); | 111 event_params->Set("source_dependency", std::move(dict)); |
| 110 } | 112 } |
| 111 | 113 |
| 112 NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const { | 114 NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const { |
| 113 return base::Bind(&SourceEventParametersCallback, *this); | 115 return base::Bind(&SourceEventParametersCallback, *this); |
| 114 } | 116 } |
| 115 | 117 |
| 116 // static | 118 // static |
| 117 bool NetLog::Source::FromEventParameters(base::Value* event_params, | 119 bool NetLog::Source::FromEventParameters(base::Value* event_params, |
| 118 Source* source) { | 120 Source* source) { |
| 119 base::DictionaryValue* dict = NULL; | 121 base::DictionaryValue* dict = NULL; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 136 | 138 |
| 137 base::Value* NetLog::Entry::ToValue() const { | 139 base::Value* NetLog::Entry::ToValue() const { |
| 138 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); | 140 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); |
| 139 | 141 |
| 140 entry_dict->SetString("time", TickCountToString(data_->time)); | 142 entry_dict->SetString("time", TickCountToString(data_->time)); |
| 141 | 143 |
| 142 // Set the entry source. | 144 // Set the entry source. |
| 143 scoped_ptr<base::DictionaryValue> source_dict(new base::DictionaryValue()); | 145 scoped_ptr<base::DictionaryValue> source_dict(new base::DictionaryValue()); |
| 144 source_dict->SetInteger("id", data_->source.id); | 146 source_dict->SetInteger("id", data_->source.id); |
| 145 source_dict->SetInteger("type", static_cast<int>(data_->source.type)); | 147 source_dict->SetInteger("type", static_cast<int>(data_->source.type)); |
| 146 entry_dict->Set("source", source_dict.Pass()); | 148 entry_dict->Set("source", std::move(source_dict)); |
| 147 | 149 |
| 148 // Set the event info. | 150 // Set the event info. |
| 149 entry_dict->SetInteger("type", static_cast<int>(data_->type)); | 151 entry_dict->SetInteger("type", static_cast<int>(data_->type)); |
| 150 entry_dict->SetInteger("phase", static_cast<int>(data_->phase)); | 152 entry_dict->SetInteger("phase", static_cast<int>(data_->phase)); |
| 151 | 153 |
| 152 // Set the event-specific parameters. | 154 // Set the event-specific parameters. |
| 153 if (data_->parameters_callback) { | 155 if (data_->parameters_callback) { |
| 154 scoped_ptr<base::Value> value( | 156 scoped_ptr<base::Value> value( |
| 155 data_->parameters_callback->Run(capture_mode_)); | 157 data_->parameters_callback->Run(capture_mode_)); |
| 156 if (value) | 158 if (value) |
| 157 entry_dict->Set("params", value.Pass()); | 159 entry_dict->Set("params", std::move(value)); |
| 158 } | 160 } |
| 159 | 161 |
| 160 return entry_dict.release(); | 162 return entry_dict.release(); |
| 161 } | 163 } |
| 162 | 164 |
| 163 base::Value* NetLog::Entry::ParametersToValue() const { | 165 base::Value* NetLog::Entry::ParametersToValue() const { |
| 164 if (data_->parameters_callback) | 166 if (data_->parameters_callback) |
| 165 return data_->parameters_callback->Run(capture_mode_).release(); | 167 return data_->parameters_callback->Run(capture_mode_).release(); |
| 166 return NULL; | 168 return NULL; |
| 167 } | 169 } |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 Liveness liveness = liveness_; | 484 Liveness liveness = liveness_; |
| 483 | 485 |
| 484 if (liveness == ALIVE) | 486 if (liveness == ALIVE) |
| 485 return; | 487 return; |
| 486 | 488 |
| 487 base::debug::Alias(&liveness); | 489 base::debug::Alias(&liveness); |
| 488 CHECK_EQ(ALIVE, liveness); | 490 CHECK_EQ(ALIVE, liveness); |
| 489 } | 491 } |
| 490 | 492 |
| 491 } // namespace net | 493 } // namespace net |
| OLD | NEW |