mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1 | // 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 Mueller | 8dbfd7e | 2020-01-10 21:04:16 | [diff] [blame] | 10 | #include "base/time/time.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 11 | #include "net/base/net_export.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 12 | #include "net/log/net_log_source_type.h" |
| 13 | |
| 14 | namespace base { |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 15 | class Value; |
| 16 | } |
| 17 | |
| 18 | namespace 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. |
| 23 | struct NET_EXPORT NetLogSource { |
| 24 | static const uint32_t kInvalidId; |
| 25 | |
| 26 | NetLogSource(); |
| 27 | NetLogSource(NetLogSourceType type, uint32_t id); |
Matt Mueller | 8dbfd7e | 2020-01-10 21:04:16 | [diff] [blame] | 28 | NetLogSource(NetLogSourceType type, uint32_t id, base::TimeTicks start_time); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 29 | bool IsValid() const; |
| 30 | |
Panos Astithas | 5ab30f1 | 2020-06-15 20:46:26 | [diff] [blame^] | 31 | // Adds the source to a dictionary containing event parameters, |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 32 | // using the name "source_dependency". |
Eric Roman | 46b16b7 | 2019-05-01 01:03:01 | [diff] [blame] | 33 | void AddToEventParameters(base::Value* event_params) const; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 34 | |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 35 | // Returns a dictionary with a single entry named "source_dependency" that |
| 36 | // describes |this|. |
| 37 | base::Value ToEventParameters() const; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 38 | |
| 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 Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 43 | static bool FromEventParameters(const base::Value* event_params, |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 44 | NetLogSource* source); |
| 45 | |
| 46 | NetLogSourceType type; |
| 47 | uint32_t id; |
Matt Mueller | 8dbfd7e | 2020-01-10 21:04:16 | [diff] [blame] | 48 | base::TimeTicks start_time; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | } // namespace net |
| 52 | |
| 53 | #endif // NET_LOG_NET_LOG_SOURCE_H_ |