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) {
}
void PrefHashFilter::Initialize(base::DictionaryValue* pref_store_contents) {
DictionaryHashStoreContents dictionary_contents(pref_store_contents);
std::unique_ptr<PrefHashStoreTransaction> hash_store_transaction(
pref_hash_store_->BeginTransaction(std::unique_ptr<HashStoreContents>(
new DictionaryHashStoreContents(pref_store_contents))));
pref_hash_store_->BeginTransaction(&dictionary_contents));
for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin();
it != tracked_paths_.end(); ++it) {
const std::string& initialized_path = it->first;
......@@ -161,9 +161,9 @@ void PrefHashFilter::FilterSerializeData(
if (!changed_paths_.empty()) {
base::TimeTicks checkpoint = base::TimeTicks::Now();
{
DictionaryHashStoreContents dictionary_contents(pref_store_contents);
std::unique_ptr<PrefHashStoreTransaction> hash_store_transaction(
pref_hash_store_->BeginTransaction(std::unique_ptr<HashStoreContents>(
new DictionaryHashStoreContents(pref_store_contents))));
pref_hash_store_->BeginTransaction(&dictionary_contents));
for (ChangedPathsMap::const_iterator it = changed_paths_.begin();
it != changed_paths_.end(); ++it) {
const std::string& changed_path = it->first;
......@@ -191,9 +191,9 @@ void PrefHashFilter::FinalizeFilterOnLoad(
bool did_reset = false;
{
DictionaryHashStoreContents dictionary_contents(pref_store_contents.get());
std::unique_ptr<PrefHashStoreTransaction> hash_store_transaction(
pref_hash_store_->BeginTransaction(std::unique_ptr<HashStoreContents>(
new DictionaryHashStoreContents(pref_store_contents.get()))));
pref_hash_store_->BeginTransaction(&dictionary_contents));
CleanupDeprecatedTrackedPreferences(
pref_store_contents.get(), hash_store_transaction.get());
......
......@@ -157,7 +157,7 @@ class MockPrefHashStore : public PrefHashStore {
// PrefHashStore implementation.
std::unique_ptr<PrefHashStoreTransaction> BeginTransaction(
std::unique_ptr<HashStoreContents> storage) override;
HashStoreContents* storage) override;
private:
// A MockPrefHashStoreTransaction is handed to the caller on
......@@ -247,7 +247,7 @@ void MockPrefHashStore::SetInvalidKeysResult(
}
std::unique_ptr<PrefHashStoreTransaction> MockPrefHashStore::BeginTransaction(
std::unique_ptr<HashStoreContents> storage) {
HashStoreContents* storage) {
EXPECT_FALSE(transaction_active_);
return std::unique_ptr<PrefHashStoreTransaction>(
new MockPrefHashStoreTransaction(this));
......
......@@ -21,8 +21,9 @@ class PrefHashStore {
// of operations on the hash store. |storage| MAY be used as the backing store
// depending on the implementation. Therefore the HashStoreContents used for
// related transactions should correspond to the same underlying data store.
// |storage| must outlive the returned transaction.
virtual std::unique_ptr<PrefHashStoreTransaction> BeginTransaction(
std::unique_ptr<HashStoreContents> storage) = 0;
HashStoreContents* storage) = 0;
};
#endif // COMPONENTS_PREFS_TRACKED_PREF_HASH_STORE_H_
......@@ -20,7 +20,7 @@ class PrefHashStoreImpl::PrefHashStoreTransactionImpl
// Constructs a PrefHashStoreTransactionImpl which can use the private
// members of its |outer| PrefHashStoreImpl.
PrefHashStoreTransactionImpl(PrefHashStoreImpl* outer,
std::unique_ptr<HashStoreContents> storage);
HashStoreContents* storage);
~PrefHashStoreTransactionImpl() override;
// PrefHashStoreTransaction implementation.
......@@ -41,7 +41,7 @@ class PrefHashStoreImpl::PrefHashStoreTransactionImpl
private:
PrefHashStoreImpl* outer_;
std::unique_ptr<HashStoreContents> contents_;
HashStoreContents* contents_;
bool super_mac_valid_;
bool super_mac_dirty_;
......@@ -59,14 +59,14 @@ PrefHashStoreImpl::~PrefHashStoreImpl() {
}
std::unique_ptr<PrefHashStoreTransaction> PrefHashStoreImpl::BeginTransaction(
std::unique_ptr<HashStoreContents> storage) {
HashStoreContents* storage) {
return std::unique_ptr<PrefHashStoreTransaction>(
new PrefHashStoreTransactionImpl(this, std::move(storage)));
}
PrefHashStoreImpl::PrefHashStoreTransactionImpl::PrefHashStoreTransactionImpl(
PrefHashStoreImpl* outer,
std::unique_ptr<HashStoreContents> storage)
HashStoreContents* storage)
: outer_(outer),
contents_(std::move(storage)),
super_mac_valid_(false),
......
......@@ -47,7 +47,7 @@ class PrefHashStoreImpl : public PrefHashStore {
// PrefHashStore implementation.
std::unique_ptr<PrefHashStoreTransaction> BeginTransaction(
std::unique_ptr<HashStoreContents> storage) override;
HashStoreContents* storage) override;
private:
class PrefHashStoreTransactionImpl;
......
......@@ -120,10 +120,9 @@ void ScheduleSourcePrefStoreCleanup(
void CleanupMigratedHashes(const std::set<std::string>& migrated_pref_names,
PrefHashStore* origin_pref_hash_store,
base::DictionaryValue* origin_pref_store) {
DictionaryHashStoreContents dictionary_contents(origin_pref_store);
std::unique_ptr<PrefHashStoreTransaction> transaction(
origin_pref_hash_store->BeginTransaction(
std::unique_ptr<HashStoreContents>(
new DictionaryHashStoreContents(origin_pref_store))));
origin_pref_hash_store->BeginTransaction(&dictionary_contents));
for (std::set<std::string>::const_iterator it = migrated_pref_names.begin();
it != migrated_pref_names.end();
++it) {
......@@ -143,9 +142,9 @@ void MigratePrefsFromOldToNewStore(const std::set<std::string>& pref_names,
bool* new_store_altered) {
const base::DictionaryValue* old_hash_store_contents =
DictionaryHashStoreContents(old_store).GetContents();
DictionaryHashStoreContents dictionary_contents(new_store);
std::unique_ptr<PrefHashStoreTransaction> new_hash_store_transaction(
new_hash_store->BeginTransaction(std::unique_ptr<HashStoreContents>(
new DictionaryHashStoreContents(new_store))));
new_hash_store->BeginTransaction(&dictionary_contents));
for (std::set<std::string>::const_iterator it = pref_names.begin();
it != pref_names.end();
......
......@@ -162,10 +162,8 @@ class TrackedPreferencesMigrationTest : public testing::Test {
DCHECK(store);
base::StringValue string_value(value);
pref_hash_store
->BeginTransaction(std::unique_ptr<HashStoreContents>(
new DictionaryHashStoreContents(store)))
->StoreHash(key, &string_value);
DictionaryHashStoreContents contents(store);
pref_hash_store->BeginTransaction(&contents)->StoreHash(key, &string_value);
}
// 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