| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "components/user_prefs/tracked/pref_hash_calculator.h" | 5 #include "components/user_prefs/tracked/pref_hash_calculator.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 const std::string& path, | 72 const std::string& path, |
| 73 const std::string& value_as_string) { | 73 const std::string& value_as_string) { |
| 74 std::string message; | 74 std::string message; |
| 75 message.reserve(device_id.size() + path.size() + value_as_string.size()); | 75 message.reserve(device_id.size() + path.size() + value_as_string.size()); |
| 76 message.append(device_id); | 76 message.append(device_id); |
| 77 message.append(path); | 77 message.append(path); |
| 78 message.append(value_as_string); | 78 message.append(value_as_string); |
| 79 return message; | 79 return message; |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Generates a device ID based on the input device ID. The derived device ID has | |
| 83 // no useful properties beyond those of the input device ID except that it is | |
| 84 // consistent with previous implementations. | |
| 85 // TODO(gab): Remove this once UMA reports for | |
| 86 // Settings.TrackedPreferenceMigratedLegacyDeviceId become insignificant. | |
| 87 std::string GenerateDeviceIdLikePrefMetricsServiceDid( | |
| 88 const std::string& original_device_id) { | |
| 89 if (original_device_id.empty()) | |
| 90 return std::string(); | |
| 91 return base::ToLowerASCII( | |
| 92 GetDigestString(original_device_id, "PrefMetricsService")); | |
| 93 } | |
| 94 | |
| 95 } // namespace | 82 } // namespace |
| 96 | 83 |
| 97 PrefHashCalculator::PrefHashCalculator(const std::string& seed, | 84 PrefHashCalculator::PrefHashCalculator(const std::string& seed, |
| 98 const std::string& device_id) | 85 const std::string& device_id, |
| 99 : seed_(seed), | 86 const std::string& legacy_device_id) |
| 100 device_id_(device_id), | 87 : seed_(seed), device_id_(device_id), legacy_device_id_(legacy_device_id) {} |
| 101 legacy_device_id_(GenerateDeviceIdLikePrefMetricsServiceDid(device_id)) { | |
| 102 } | |
| 103 | 88 |
| 104 PrefHashCalculator::~PrefHashCalculator() { | 89 PrefHashCalculator::~PrefHashCalculator() { |
| 105 } | 90 } |
| 106 | 91 |
| 107 std::string PrefHashCalculator::Calculate(const std::string& path, | 92 std::string PrefHashCalculator::Calculate(const std::string& path, |
| 108 const base::Value* value) const { | 93 const base::Value* value) const { |
| 109 return GetDigestString(seed_, | 94 return GetDigestString(seed_, |
| 110 GetMessage(device_id_, path, ValueAsString(value))); | 95 GetMessage(device_id_, path, ValueAsString(value))); |
| 111 } | 96 } |
| 112 | 97 |
| 113 PrefHashCalculator::ValidationResult PrefHashCalculator::Validate( | 98 PrefHashCalculator::ValidationResult PrefHashCalculator::Validate( |
| 114 const std::string& path, | 99 const std::string& path, |
| 115 const base::Value* value, | 100 const base::Value* value, |
| 116 const std::string& digest_string) const { | 101 const std::string& digest_string) const { |
| 117 const std::string value_as_string(ValueAsString(value)); | 102 const std::string value_as_string(ValueAsString(value)); |
| 118 if (VerifyDigestString(seed_, GetMessage(device_id_, path, value_as_string), | 103 if (VerifyDigestString(seed_, GetMessage(device_id_, path, value_as_string), |
| 119 digest_string)) { | 104 digest_string)) { |
| 120 return VALID; | 105 return VALID; |
| 121 } | 106 } |
| 122 if (VerifyDigestString(seed_, | 107 if (VerifyDigestString(seed_, |
| 123 GetMessage(legacy_device_id_, path, value_as_string), | 108 GetMessage(legacy_device_id_, path, value_as_string), |
| 124 digest_string)) { | 109 digest_string)) { |
| 125 return VALID_SECURE_LEGACY; | 110 return VALID_SECURE_LEGACY; |
| 126 } | 111 } |
| 127 return INVALID; | 112 return INVALID; |
| 128 } | 113 } |
| OLD | NEW |