| Index: components/user_prefs/tracked/pref_hash_store_impl.cc
|
| diff --git a/components/user_prefs/tracked/pref_hash_store_impl.cc b/components/user_prefs/tracked/pref_hash_store_impl.cc
|
| index 43b262b6907d60172948bd9f272e7b879364fe1a..7dd51c759f54931b258899d06c439bf15a6ec8d1 100644
|
| --- a/components/user_prefs/tracked/pref_hash_store_impl.cc
|
| +++ b/components/user_prefs/tracked/pref_hash_store_impl.cc
|
| @@ -10,9 +10,7 @@
|
| #include "base/logging.h"
|
| #include "base/macros.h"
|
| #include "base/metrics/histogram.h"
|
| -#include "base/values.h"
|
| #include "components/user_prefs/tracked/hash_store_contents.h"
|
| -#include "components/user_prefs/tracked/pref_hash_store_transaction.h"
|
|
|
| class PrefHashStoreImpl::PrefHashStoreTransactionImpl
|
| : public PrefHashStoreTransaction {
|
| @@ -64,6 +62,35 @@ std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction(
|
| new PrefHashStoreTransactionImpl(this, std::move(storage)));
|
| }
|
|
|
| +std::string PrefHashStoreImpl::ComputeMac(const std::string& path,
|
| + const base::Value* value) {
|
| + return pref_hash_calculator_.Calculate(path, value);
|
| +}
|
| +
|
| +std::unique_ptr<base::DictionaryValue> PrefHashStoreImpl::ComputeSplitMacs(
|
| + const std::string& path,
|
| + const base::DictionaryValue* split_values) {
|
| + DCHECK(split_values);
|
| +
|
| + std::string keyed_path(path);
|
| + keyed_path.push_back('.');
|
| + const size_t common_part_length = keyed_path.length();
|
| +
|
| + std::unique_ptr<base::DictionaryValue> split_macs(new base::DictionaryValue);
|
| +
|
| + for (base::DictionaryValue::Iterator it(*split_values); !it.IsAtEnd();
|
| + it.Advance()) {
|
| + // Keep the common part from the old |keyed_path| and replace the key to
|
| + // get the new |keyed_path|.
|
| + keyed_path.replace(common_part_length, std::string::npos, it.key());
|
| +
|
| + split_macs->SetStringWithoutPathExpansion(
|
| + it.key(), ComputeMac(keyed_path, &it.value()));
|
| + }
|
| +
|
| + return split_macs;
|
| +}
|
| +
|
| PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl(
|
| PrefHashStoreImpl* outer,
|
| HashStoreContents* storage)
|
| @@ -89,8 +116,7 @@ PrefHashStoreImpl::PrefHashStoreTransactionImpl::
|
| if (super_mac_dirty_ && outer_->use_super_mac_) {
|
| // Get the dictionary of hashes (or NULL if it doesn't exist).
|
| const base::DictionaryValue* hashes_dict = contents_->GetContents();
|
| - contents_->SetSuperMac(
|
| - outer_->pref_hash_calculator_.Calculate("", hashes_dict));
|
| + contents_->SetSuperMac(outer_->ComputeMac("", hashes_dict));
|
| }
|
| }
|
|
|
| @@ -130,8 +156,7 @@ PrefHashStoreImpl::PrefHashStoreTransactionImpl::CheckValue(
|
| void PrefHashStoreImpl::PrefHashStoreTransactionImpl::StoreHash(
|
| const std::string& path,
|
| const base::Value* new_value) {
|
| - const std::string mac =
|
| - outer_->pref_hash_calculator_.Calculate(path, new_value);
|
| + const std::string mac = outer_->ComputeMac(path, new_value);
|
| contents_->SetMac(path, mac);
|
| super_mac_dirty_ = true;
|
| }
|
| @@ -207,17 +232,16 @@ void PrefHashStoreImpl::PrefHashStoreTransactionImpl::StoreSplitHash(
|
| contents_->RemoveEntry(path);
|
|
|
| if (split_value) {
|
| - std::string keyed_path(path);
|
| - keyed_path.push_back('.');
|
| - const size_t common_part_length = keyed_path.length();
|
| - for (base::DictionaryValue::Iterator it(*split_value); !it.IsAtEnd();
|
| + std::unique_ptr<base::DictionaryValue> split_macs =
|
| + outer_->ComputeSplitMacs(path, split_value);
|
| +
|
| + for (base::DictionaryValue::Iterator it(*split_macs); !it.IsAtEnd();
|
| it.Advance()) {
|
| - // Keep the common part from the old |keyed_path| and replace the key to
|
| - // get the new |keyed_path|.
|
| - keyed_path.replace(common_part_length, std::string::npos, it.key());
|
| - contents_->SetSplitMac(
|
| - path, it.key(),
|
| - outer_->pref_hash_calculator_.Calculate(keyed_path, &it.value()));
|
| + const base::StringValue* value_as_string;
|
| + bool is_string = it.value().GetAsString(&value_as_string);
|
| + DCHECK(is_string);
|
| +
|
| + contents_->SetSplitMac(path, it.key(), value_as_string->GetString());
|
| }
|
| }
|
| super_mac_dirty_ = true;
|
|
|