Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: net/traffic_annotation/network_traffic_annotation.h

Issue 2893233002: Network traffic annotation added to URLLoaderImpl. (Closed)
Patch Set: All comments addressed. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/network/url_loader_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 namespace { 10 namespace {
(...skipping 20 matching lines...) Expand all
31 31
32 namespace net { 32 namespace net {
33 33
34 // Defined types for network traffic annotation tags. 34 // Defined types for network traffic annotation tags.
35 struct NetworkTrafficAnnotationTag { 35 struct NetworkTrafficAnnotationTag {
36 const int32_t unique_id_hash_code; 36 const int32_t unique_id_hash_code;
37 }; 37 };
38 struct PartialNetworkTrafficAnnotationTag { 38 struct PartialNetworkTrafficAnnotationTag {
39 const int32_t unique_id_hash_code; 39 const int32_t unique_id_hash_code;
40 40
41 #if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON) 41 #ifndef NDEBUG
jochen (gone - plz use gerrit) 2017/06/12 08:34:25 can you keep the DCHECK_ALWAYS_ON check? i.e. !de
Ramin Halavati 2017/06/12 09:04:55 Done.
42 // |completing_id_hash_code| holds a reference to the hash coded unique id 42 // |completing_id_hash_code| holds a reference to the hash coded unique id
43 // of a network traffic annotation (or group id of several network traffic 43 // of a network traffic annotation (or group id of several network traffic
44 // annotations) that complete a partial network annotation. Please refer to 44 // annotations) that complete a partial network annotation. Please refer to
45 // the description of DefinePartialNetworkTrafficAnnotation function for more 45 // the description of DefinePartialNetworkTrafficAnnotation function for more
46 // details. 46 // details.
47 // This value is used by the clang tools to find linkage between partial 47 // This value is used by the clang tools to find linkage between partial
48 // annotations and their completing parts, and is used in debug mode to check 48 // annotations and their completing parts, and is used in debug mode to check
49 // if an intended completing part is added to a partial network annotation. 49 // if an intended completing part is added to a partial network annotation.
50 const int32_t completing_id_hash_code; 50 const int32_t completing_id_hash_code;
51 #endif 51 #endif
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // 'BranchedCompleteNetworkTrafficAnnotation' functions. In case of 90 // 'BranchedCompleteNetworkTrafficAnnotation' functions. In case of
91 // CompleteNetworkTrafficAnnotation, |completing_id| is the unique id of the 91 // CompleteNetworkTrafficAnnotation, |completing_id| is the unique id of the
92 // annotation that will complete it. In the case of 92 // annotation that will complete it. In the case of
93 // BranchedCompleteNetworkTrafficAnnotation, |completing_id| is the group id 93 // BranchedCompleteNetworkTrafficAnnotation, |completing_id| is the group id
94 // of the completing annotations. 94 // of the completing annotations.
95 template <size_t N1, size_t N2, size_t N3> 95 template <size_t N1, size_t N2, size_t N3>
96 constexpr PartialNetworkTrafficAnnotationTag 96 constexpr PartialNetworkTrafficAnnotationTag
97 DefinePartialNetworkTrafficAnnotation(const char (&unique_id)[N1], 97 DefinePartialNetworkTrafficAnnotation(const char (&unique_id)[N1],
98 const char (&completing_id)[N2], 98 const char (&completing_id)[N2],
99 const char (&proto)[N3]) { 99 const char (&proto)[N3]) {
100 #if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON) 100 #ifndef NDEBUG
101 return PartialNetworkTrafficAnnotationTag( 101 return PartialNetworkTrafficAnnotationTag(
102 {COMPUTE_STRING_HASH(unique_id), COMPUTE_STRING_HASH(completing_id)}); 102 {COMPUTE_STRING_HASH(unique_id), COMPUTE_STRING_HASH(completing_id)});
103 #else 103 #else
104 return PartialNetworkTrafficAnnotationTag({COMPUTE_STRING_HASH(unique_id)}); 104 return PartialNetworkTrafficAnnotationTag({COMPUTE_STRING_HASH(unique_id)});
105 #endif 105 #endif
106 } 106 }
107 107
108 // This function can be used to define a completing partial annotation. This 108 // This function can be used to define a completing partial annotation. This
109 // annotation adds details to another annotation that is defined before. 109 // annotation adds details to another annotation that is defined before.
110 // |partial_annotation| is the PartialNetworkTrafficAnnotationTag returned 110 // |partial_annotation| is the PartialNetworkTrafficAnnotationTag returned
111 // by a call to DefinePartialNetworkTrafficAnnotation(). 111 // by a call to DefinePartialNetworkTrafficAnnotation().
112 template <size_t N1, size_t N2> 112 template <size_t N1, size_t N2>
113 NetworkTrafficAnnotationTag CompleteNetworkTrafficAnnotation( 113 NetworkTrafficAnnotationTag CompleteNetworkTrafficAnnotation(
114 const char (&unique_id)[N1], 114 const char (&unique_id)[N1],
115 const PartialNetworkTrafficAnnotationTag& partial_annotation, 115 const PartialNetworkTrafficAnnotationTag& partial_annotation,
116 const char (&proto)[N2]) { 116 const char (&proto)[N2]) {
117 #if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON) 117 #ifndef NDEBUG
118 DCHECK(partial_annotation.completing_id_hash_code == 118 DCHECK(partial_annotation.completing_id_hash_code ==
119 COMPUTE_STRING_HASH(unique_id) || 119 COMPUTE_STRING_HASH(unique_id) ||
120 partial_annotation.unique_id_hash_code == 120 partial_annotation.unique_id_hash_code ==
121 COMPUTE_STRING_HASH("test_partial") || 121 COMPUTE_STRING_HASH("test_partial") ||
122 partial_annotation.unique_id_hash_code == 122 partial_annotation.unique_id_hash_code ==
123 COMPUTE_STRING_HASH("undefined")); 123 COMPUTE_STRING_HASH("undefined"));
124 #endif 124 #endif
125 return NetworkTrafficAnnotationTag({partial_annotation.unique_id_hash_code}); 125 return NetworkTrafficAnnotationTag({partial_annotation.unique_id_hash_code});
126 } 126 }
127 127
128 // This function can be used to define a completing partial annotation that is 128 // This function can be used to define a completing partial annotation that is
129 // branched into several annotations. In this case, |group_id| is a common id 129 // branched into several annotations. In this case, |group_id| is a common id
130 // that is used by all members of the branch and referenced by partial 130 // that is used by all members of the branch and referenced by partial
131 // annotation that is completed by them. 131 // annotation that is completed by them.
132 template <size_t N1, size_t N2, size_t N3> 132 template <size_t N1, size_t N2, size_t N3>
133 NetworkTrafficAnnotationTag BranchedCompleteNetworkTrafficAnnotation( 133 NetworkTrafficAnnotationTag BranchedCompleteNetworkTrafficAnnotation(
134 const char (&unique_id)[N1], 134 const char (&unique_id)[N1],
135 const char (&group_id)[N2], 135 const char (&group_id)[N2],
136 const PartialNetworkTrafficAnnotationTag& partial_annotation, 136 const PartialNetworkTrafficAnnotationTag& partial_annotation,
137 const char (&proto)[N3]) { 137 const char (&proto)[N3]) {
138 #if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON) 138 #ifndef NDEBUG
139 DCHECK(partial_annotation.completing_id_hash_code == 139 DCHECK(partial_annotation.completing_id_hash_code ==
140 COMPUTE_STRING_HASH(unique_id) || 140 COMPUTE_STRING_HASH(unique_id) ||
141 partial_annotation.unique_id_hash_code == 141 partial_annotation.unique_id_hash_code ==
142 COMPUTE_STRING_HASH("test_partial") || 142 COMPUTE_STRING_HASH("test_partial") ||
143 partial_annotation.unique_id_hash_code == 143 partial_annotation.unique_id_hash_code ==
144 COMPUTE_STRING_HASH("undefined")); 144 COMPUTE_STRING_HASH("undefined"));
145 #endif 145 #endif
146 return NetworkTrafficAnnotationTag({COMPUTE_STRING_HASH(unique_id)}); 146 return NetworkTrafficAnnotationTag({COMPUTE_STRING_HASH(unique_id)});
147 } 147 }
148 148
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // // final_tag is hash code of "call_bool_branch_1". 187 // // final_tag is hash code of "call_bool_branch_1".
188 // net::URLFetcher::Create(url1, ..., final_tag); 188 // net::URLFetcher::Create(url1, ..., final_tag);
189 // } else { 189 // } else {
190 // auto final_tag = BranchedCompleteNetworkTrafficAnnotation( 190 // auto final_tag = BranchedCompleteNetworkTrafficAnnotation(
191 // "call_bool_branch_2", "completion_by_bar", tag, [rest_of_proto]); 191 // "call_bool_branch_2", "completion_by_bar", tag, [rest_of_proto]);
192 // // final_tag is hash code of "call_bool_branch_2". 192 // // final_tag is hash code of "call_bool_branch_2".
193 // net::URLFetcher::Create(url2, ..., final_tag); 193 // net::URLFetcher::Create(url2, ..., final_tag);
194 // } 194 // }
195 // } 195 // }
196 196
197 #define TRAFFIC_ANNOTATION_UNINITIALIZED -1
198
199 // Do not use this unless net-serialization is required.
200 // TODO(crbug.com/690323): Add tools to check constructor of this structure is
201 // used only in .mojom.cc files.
202 struct MutableNetworkTrafficAnnotationTag {
203 MutableNetworkTrafficAnnotationTag()
204 : unique_id_hash_code(TRAFFIC_ANNOTATION_UNINITIALIZED) {}
205 explicit MutableNetworkTrafficAnnotationTag(
206 const NetworkTrafficAnnotationTag& traffic_annotation)
207 : unique_id_hash_code(traffic_annotation.unique_id_hash_code) {}
208
209 int32_t unique_id_hash_code;
210
211 explicit operator NetworkTrafficAnnotationTag() const {
212 return NetworkTrafficAnnotationTag({unique_id_hash_code});
213 }
214 };
215
216 struct MutablePartialNetworkTrafficAnnotationTag {
217 #ifndef NDEBUG
218 MutablePartialNetworkTrafficAnnotationTag()
219 : unique_id_hash_code(TRAFFIC_ANNOTATION_UNINITIALIZED),
220 completing_id_hash_code(TRAFFIC_ANNOTATION_UNINITIALIZED) {}
221 explicit MutablePartialNetworkTrafficAnnotationTag(
222 const PartialNetworkTrafficAnnotationTag& partial_traffic_annotation)
223 : unique_id_hash_code(partial_traffic_annotation.unique_id_hash_code),
224 completing_id_hash_code(
225 partial_traffic_annotation.completing_id_hash_code) {}
226
227 int32_t unique_id_hash_code;
228 int32_t completing_id_hash_code;
229
230 explicit operator PartialNetworkTrafficAnnotationTag() const {
231 return PartialNetworkTrafficAnnotationTag(
232 {unique_id_hash_code, completing_id_hash_code});
233 }
234 #else
235 MutablePartialNetworkTrafficAnnotationTag()
236 : unique_id_hash_code(TRAFFIC_ANNOTATION_UNINITIALIZED) {}
237 explicit MutablePartialNetworkTrafficAnnotationTag(
238 const PartialNetworkTrafficAnnotationTag& partial_traffic_annotation)
239 : unique_id_hash_code(partial_traffic_annotation.unique_id_hash_code) {}
240
241 int32_t unique_id_hash_code;
242
243 explicit operator PartialNetworkTrafficAnnotationTag() const {
244 return PartialNetworkTrafficAnnotationTag({unique_id_hash_code});
245 }
246 #endif // NDEBUG
247 };
248
197 } // namespace net 249 } // namespace net
198 250
199 // Placeholder for unannotated usages. 251 // Placeholder for unannotated usages.
200 #define NO_TRAFFIC_ANNOTATION_YET \ 252 #define NO_TRAFFIC_ANNOTATION_YET \
201 net::DefineNetworkTrafficAnnotation("undefined", "Nothing here yet.") 253 net::DefineNetworkTrafficAnnotation("undefined", "Nothing here yet.")
202 254
203 #define NO_PARTIAL_TRAFFIC_ANNOTATION_YET \ 255 #define NO_PARTIAL_TRAFFIC_ANNOTATION_YET \
204 net::DefinePartialNetworkTrafficAnnotation("undefined", "undefined", \ 256 net::DefinePartialNetworkTrafficAnnotation("undefined", "undefined", \
205 "Nothing here yet.") 257 "Nothing here yet.")
206 258
207 #define MISSING_TRAFFIC_ANNOTATION \ 259 #define MISSING_TRAFFIC_ANNOTATION \
208 net::DefineNetworkTrafficAnnotation( \ 260 net::DefineNetworkTrafficAnnotation( \
209 "missing", "Function called without traffic annotation.") 261 "missing", "Function called without traffic annotation.")
210 262
211 #undef COMPUTE_STRING_HASH 263 #undef COMPUTE_STRING_HASH
212 264
213 #endif // NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_ 265 #endif // NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_
OLDNEW
« no previous file with comments | « content/network/url_loader_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698