OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
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 constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation( | |
42 const char* unique_id, | |
43 const char* proto) { | |
44 return (NetworkTrafficAnnotationTag)unique_id; | |
45 } | |
46 | |
47 // Placeholder for unannotated usages. | |
48 #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.
| |
49 net::DefineNetworkTrafficAnnotation("Undefined", "Nothing here yet.") | |
50 | |
51 // Macro for unit tests traffic annotations. | |
52 #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.
| |
53 net::DefineNetworkTrafficAnnotation( \ | |
54 "UnitTest", "Traffic annotation for unit, browser and other tests") | |
55 | |
56 } // namespace net | |
57 | |
58 #endif // NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ | |
OLD | NEW |