mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 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 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7 | #include "net/log/net_log.h" |
| 8 | |
| 9 | namespace net { |
| 10 | |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 11 | NetLogEntry::NetLogEntry(NetLogEventType type, |
| 12 | NetLogSource source, |
| 13 | NetLogEventPhase phase, |
| 14 | base::TimeTicks time, |
| 15 | base::Value params) |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 16 | : type(type), |
| 17 | source(source), |
| 18 | phase(phase), |
| 19 | time(time), |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 20 | params(std::move(params)) {} |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 21 | |
Chris Watkins | 6a33f76 | 2017-12-04 03:39:25 | [diff] [blame] | 22 | NetLogEntry::~NetLogEntry() = default; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 23 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 24 | NetLogEntry::NetLogEntry(NetLogEntry&& entry) = default; |
| 25 | NetLogEntry& NetLogEntry::operator=(NetLogEntry&& entry) = default; |
| 26 | |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 27 | base::Value NetLogEntry::ToValue() const { |
| 28 | base::DictionaryValue entry_dict; |
| 29 | |
| 30 | entry_dict.SetString("time", NetLog::TickCountToString(time)); |
| 31 | |
| 32 | // Set the entry source. |
| 33 | base::DictionaryValue source_dict; |
| 34 | source_dict.SetInteger("id", source.id); |
| 35 | source_dict.SetInteger("type", static_cast<int>(source.type)); |
| 36 | entry_dict.SetKey("source", std::move(source_dict)); |
| 37 | |
| 38 | // Set the event info. |
| 39 | entry_dict.SetInteger("type", static_cast<int>(type)); |
| 40 | entry_dict.SetInteger("phase", static_cast<int>(phase)); |
| 41 | |
| 42 | // Set the event-specific parameters. |
| 43 | if (!params.is_none()) |
| 44 | entry_dict.SetKey("params", params.Clone()); |
| 45 | |
| 46 | return std::move(entry_dict); |
| 47 | } |
| 48 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 49 | NetLogEntry NetLogEntry::Clone() const { |
| 50 | return NetLogEntry(type, source, phase, time, params.Clone()); |
| 51 | } |
| 52 | |
| 53 | bool NetLogEntry::HasParams() const { |
| 54 | return !params.is_none(); |
| 55 | } |
| 56 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 57 | } // namespace net |