| 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 "chrome/browser/prefs/pref_hash_calculator.h" | 5 #include "chrome/browser/prefs/pref_hash_calculator.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "crypto/hmac.h" | 15 #include "crypto/hmac.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Renders |value| as a string. |value| may be NULL, in which case the result | 19 // Renders |value| as a string. |value| may be NULL, in which case the result |
| 20 // is an empty string. | 20 // is an empty string. |
| 21 std::string ValueAsString(const base::Value* value) { | 21 std::string ValueAsString(const base::Value* value) { |
| 22 // Dictionary values may contain empty lists and sub-dictionaries. Make a | 22 // Dictionary values may contain empty lists and sub-dictionaries. Make a |
| 23 // deep copy with those removed to make the hash more stable. | 23 // deep copy with those removed to make the hash more stable. |
| 24 const base::DictionaryValue* dict_value; | 24 const base::DictionaryValue* dict_value; |
| 25 scoped_ptr<DictionaryValue> canonical_dict_value; | 25 scoped_ptr<base::DictionaryValue> canonical_dict_value; |
| 26 if (value && value->GetAsDictionary(&dict_value)) { | 26 if (value && value->GetAsDictionary(&dict_value)) { |
| 27 canonical_dict_value.reset(dict_value->DeepCopyWithoutEmptyChildren()); | 27 canonical_dict_value.reset(dict_value->DeepCopyWithoutEmptyChildren()); |
| 28 value = canonical_dict_value.get(); | 28 value = canonical_dict_value.get(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 std::string value_as_string; | 31 std::string value_as_string; |
| 32 if (value) { | 32 if (value) { |
| 33 JSONStringValueSerializer serializer(&value_as_string); | 33 JSONStringValueSerializer serializer(&value_as_string); |
| 34 serializer.Serialize(*value); | 34 serializer.Serialize(*value); |
| 35 } | 35 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 return VALID_LEGACY; | 81 return VALID_LEGACY; |
| 82 return INVALID; | 82 return INVALID; |
| 83 } | 83 } |
| 84 | 84 |
| 85 std::string PrefHashCalculator::CalculateLegacyHash( | 85 std::string PrefHashCalculator::CalculateLegacyHash( |
| 86 const std::string& path, const base::Value* value) const { | 86 const std::string& path, const base::Value* value) const { |
| 87 return CalculateFromValueAndComponents(seed_, | 87 return CalculateFromValueAndComponents(seed_, |
| 88 value, | 88 value, |
| 89 std::vector<std::string>()); | 89 std::vector<std::string>()); |
| 90 } | 90 } |
| OLD | NEW |