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