1 // Copyright 2016 The Chromium Authors
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/time/time.h"
10 #include "base/values.h"
11 #include "net/log/net_log.h"
12 #include "net/log/net_log_event_type.h"
13 #include "net/log/net_log_source.h"
14
15 namespace net {
16
NetLogEntry(NetLogEventType type,NetLogSource source,NetLogEventPhase phase,base::TimeTicks time,base::Value::Dict params)17 NetLogEntry::NetLogEntry(NetLogEventType type,
18 NetLogSource source,
19 NetLogEventPhase phase,
20 base::TimeTicks time,
21 base::Value::Dict params)
22 : type(type),
23 source(source),
24 phase(phase),
25 time(time),
26 params(std::move(params)) {}
27
28 NetLogEntry::~NetLogEntry() = default;
29
30 NetLogEntry::NetLogEntry(NetLogEntry&& entry) = default;
31 NetLogEntry& NetLogEntry::operator=(NetLogEntry&& entry) = default;
32
ToDict() const33 base::Value::Dict NetLogEntry::ToDict() const {
34 base::Value::Dict entry_dict;
35
36 entry_dict.Set("time", NetLog::TickCountToString(time));
37
38 // Set the entry source.
39 base::Value::Dict source_dict;
40 source_dict.Set("id", static_cast<int>(source.id));
41 source_dict.Set("type", static_cast<int>(source.type));
42 source_dict.Set("start_time", NetLog::TickCountToString(source.start_time));
43 entry_dict.Set("source", std::move(source_dict));
44
45 // Set the event info.
46 entry_dict.Set("type", static_cast<int>(type));
47 entry_dict.Set("phase", static_cast<int>(phase));
48
49 // Set the event-specific parameters.
50 if (!params.empty()) {
51 entry_dict.Set("params", params.Clone());
52 }
53
54 return entry_dict;
55 }
56
Clone() const57 NetLogEntry NetLogEntry::Clone() const {
58 return NetLogEntry(type, source, phase, time, params.Clone());
59 }
60
HasParams() const61 bool NetLogEntry::HasParams() const {
62 return !params.empty();
63 }
64
65 } // namespace net
66