| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ | 5 #ifndef NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ |
| 6 #define NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ | 6 #define NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ |
| 7 | 7 |
| 8 namespace net { | 8 namespace net { |
| 9 | 9 |
| 10 // Defined type for network traffic annotation tags. | 10 // Defined type for network traffic annotation tags. |
| 11 #if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON) |
| 12 struct NetworkTrafficAnnotationTag { |
| 13 const char* const unique_id; |
| 14 const char* const proto; |
| 15 }; |
| 16 #else |
| 11 using NetworkTrafficAnnotationTag = const char* const; | 17 using NetworkTrafficAnnotationTag = const char* const; |
| 18 #endif |
| 12 | 19 |
| 13 // Function to convert a network traffic annotation's unique id and protobuf | 20 // Function to convert a network traffic annotation's unique id and protobuf |
| 14 // text into a NetworkTrafficAnnotationTag. | 21 // text into a NetworkTrafficAnnotationTag. |
| 15 // | 22 // |
| 16 // This function serves as a tag that can be discovered and extracted via | 23 // 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 | 24 // clang tools. This allows reviewing all network traffic that is generated |
| 18 // and annotated by Chrome. | 25 // and annotated by Chrome. |
| 19 // | 26 // |
| 20 // |unique_id| should be a string that uniquely identifies this annotation | 27 // |unique_id| should be a string that uniquely identifies this annotation |
| 21 // across all of Chromium source code. | 28 // across all of Chromium source code. |
| 22 // |proto| is a text-encoded NetworkTrafficAnnotation protobuf (see | 29 // |proto| is a text-encoded NetworkTrafficAnnotation protobuf (see |
| 23 // tools/traffic_annotation/traffic_annotation.proto) | 30 // tools/traffic_annotation/traffic_annotation.proto) |
| 24 // | 31 // |
| 25 // An empty and a sample template for the text-encoded protobuf can be found in | 32 // An empty and a sample template for the text-encoded protobuf can be found in |
| 26 // //tools/traffic_annotation/sample_traffic_annotation.cc. | 33 // //tools/traffic_annotation/sample_traffic_annotation.cc. |
| 27 // TODO(crbug.com/690323): Add tools to check annotation text's format during | 34 // TODO(crbug.com/690323): Add tools to check annotation text's format during |
| 28 // presubmit checks. | 35 // presubmit checks. |
| 29 template <size_t N1, size_t N2> | 36 template <unsigned N1, unsigned N2> |
| 30 constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation( | 37 constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation( |
| 31 const char (&unique_id)[N1], | 38 const char (&unique_id)[N1], |
| 32 const char (&proto)[N2]) { | 39 const char (&proto)[N2]) { |
| 40 #if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON) |
| 41 return NetworkTrafficAnnotationTag({unique_id, proto}); |
| 42 #else |
| 33 return unique_id; | 43 return unique_id; |
| 44 #endif |
| 34 } | 45 } |
| 35 | 46 |
| 36 } // namespace net | 47 } // namespace net |
| 37 | 48 |
| 38 // Placeholder for unannotated usages. | 49 // Placeholder for unannotated usages. |
| 39 #define NO_TRAFFIC_ANNOTATION_YET \ | 50 #define NO_TRAFFIC_ANNOTATION_YET \ |
| 40 net::DefineNetworkTrafficAnnotation("Undefined", "Nothing here yet.") | 51 net::DefineNetworkTrafficAnnotation("Undefined", "Nothing here yet.") |
| 41 | 52 |
| 53 #define MISSING_TRAFFIC_ANNOTATION \ |
| 54 net::DefineNetworkTrafficAnnotation( \ |
| 55 "Missing", "Function called without traffic annotation.") |
| 42 #endif // NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ | 56 #endif // NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ |
| OLD | NEW |