Skip to content

Commit

Permalink
Adopt OnceCallback in ModelTypeStore
Browse files Browse the repository at this point in the history
Trivial change, no behavioral differences.

Bug: 681921
Change-Id: Id512b11a574afcf902d35553bb10a1a85cbcdea7
Reviewed-on: https://chromium-review.googlesource.com/940134
Reviewed-by: Sean Kau <skau@chromium.org>
Reviewed-by: Marc Treib <treib@chromium.org>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: Pavel Yatsuk <pavely@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540790}
  • Loading branch information
Mikel Astiz authored and Commit Bot committed Mar 5, 2018
1 parent 5a4aa3b commit 5f07ce2
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/printing/printers_sync_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void PrintersSyncBridge::GetData(StorageKeyList storage_keys,
}
}
}
callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

void PrintersSyncBridge::GetAllData(DataCallback callback) {
Expand All @@ -263,7 +263,7 @@ void PrintersSyncBridge::GetAllData(DataCallback callback) {
batch->Put(entry.first, CopyToEntityData(*entry.second));
}
}
callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

std::string PrintersSyncBridge::GetClientTag(const EntityData& entity_data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void AutocompleteSyncBridge::AutocompleteSyncBridge::GetData(
batch->Put(key, CreateEntityData(entry));
}
}
callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

void AutocompleteSyncBridge::GetAllData(DataCallback callback) {
Expand All @@ -399,7 +399,7 @@ void AutocompleteSyncBridge::GetAllData(DataCallback callback) {
for (const AutofillEntry& entry : entries) {
batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry));
}
callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

