blob: 16391679e33ac17f5b53647779b7bbf342aeb950 [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
10#include "net/base/net_export.h"
mikecironef22f9812016-10-04 03:40:1911#include "net/log/net_log_source_type.h"
12
13namespace base {
14class DictionaryValue;
15class 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);
28 bool IsValid() const;
29
30 // Adds the source to a DictionaryValue containing event parameters,
31 // using the name "source_dependency".
Eric Roman46b16b72019-05-01 01:03:0132 void AddToEventParameters(base::Value* event_params) const;
mikecironef22f9812016-10-04 03:40:1933
Eric Roman06bd9742019-07-13 15:19:1334 // Returns a dictionary with a single entry named "source_dependency" that
35 // describes |this|.
36 base::Value ToEventParameters() const;
mikecironef22f9812016-10-04 03:40:1937
38 // Attempts to extract a NetLogSource from a set of event parameters. Returns
39 // true and writes the result to |source| on success. Returns false and
40 // makes |source| an invalid source on failure.
41 // TODO(mmenke): Long term, we want to remove this.
42 static bool FromEventParameters(base::Value* event_params,
43 NetLogSource* source);
44
45 NetLogSourceType type;
46 uint32_t id;
47};
48
49} // namespace net
50
51#endif // NET_LOG_NET_LOG_SOURCE_H_