Index: chrome/browser/safe_browsing/tracked_preference_incident_handlers.cc |
diff --git a/chrome/browser/safe_browsing/tracked_preference_incident_handlers.cc b/chrome/browser/safe_browsing/tracked_preference_incident_handlers.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3c86b2d71476caa763b5bf4987c1294fa284f099 |
--- /dev/null |
+++ b/chrome/browser/safe_browsing/tracked_preference_incident_handlers.cc |
@@ -0,0 +1,46 @@ |
+// Copyright 2014 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/safe_browsing/tracked_preference_incident_handlers.h" |
+ |
+#include "base/logging.h" |
+#include "chrome/browser/safe_browsing/incident_handler_util.h" |
+#include "chrome/common/safe_browsing/csd.pb.h" |
+ |
+namespace safe_browsing { |
+ |
+std::string GetTrackedPreferenceIncidentKey( |
+ const ClientIncidentReport_IncidentData& incident_data) { |
+ DCHECK(incident_data.has_tracked_preference()); |
+ DCHECK(incident_data.tracked_preference().has_path()); |
+ return incident_data.tracked_preference().path(); |
+} |
+ |
+uint32_t GetTrackedPreferenceIncidentDigest( |
+ const ClientIncidentReport_IncidentData& incident_data) { |
+ DCHECK(incident_data.has_tracked_preference()); |
+ |
+ // Make a canonical representation of the incident's payload over which a hash |
+ // digest is computed. |
+ const ClientIncidentReport_IncidentData_TrackedPreferenceIncident& input = |
+ incident_data.tracked_preference(); |
+ ClientIncidentReport_IncidentData_TrackedPreferenceIncident incident; |
+ |
+ if (input.has_path() && !input.path().empty()) |
+ incident.set_path(input.path()); |
+ if (input.has_atomic_value() && !input.atomic_value().empty()) { |
+ incident.set_atomic_value(input.atomic_value()); |
+ } else { |
+ for (int i = 0; i < input.split_key_size(); ++i) { |
+ if (!input.split_key(i).empty()) |
+ incident.add_split_key(input.split_key(i)); |
+ } |
+ } |
+ if (input.has_value_state()) |
+ incident.set_value_state(input.value_state()); |
+ |
+ return HashMessage(incident); |
+} |
+ |
+} // namespace safe_browsing |