void AutocompleteSyncBridge::ActOnLocalChanges(
Expand Down
4 changes: 2 additions & 2 deletions components/history/core/browser/typed_url_sync_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void TypedURLSyncBridge::GetData(StorageKeyList storage_keys,
batch->Put(key, std::move(entity_data));
}

callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

void TypedURLSyncBridge::GetAllData(DataCallback callback) {
Expand Down Expand Up @@ -318,7 +318,7 @@ void TypedURLSyncBridge::GetAllData(DataCallback callback) {
batch->Put(GetStorageKeyFromURLRow(url), std::move(entity_data));
}

callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

// Must be exactly the value of GURL::spec() for backwards comparability with
Expand Down
4 changes: 2 additions & 2 deletions components/reading_list/core/reading_list_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void ReadingListStore::GetData(StorageKeyList storage_keys,
}
}

callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

void ReadingListStore::GetAllData(DataCallback callback) {
Expand All @@ -379,7 +379,7 @@ void ReadingListStore::GetAllData(DataCallback callback) {
AddEntryToBatch(batch.get(), *entry);
}

callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

void ReadingListStore::AddEntryToBatch(syncer::MutableDataBatch* batch,
Expand Down
4 changes: 2 additions & 2 deletions components/sync/device_info/device_info_sync_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ void DeviceInfoSyncBridge::GetData(StorageKeyList storage_keys,
batch->Put(key, CopyToEntityData(*iter->second));
}
}
callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

void DeviceInfoSyncBridge::GetAllData(DataCallback callback) {
auto batch = std::make_unique<MutableDataBatch>();
for (const auto& kv : all_data_) {
batch->Put(kv.first, CopyToEntityData(*kv.second));
}
callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

std::string DeviceInfoSyncBridge::GetClientTag(const EntityData& entity_data) {
Expand Down
4 changes: 2 additions & 2 deletions components/sync/model/fake_model_type_sync_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void FakeModelTypeSyncBridge::GetData(StorageKeyList keys,
DCHECK(db_->HasData(key)) << "No data for " << key;
batch->Put(key, CopyEntityData(db_->GetData(key)));
}
callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

void FakeModelTypeSyncBridge::GetAllData(DataCallback callback) {
Expand All @@ -328,7 +328,7 @@ void FakeModelTypeSyncBridge::GetAllData(DataCallback callback) {
for (const auto& kv : db_->all_data()) {
batch->Put(kv.first, CopyEntityData(*kv.second));
}
callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

std::string FakeModelTypeSyncBridge::GetClientTag(
Expand Down
2 changes: 1 addition & 1 deletion components/sync/model/model_type_sync_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MetadataChangeList;
// ReportError() method should be called instead of ModelReadyToSync().
class ModelTypeSyncBridge : public base::SupportsWeakPtr<ModelTypeSyncBridge> {
public:
using DataCallback = base::Callback<void(std::unique_ptr<DataBatch>)>;
using DataCallback = base::OnceCallback<void(std::unique_ptr<DataBatch>)>;
using StorageKeyList = std::vector<std::string>;
using ChangeProcessorFactory = base::RepeatingCallback<std::unique_ptr<
ModelTypeChangeProcessor>(ModelType type, ModelTypeSyncBridge* bridge)>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class TestModelTypeSyncBridge : public FakeModelTypeSyncBridge {

void OnPendingCommitDataLoaded() {
ASSERT_TRUE(data_callback_);
data_callback_.Run();
data_callback_.Reset();
std::move(data_callback_).Run();
}

void InitializeToReadyState() {
Expand Down Expand Up @@ -133,19 +132,19 @@ class TestModelTypeSyncBridge : public FakeModelTypeSyncBridge {
void GetData(StorageKeyList keys, DataCallback callback) override {
if (synchronous_data_callback_) {
synchronous_data_callback_ = false;
FakeModelTypeSyncBridge::GetData(keys, callback);
FakeModelTypeSyncBridge::GetData(keys, std::move(callback));
} else {
FakeModelTypeSyncBridge::GetData(
keys, base::Bind(&TestModelTypeSyncBridge::CaptureDataCallback,
base::Unretained(this), callback));
keys, base::BindOnce(&TestModelTypeSyncBridge::CaptureDataCallback,
base::Unretained(this), std::move(callback)));
}
}

private:
void CaptureDataCallback(DataCallback callback,
std::unique_ptr<DataBatch> data) {
EXPECT_FALSE(data_callback_);
data_callback_ = base::Bind(callback, base::Passed(std::move(data)));
data_callback_ = base::BindOnce(std::move(callback), std::move(data));
}

// The number of times MergeSyncData has been called.
Expand All @@ -154,7 +153,7 @@ class TestModelTypeSyncBridge : public FakeModelTypeSyncBridge {
int get_storage_key_call_count_ = 0;

// Stores the data callback between GetData() and OnPendingCommitDataLoaded().
base::Closure data_callback_;
base::OnceClosure data_callback_;

// Whether to return GetData results synchronously. Overrides the default
// callback capture behavior if set to true.
Expand Down
18 changes: 10 additions & 8 deletions components/sync/user_events/user_event_sync_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ base::Optional<ModelError> UserEventSyncBridge::ApplySyncChanges(

void UserEventSyncBridge::GetData(StorageKeyList storage_keys,
DataCallback callback) {
store_->ReadData(storage_keys, base::Bind(&UserEventSyncBridge::OnReadData,
base::AsWeakPtr(this), callback));
store_->ReadData(storage_keys,
base::BindOnce(&UserEventSyncBridge::OnReadData,
base::AsWeakPtr(this), std::move(callback)));
}

void UserEventSyncBridge::GetAllData(DataCallback callback) {
store_->ReadAllData(base::Bind(&UserEventSyncBridge::OnReadAllData,
base::AsWeakPtr(this), callback));
store_->ReadAllData(base::BindOnce(&UserEventSyncBridge::OnReadAllData,
base::AsWeakPtr(this),
std::move(callback)));
}

std::string UserEventSyncBridge::GetClientTag(const EntityData& entity_data) {
Expand All @@ -144,8 +146,8 @@ std::string UserEventSyncBridge::GetStorageKey(const EntityData& entity_data) {

void UserEventSyncBridge::DisableSync() {
// No data should be retained through sign out.
store_->ReadAllData(base::Bind(&UserEventSyncBridge::OnReadAllDataToDelete,
base::AsWeakPtr(this)));
store_->ReadAllData(base::BindOnce(
&UserEventSyncBridge::OnReadAllDataToDelete, base::AsWeakPtr(this)));
}

void UserEventSyncBridge::RecordUserEvent(
Expand Down Expand Up @@ -234,7 +236,7 @@ void UserEventSyncBridge::OnReadData(DataCallback callback,
const base::Optional<ModelError>& error,
std::unique_ptr<RecordList> data_records,
std::unique_ptr<IdList> missing_id_list) {
OnReadAllData(callback, error, std::move(data_records));
OnReadAllData(std::move(callback), error, std::move(data_records));
}

void UserEventSyncBridge::OnReadAllData(
Expand All @@ -258,7 +260,7 @@ void UserEventSyncBridge::OnReadAllData(
return;
}
}
callback.Run(std::move(batch));
std::move(callback).Run(std::move(batch));
}

void UserEventSyncBridge::OnReadAllDataToDelete(
Expand Down

0 comments on commit 5f07ce2

Please sign in to comment.