xref: /aosp_15_r20/external/cronet/net/log/net_log_source.h (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 #ifndef NET_LOG_NET_LOG_SOURCE_H_
6 #define NET_LOG_NET_LOG_SOURCE_H_
7 
8 #include <stdint.h>
9 
10 #include "base/time/time.h"
11 #include "base/values.h"
12 #include "net/base/net_export.h"
13 #include "net/log/net_log_source_type.h"
14 
15 namespace net {
16 
17 // Identifies the entity that generated this log. The |id| field should
18 // uniquely identify the source, and is used by log observers to infer
19 // message groupings. Can use NetLog::NextID() to create unique IDs.
20 struct NET_EXPORT NetLogSource {
21   static const uint32_t kInvalidId;
22 
23   NetLogSource();
24   NetLogSource(NetLogSourceType type, uint32_t id);
25   NetLogSource(NetLogSourceType type, uint32_t id, base::TimeTicks start_time);
26 
27   bool operator==(const NetLogSource& rhs) const;
28 
29   bool IsValid() const;
30 
31   // Adds the source to a dictionary containing event parameters,
32   // using the name "source_dependency".
33   void AddToEventParameters(base::Value::Dict& event_params) const;
34 
35   // Returns a dictionary with a single entry named "source_dependency" that
36   // describes |this|.
37   base::Value::Dict ToEventParameters() const;
38 
39   NetLogSourceType type;
40   uint32_t id;
41   base::TimeTicks start_time;
42 };
43 
44 }  // namespace net
45 
46 #endif  // NET_LOG_NET_LOG_SOURCE_H_
47