Commit 9164d24b authored by proberge's avatar proberge Committed by Commit bot

Refactor PrefHashStore's BeginTransaction to take a rawptr

To support a new HashStoreContents which needs to be passed around in
a different manner, the PrefHashStoreTransaction now has a raw ptr
instead of owning the HashStoreContents.

BUG=624858

Review-Url: https://codereview.chromium.org/2297373002
Cr-Commit-Position: refs/heads/master@{#417023}
parent 6326fc6e
...@@ -132,9 +132,9 @@ void PrefHashFilter::ClearResetTime(PrefService* user_prefs) { ...@@ -132,9 +132,9 @@ void PrefHashFilter::ClearResetTime(PrefService* user_prefs) {
} }
void PrefHashFilter::Initialize(base::DictionaryValue* pref_store_contents) { void PrefHashFilter::Initialize(base::DictionaryValue* pref_store_contents) {
DictionaryHashStoreContents dictionary_contents(pref_store_contents);
std::unique_ptr<PrefHashStoreTransaction> hash_store_transaction( std::unique_ptr<PrefHashStoreTransaction> hash_store_transaction(
pref_hash_store_->BeginTransaction(std::unique_ptr<HashStoreContents>( pref_hash_store_->BeginTransaction(&dictionary_contents));
new DictionaryHashStoreContents(pref_store_contents))));
for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin(); for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin();
it != tracked_paths_.end(); ++it) { it != tracked_paths_.end(); ++it) {
const std::string& initialized_path = it->first; const std::string& initialized_path = it->first;
...@@ -161,9 +161,9 @@ void PrefHashFilter::FilterSerializeData( ...@@ -161,9 +161,9 @@ void PrefHashFilter::FilterSerializeData(
if (!changed_paths_.empty()) { if (!changed_paths_.empty()) {
base::TimeTicks checkpoint = base::TimeTicks::Now(); base::TimeTicks checkpoint = base::TimeTicks::Now();
{ {
DictionaryHashStoreContents dictionary_contents(pref_store_contents);
std::unique_ptr<PrefHashStoreTransaction> hash_store_transaction( std::unique_ptr<PrefHashStoreTransaction> hash_store_transaction(
pref_hash_store_->BeginTransaction(std::unique_ptr<HashStoreContents>( pref_hash_store_->BeginTransaction(&dictionary_contents));
new DictionaryHashStoreContents(pref_store_contents))));
for (ChangedPathsMap::const_iterator it = changed_paths_.begin(); for (ChangedPathsMap::const_iterator it = changed_paths_.begin();
it != changed_paths_.end(); ++it) { it != changed_paths_.end(); ++it) {
const std::string& changed_path = it->first; const std::string& changed_path = it->first;
...@@ -191,9 +191,9 @@ void PrefHashFilter::FinalizeFilterOnLoad( ...@@ -191,9 +191,9 @@ void PrefHashFilter::FinalizeFilterOnLoad(
bool did_reset = false; bool did_reset = false;
{ {
DictionaryHashStoreContents dictionary_contents(pref_store_contents.get());
std::unique_ptr<PrefHashStoreTransaction> hash_store_transaction( std::unique_ptr<PrefHashStoreTransaction> hash_store_transaction(
pref_hash_store_->BeginTransaction(std::unique_ptr<HashStoreContents>( pref_hash_store_->BeginTransaction(&dictionary_contents));
new DictionaryHashStoreContents(pref_store_contents.get()))));
CleanupDeprecatedTrackedPreferences( CleanupDeprecatedTrackedPreferences(
pref_store_contents.get(), hash_store_transaction.get()); pref_store_contents.get(), hash_store_transaction.get());
......
...@@ -157,7 +157,7 @@ class MockPrefHashStore : public PrefHashStore { ...@@ -157,7 +157,7 @@ class MockPrefHashStore : public PrefHashStore {
// PrefHashStore implementation. // PrefHashStore implementation.
std::unique_ptr<PrefHashStoreTransaction> BeginTransaction( std::unique_ptr<PrefHashStoreTransaction> BeginTransaction(
std::unique_ptr<HashStoreContents> storage) override; HashStoreContents* storage) override;
private: private:
// A MockPrefHashStoreTransaction is handed to the caller on // A MockPrefHashStoreTransaction is handed to the caller on
...@@ -247,7 +247,7 @@ void MockPrefHashStore::SetInvalidKeysResult( ...@@ -247,7 +247,7 @@ void MockPrefHashStore::SetInvalidKeysResult(
} }
std::unique_ptr<PrefHashStoreTransaction> MockPrefHashStore::BeginTransaction( std::unique_ptr<PrefHashStoreTransaction> MockPrefHashStore::BeginTransaction(
std::unique_ptr<HashStoreContents> storage) { HashStoreContents* storage) {
EXPECT_FALSE(transaction_active_); EXPECT_FALSE(transaction_active_);
return std::unique_ptr<PrefHashStoreTransaction>( return std::unique_ptr<PrefHashStoreTransaction>(
new MockPrefHashStoreTransaction(this)); new MockPrefHashStoreTransaction(this));
......
...@@ -21,8 +21,9 @@ class PrefHashStore { ...@@ -21,8 +21,9 @@ class PrefHashStore {
// of operations on the hash store. |storage| MAY be used as the backing store // of operations on the hash store. |storage| MAY be used as the backing store
// depending on the implementation. Therefore the HashStoreContents used for // depending on the implementation. Therefore the HashStoreContents used for
// related transactions should correspond to the same underlying data store. // related transactions should correspond to the same underlying data store.
// |storage| must outlive the returned transaction.
virtual std::unique_ptr<PrefHashStoreTransaction> BeginTransaction( virtual std::unique_ptr<PrefHashStoreTransaction> BeginTransaction(
std::unique_ptr<HashStoreContents> storage) = 0; HashStoreContents* storage) = 0;
}; };
#endif // COMPONENTS_PREFS_TRACKED_PREF_HASH_STORE_H_ #endif // COMPONENTS_PREFS_TRACKED_PREF_HASH_STORE_H_
...@@ -20,7 +20,7 @@ class PrefHashStoreImpl::PrefHashStoreTransactionImpl ...@@ -20,7 +20,7 @@ class PrefHashStoreImpl::PrefHashStoreTransactionImpl
// Constructs a PrefHashStoreTransactionImpl which can use the private // Constructs a PrefHashStoreTransactionImpl which can use the private
// members of its |outer| PrefHashStoreImpl. // members of its |outer| PrefHashStoreImpl.
PrefHashStoreTransactionImpl(PrefHashStoreImpl* outer, PrefHashStoreTransactionImpl(PrefHashStoreImpl* outer,
std::unique_ptr<HashStoreContents> storage); HashStoreContents* storage);
~PrefHashStoreTransactionImpl() override; ~PrefHashStoreTransactionImpl() override;
// PrefHashStoreTransaction implementation. // PrefHashStoreTransaction implementation.
...@@ -41,7 +41,7 @@ class PrefHashStoreImpl::PrefHashStoreTransactionImpl ...@@ -41,7 +41,7 @@ class PrefHashStoreImpl::PrefHashStoreTransactionImpl
private: private:
PrefHashStoreImpl* outer_; PrefHashStoreImpl* outer_;
std::unique_ptr<HashStoreContents> contents_; HashStoreContents* contents_;
bool super_mac_valid_; bool super_mac_valid_;
bool super_mac_dirty_; bool super_mac_dirty_;
...@@ -59,14 +59,14 @@ PrefHashStoreImpl::~PrefHashStoreImpl() { ...@@ -59,14 +59,14 @@ PrefHashStoreImpl::~PrefHashStoreImpl() {
} }
std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction( std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction(
std::unique_ptr<HashStoreContents> storage) { HashStoreContents* storage) {
return std::unique_ptr<PrefHashStoreTransaction>( return std::unique_ptr<PrefHashStoreTransaction>(
new PrefHashStoreTransactionImpl(this, std::move(storage))); new PrefHashStoreTransactionImpl(this, std::move(storage)));
} }
PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl( PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl(
PrefHashStoreImpl* outer, PrefHashStoreImpl* outer,
std::unique_ptr<HashStoreContents> storage) HashStoreContents* storage)
: outer_(outer), : outer_(outer),
contents_(std::move(storage)), contents_(std::move(storage)),
super_mac_valid_(false), super_mac_valid_(false),
......
...@@ -47,7 +47,7 @@ class PrefHashStoreImpl : public PrefHashStore { ...@@ -47,7 +47,7 @@ class PrefHashStoreImpl : public PrefHashStore {
// PrefHashStore implementation. // PrefHashStore implementation.
std::unique_ptr<PrefHashStoreTransaction> BeginTransaction( std::unique_ptr<PrefHashStoreTransaction> BeginTransaction(
std::unique_ptr<HashStoreContents> storage) override; HashStoreContents* storage) override;
private: private:
class PrefHashStoreTransactionImpl; class PrefHashStoreTransactionImpl;
......
...@@ -120,10 +120,9 @@ void ScheduleSourcePrefStoreCleanup( ...@@ -120,10 +120,9 @@ void ScheduleSourcePrefStoreCleanup(
void CleanupMigratedHashes(const std::set<std::string>& migrated_pref_names, void CleanupMigratedHashes(const std::set<std::string>& migrated_pref_names,
PrefHashStore* origin_pref_hash_store, PrefHashStore* origin_pref_hash_store,
base::DictionaryValue* origin_pref_store) { base::DictionaryValue* origin_pref_store) {
DictionaryHashStoreContents dictionary_contents(origin_pref_store);
std::unique_ptr<PrefHashStoreTransaction> transaction( std::unique_ptr<PrefHashStoreTransaction> transaction(
origin_pref_hash_store->BeginTransaction( origin_pref_hash_store->BeginTransaction(&dictionary_contents));
std::unique_ptr<HashStoreContents>(
new DictionaryHashStoreContents(origin_pref_store))));
for (std::set<std::string>::const_iterator it = migrated_pref_names.begin(); for (std::set<std::string>::const_iterator it = migrated_pref_names.begin();
it != migrated_pref_names.end(); it != migrated_pref_names.end();
++it) { ++it) {
...@@ -143,9 +142,9 @@ void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names, ...@@ -143,9 +142,9 @@ void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names,
bool* new_store_altered) { bool* new_store_altered) {
const base::DictionaryValue* old_hash_store_contents = const base::DictionaryValue* old_hash_store_contents =
DictionaryHashStoreContents(old_store).GetContents(); DictionaryHashStoreContents(old_store).GetContents();
DictionaryHashStoreContents dictionary_contents(new_store);
std::unique_ptr<PrefHashStoreTransaction> new_hash_store_transaction( std::unique_ptr<PrefHashStoreTransaction> new_hash_store_transaction(
new_hash_store->BeginTransaction(std::unique_ptr<HashStoreContents>( new_hash_store->BeginTransaction(&dictionary_contents));
new DictionaryHashStoreContents(new_store))));
for (std::set<std::string>::const_iterator it = pref_names.begin(); for (std::set<std::string>::const_iterator it = pref_names.begin();
it != pref_names.end(); it != pref_names.end();
......
...@@ -162,10 +162,8 @@ class TrackedPreferencesMigrationTest : public testing::Test { ...@@ -162,10 +162,8 @@ class TrackedPreferencesMigrationTest : public testing::Test {
DCHECK(store); DCHECK(store);
base::StringValue string_value(value); base::StringValue string_value(value);
pref_hash_store DictionaryHashStoreContents contents(store);
->BeginTransaction(std::unique_ptr<HashStoreContents>( pref_hash_store->BeginTransaction(&contents)->StoreHash(key, &string_value);
new DictionaryHashStoreContents(store)))
->StoreHash(key, &string_value);
} }
// Returns true if the store opposite to |store_id| is observed for its next // Returns true if the store opposite to |store_id| is observed for its next
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment