blob: 91797098fad36ceaedeb2d54dce5401244ce9ba2 [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#ifndef NET_LOG_NET_LOG_SOURCE_H_
6#define NET_LOG_NET_LOG_SOURCE_H_
7
8#include <stdint.h>
9
Matt Mueller8dbfd7e2020-01-10 21:04:1610#include "base/time/time.h"
Matt Menkec9a0b382022-05-27 22:31:4711#include "base/values.h"
mikecironef22f9812016-10-04 03:40:1912#include "net/base/net_export.h"
mikecironef22f9812016-10-04 03:40:1913#include "net/log/net_log_source_type.h"
14
mikecironef22f9812016-10-04 03:40:1915namespace 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.
20struct NET_EXPORT NetLogSource {
21 static const uint32_t kInvalidId;
22
23 NetLogSource();
24 NetLogSource(NetLogSourceType type, uint32_t id);
Matt Mueller8dbfd7e2020-01-10 21:04:1625 NetLogSource(NetLogSourceType type, uint32_t id, base::TimeTicks start_time);
ainozaki7eefe912021-10-12 03:40:2626
27 bool operator==(const NetLogSource& rhs) const;
28
mikecironef22f9812016-10-04 03:40:1929 bool IsValid() const;
30
Panos Astithas5ab30f12020-06-15 20:46:2631 // Adds the source to a dictionary containing event parameters,
mikecironef22f9812016-10-04 03:40:1932 // using the name "source_dependency".
Matt Menkec9a0b382022-05-27 22:31:4733 void AddToEventParameters(base::Value::Dict& event_params) const;
34 // Legacy version of above method. Should be removed once no longer used.
Eric Roman46b16b72019-05-01 01:03:0135 void AddToEventParameters(base::Value* event_params) const;
mikecironef22f9812016-10-04 03:40:1936
Eric Roman06bd9742019-07-13 15:19:1337 // Returns a dictionary with a single entry named "source_dependency" that
38 // describes |this|.
39 base::Value ToEventParameters() const;
mikecironef22f9812016-10-04 03:40:1940
mikecironef22f9812016-10-04 03:40:1941 NetLogSourceType type;
42 uint32_t id;
Matt Mueller8dbfd7e2020-01-10 21:04:1643 base::TimeTicks start_time;
mikecironef22f9812016-10-04 03:40:1944};
45
46} // namespace net
47
48#endif // NET_LOG_NET_LOG_SOURCE_H_