blob: 10c0c98b82ea862d041b350368564df14274e81c [file] [log] [blame]
mikecironef22f9812016-10-04 03:40:191// 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
mikecironef22f9812016-10-04 03:40:197#include "net/log/net_log.h"
8
9namespace net {
10
Eric Roman06bd9742019-07-13 15:19:1311NetLogEntry::NetLogEntry(NetLogEventType type,
12 NetLogSource source,
13 NetLogEventPhase phase,
14 base::TimeTicks time,
15 base::Value params)
mikecironef22f9812016-10-04 03:40:1916 : type(type),
17 source(source),
18 phase(phase),
19 time(time),
Eric Roman06bd9742019-07-13 15:19:1320 params(std::move(params)) {}
mikecironef22f9812016-10-04 03:40:1921
Chris Watkins6a33f762017-12-04 03:39:2522NetLogEntry::~NetLogEntry() = default;
mikecironef22f9812016-10-04 03:40:1923
Eric Roman79cc7552019-07-19 02:17:5424NetLogEntry::NetLogEntry(NetLogEntry&& entry) = default;
25NetLogEntry& NetLogEntry::operator=(NetLogEntry&& entry) = default;
26
Eric Roman06bd9742019-07-13 15:19:1327base::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 Roman79cc7552019-07-19 02:17:5449NetLogEntry NetLogEntry::Clone() const {
50 return NetLogEntry(type, source, phase, time, params.Clone());
51}
52
53bool NetLogEntry::HasParams() const {
54 return !params.is_none();
55}
56
mikecironef22f9812016-10-04 03:40:1957} // namespace net