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

Unified Diff: net/traffic_annotation/network_traffic_annotation.h

Issue 2866183003: Syntax and coverage checking added to Network Traffic Annotations. (Closed)
Patch Set: Protobuf build updated. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
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
index 989f4f348300272732063cee88ea1da2ed9c8b6f..1b074e94b85774208fbd26f8faa10f3e3c103b5f 100644
--- a/net/traffic_annotation/network_traffic_annotation.h
+++ b/net/traffic_annotation/network_traffic_annotation.h
@@ -8,7 +8,14 @@
namespace net {
// Defined type for network traffic annotation tags.
+#if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON)
+struct NetworkTrafficAnnotationTag {
+ const char* const unique_id;
+ const char* const proto;
+};
+#else
using NetworkTrafficAnnotationTag = const char* const;
+#endif
// Function to convert a network traffic annotation's unique id and protobuf
// text into a NetworkTrafficAnnotationTag.
@@ -26,11 +33,15 @@ using NetworkTrafficAnnotationTag = const char* const;
// //tools/traffic_annotation/sample_traffic_annotation.cc.
// TODO(crbug.com/690323): Add tools to check annotation text's format during
// presubmit checks.
-template <size_t N1, size_t N2>
+template <unsigned N1, unsigned N2>
constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation(
const char (&unique_id)[N1],
const char (&proto)[N2]) {
+#if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON)
+ return NetworkTrafficAnnotationTag({unique_id, proto});
+#else
return unique_id;
+#endif
}
} // namespace net
@@ -39,4 +50,7 @@ constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation(
#define NO_TRAFFIC_ANNOTATION_YET \
net::DefineNetworkTrafficAnnotation("Undefined", "Nothing here yet.")
+#define MISSING_TRAFFIC_ANNOTATION \
+ net::DefineNetworkTrafficAnnotation( \
+ "Missing", "Function called without traffic annotation.")
#endif // NET_TRAFFIC_ANNOTATION_NETWORK_TRAFFIC_ANNOTATION_H_
« no previous file with comments | « chrome/browser/net/traffic_annotation/network_traffic_annotation_checker.cc ('k') | net/url_request/url_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698