OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/log/net_log_entry.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/callback.h" |
| 10 #include "base/values.h" |
| 11 #include "net/log/net_log.h" |
| 12 |
| 13 namespace net { |
| 14 |
| 15 std::unique_ptr<base::Value> NetLogEntry::ToValue() const { |
| 16 std::unique_ptr<base::DictionaryValue> entry_dict( |
| 17 new base::DictionaryValue()); |
| 18 |
| 19 entry_dict->SetString("time", NetLog::TickCountToString(data_->time)); |
| 20 |
| 21 // Set the entry source. |
| 22 std::unique_ptr<base::DictionaryValue> source_dict( |
| 23 new base::DictionaryValue()); |
| 24 source_dict->SetInteger("id", data_->source.id); |
| 25 source_dict->SetInteger("type", static_cast<int>(data_->source.type)); |
| 26 entry_dict->Set("source", std::move(source_dict)); |
| 27 |
| 28 // Set the event info. |
| 29 entry_dict->SetInteger("type", static_cast<int>(data_->type)); |
| 30 entry_dict->SetInteger("phase", static_cast<int>(data_->phase)); |
| 31 |
| 32 // Set the event-specific parameters. |
| 33 if (data_->parameters_callback) { |
| 34 std::unique_ptr<base::Value> value( |
| 35 data_->parameters_callback->Run(capture_mode_)); |
| 36 if (value) |
| 37 entry_dict->Set("params", std::move(value)); |
| 38 } |
| 39 |
| 40 return std::move(entry_dict); |
| 41 } |
| 42 |
| 43 std::unique_ptr<base::Value> NetLogEntry::ParametersToValue() const { |
| 44 if (data_->parameters_callback) |
| 45 return data_->parameters_callback->Run(capture_mode_); |
| 46 return nullptr; |
| 47 } |
| 48 |
| 49 NetLogEntryData::NetLogEntryData( |
| 50 NetLogEventType type, |
| 51 NetLogSource source, |
| 52 NetLogEventPhase phase, |
| 53 base::TimeTicks time, |
| 54 const NetLogParametersCallback* parameters_callback) |
| 55 : type(type), |
| 56 source(source), |
| 57 phase(phase), |
| 58 time(time), |
| 59 parameters_callback(parameters_callback) {} |
| 60 |
| 61 NetLogEntryData::~NetLogEntryData() {} |
| 62 |
| 63 NetLogEntry::NetLogEntry(const NetLogEntryData* data, |
| 64 NetLogCaptureMode capture_mode) |
| 65 : data_(data), capture_mode_(capture_mode) {} |
| 66 |
| 67 NetLogEntry::~NetLogEntry() {} |
| 68 |
| 69 } // namespace net |
OLD | NEW |