blob: 046f371c9f111a0a130724ebc43d1b664a934aa2 [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"
mikecironef22f9812016-10-04 03:40:1911#include "net/base/net_export.h"
mikecironef22f9812016-10-04 03:40:1912#include "net/log/net_log_source_type.h"
13
14namespace base {
mikecironef22f9812016-10-04 03:40:1915class Value;
16}
17
18namespace net {
19
20// Identifies the entity that generated this log. The |id| field should
21// uniquely identify the source, and is used by log observers to infer
22// message groupings. Can use NetLog::NextID() to create unique IDs.
23struct NET_EXPORT NetLogSource {
24 static const uint32_t kInvalidId;
25
26 NetLogSource();
27 NetLogSource(NetLogSourceType type, uint32_t id);
Matt Mueller8dbfd7e2020-01-10 21:04:1628 NetLogSource(NetLogSourceType type, uint32_t id, base::TimeTicks start_time);
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".
Eric Roman46b16b72019-05-01 01:03:0133 void AddToEventParameters(base::Value* event_params) const;
mikecironef22f9812016-10-04 03:40:1934
Eric Roman06bd9742019-07-13 15:19:1335 // Returns a dictionary with a single entry named "source_dependency" that
36 // describes |this|.
37 base::Value ToEventParameters() const;
mikecironef22f9812016-10-04 03:40:1938
39 // Attempts to extract a NetLogSource from a set of event parameters. Returns
40 // true and writes the result to |source| on success. Returns false and
41 // makes |source| an invalid source on failure.
42 // TODO(mmenke): Long term, we want to remove this.
Eric Roman79cc7552019-07-19 02:17:5443 static bool FromEventParameters(const base::Value* event_params,
mikecironef22f9812016-10-04 03:40:1944 NetLogSource* source);
45
46 NetLogSourceType type;
47 uint32_t id;
Matt Mueller8dbfd7e2020-01-10 21:04:1648 base::TimeTicks start_time;
mikecironef22f9812016-10-04 03:40:1949};
50
51} // namespace net
52
53#endif // NET_LOG_NET_LOG_SOURCE_H_