OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ |
| 6 #define NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ |
| 7 |
| 8 namespace net { |
| 9 |
| 10 // Defined type for network traffic annotation tags. |
| 11 using NetworkTrafficAnnotationTag = const char*; |
| 12 |
| 13 // Function to convert a network traffic annotation's unique id and protobuf |
| 14 // text into a NetworkTrafficAnnotationTag. |
| 15 // |
| 16 // This function serves as a tag that can be discovered and extracted via |
| 17 // clang tools. This allows reviewing all network traffic that is generated |
| 18 // and annotated by Chrome. |
| 19 // |
| 20 // |unique_id| should be a string that uniquely identifies this annotation |
| 21 // across all of Chromium source code. |
| 22 // |proto| is a text-encoded NetworkTrafficAnnotation protobuf (see |
| 23 // tools/traffic_annotaiton/traffic_annotation.proto) |
| 24 // |
| 25 // This function should be called with inlined parameters like |
| 26 // NetworkTrafficAnnotationTag tag = DefineNetworkTrafficAnnotation( |
| 27 // "unique_tag_id", |
| 28 // R"(semantics: {...} |
| 29 // policy: {...} |
| 30 // )"); |
| 31 // This allows the compiler to extract the |unique_id| at compile time without |
| 32 // copying the entire protobuf into the text segment of the binary or creating |
| 33 // any runtime performance impact. |
| 34 // |
| 35 // Please do NOT use the following syntax: |
| 36 // const char* proto = R("..."); |
| 37 // NetworkTrafficAnnotationTag tag = DefineNetworkTrafficAnnotation( |
| 38 // "unique_tag_id", proto); |
| 39 // You can see a sample and an empty template for text-coded protobuf in |
| 40 // (tools/traffic_annotation/sample_traffic_annotation.cc) |
| 41 // TODO(crbug.com/690323): Add tools to check annotation text's format during |
| 42 // presubmit checks. |
| 43 constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation( |
| 44 const char* unique_id, |
| 45 const char* proto) { |
| 46 return (NetworkTrafficAnnotationTag)unique_id; |
| 47 } |
| 48 |
| 49 } // namespace net |
| 50 |
| 51 // Placeholder for unannotated usages. |
| 52 #define NO_TRAFFIC_ANNOTATION_YET \ |
| 53 net::DefineNetworkTrafficAnnotation("Undefined", "Nothing here yet.") |
| 54 |
| 55 #endif // NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ |
OLD | NEW |