Index: net/traffic_annotation/network_traffic_annotation.h |
diff --git a/net/traffic_annotation/network_traffic_annotation.h b/net/traffic_annotation/network_traffic_annotation.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b959efdf104e02a5e105625dc0e8d618539832bf |
--- /dev/null |
+++ b/net/traffic_annotation/network_traffic_annotation.h |
@@ -0,0 +1,58 @@ |
+// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
please use gerrit instead
2017/02/01 22:10:20
No "(c)" and 2017.
Ramin Halavati
2017/02/02 07:44:24
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ |
+#define NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ |
+ |
+namespace net { |
+ |
+// Defined type for network traffic annotation tags. |
+using NetworkTrafficAnnotationTag = const char*; |
+ |
+// Function to convert a network traffic annotation's unique id and protobuf |
+// text into a NetworkTrafficAnnotationTag. |
+// |
+// This function serves as a tag that can be discovered and extracted via |
+// clang tools. This allows reviewing all network traffic that is generated |
+// and annotated by Chrome. |
+// |
+// |unique_id| should be a string that uniquely identifies this annotation |
+// across all of Chromium source code. |
+// |proto| is a text-encoded NetworkTrafficAnnotation protobuf (see |
+// tools/traffic_annotaiton/traffic_annotation.proto) |
+// |
+// This function should be called with inlined parameters like |
+// NetworkTrafficAnnotationTag tag = DefineNetworkTrafficAnnotation( |
+// "unique_tag_id", |
+// R"(semantics: {...} |
+// policy: {...} |
+// )"); |
+// This allows the compiler to extract the |unique_id| at compile time without |
+// copying the entire protobuf into the text segment of the binary or creating |
+// any runtime performance impact. |
+// |
+// Please do NOT use the following syntax: |
+// const char* proto = R("..."); |
+// NetworkTrafficAnnotationTag tag = DefineNetworkTrafficAnnotation( |
+// "unique_tag_id", proto); |
+// You can see a sample and an empty template for text-coded protobuf in |
+// (tools/traffic_annotation/sample_traffic_annotation.cc) |
+constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation( |
+ const char* unique_id, |
+ const char* proto) { |
+ return (NetworkTrafficAnnotationTag)unique_id; |
+} |
+ |
+// Placeholder for unannotated usages. |
+#define NO_TRAFFIC_ANNOTATION_YET \ |
please use gerrit instead
2017/02/01 22:10:20
I'd prefer to move this #define outside of the "ne
Ramin Halavati
2017/02/02 07:44:24
Done.
|
+ net::DefineNetworkTrafficAnnotation("Undefined", "Nothing here yet.") |
+ |
+// Macro for unit tests traffic annotations. |
+#define TRAFFIC_ANNOTATION_FOR_TESTS \ |
please use gerrit instead
2017/02/01 22:10:20
Nit: Would be nice to move to network_traffic_anno
Ramin Halavati
2017/02/02 07:44:24
Done.
|
+ net::DefineNetworkTrafficAnnotation( \ |
+ "UnitTest", "Traffic annotation for unit, browser and other tests") |
+ |
+} // namespace net |
+ |
+#endif // NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ |