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 3a25bbc6742fcdb39300bca0e025eed5c5570213..40a979621e9010d5023b1b6af4a0cb4f3b2a975f 100644 |
--- a/components/user_prefs/tracked/pref_hash_store_impl.cc |
+++ b/components/user_prefs/tracked/pref_hash_store_impl.cc |
@@ -10,7 +10,6 @@ |
#include "base/logging.h" |
#include "base/macros.h" |
#include "base/metrics/histogram.h" |
-#include "base/values.h" |
gab
2016/09/01 21:21:56
Keep this now that it's only fwd-decl'ed in header
proberge
2016/09/06 18:43:39
Done.
|
#include "components/user_prefs/tracked/hash_store_contents.h" |
#include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
@@ -64,6 +63,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, |
std::unique_ptr<HashStoreContents> storage) |
@@ -89,8 +117,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 +157,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 +233,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; |