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 | |
| 10 | #include "net/base/net_export.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 11 | #include "net/log/net_log_source_type.h" |
| 12 | |
| 13 | namespace base { |
| 14 | class DictionaryValue; |
| 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); |
| 28 | bool IsValid() const; |
| 29 | |
| 30 | // Adds the source to a DictionaryValue containing event parameters, |
| 31 | // using the name "source_dependency". |
Eric Roman | 46b16b7 | 2019-05-01 01:03:01 | [diff] [blame] | 32 | void AddToEventParameters(base::Value* event_params) const; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 33 | |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame^] | 34 | // Returns a dictionary with a single entry named "source_dependency" that |
| 35 | // describes |this|. |
| 36 | base::Value ToEventParameters() const; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 37 | |
| 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_ |