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

Unified Diff: chrome/browser/net/traffic_annotation/network_traffic_annotation_checker.cc

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: chrome/browser/net/traffic_annotation/network_traffic_annotation_checker.cc
diff --git a/chrome/browser/net/traffic_annotation/network_traffic_annotation_checker.cc b/chrome/browser/net/traffic_annotation/network_traffic_annotation_checker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3d790a9fc51bd137cce632b4a55a3ea259899807
--- /dev/null
+++ b/chrome/browser/net/traffic_annotation/network_traffic_annotation_checker.cc
@@ -0,0 +1,49 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/net/traffic_annotation/network_traffic_annotation_checker.h"
+
+#include "base/logging.h"
+
+namespace {}
+
+NetworkTrafficAnnotationChecker::NetworkTrafficAnnotationChecker() {}
+
+NetworkTrafficAnnotationChecker::~NetworkTrafficAnnotationChecker() {}
+
+void NetworkTrafficAnnotationChecker::CheckAnnotation(
+ const net::NetworkTrafficAnnotationTag& traffic_annotation) {
+#if defined(_DEBUG) || defined(DCHECK_ALWAYS_ON)
+ if (visited_annotations_.find(traffic_annotation.unique_id) !=
+ visited_annotations_.end())
+ return;
+
+ bool syntax_checked = false;
+ // Check if unique_id/content pair is unique.
+ for (const auto& other_annotation : visited_annotations_) {
+ if (!strcmp(other_annotation.first, traffic_annotation.unique_id)) {
+ if (!strcmp(other_annotation.second, traffic_annotation.proto)) {
+ // For some reason, there are more than one copie of one pair.
+ DLOG(WARNING)
+ << "Traffic other_annotation comes from multiple sources: "
+ << traffic_annotation.unique_id;
+ syntax_checked = true;
+ break;
+ } else {
+ DLOG(ERROR)
+ << "Traffic other_annotation unique id with multiple protos: "
+ << traffic_annotation.unique_id;
+ }
+ }
+ }
+ // Check if content syntax is correct and complete.
+ if (!syntax_checked) {
+ // Proto stuff.
+ }
+
+ // Add it to the list.
+ visited_annotations_.insert(
+ std::make_pair(traffic_annotation.unique_id, traffic_annotation.proto));
+#endif
+}

Powered by Google App Engine
This is Rietveld 408576698