Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Unified Diff: components/password_manager/sync/browser/password_model_worker.cc

Issue 2466313003: Remove ModelSafeWorker::work_done_or_stopped(). (Closed)
Patch Set: CR zea #11 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/password_manager/sync/browser/password_model_worker.h ('k') | components/sync/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/password_manager/sync/browser/password_model_worker.cc
diff --git a/components/password_manager/sync/browser/password_model_worker.cc b/components/password_manager/sync/browser/password_model_worker.cc
index 019ca85e9ceecfc1f501620265da837fa901c78b..e081ff17a7addf1e2b89552323752d5b7bfd5866 100644
--- a/components/password_manager/sync/browser/password_model_worker.cc
+++ b/components/password_manager/sync/browser/password_model_worker.cc
@@ -8,11 +8,21 @@
#include "base/memory/ref_counted.h"
#include "base/synchronization/waitable_event.h"
#include "components/password_manager/core/browser/password_store.h"
-
-using base::WaitableEvent;
+#include "components/sync/base/scoped_event_signal.h"
namespace browser_sync {
+namespace {
+
+void CallDoWorkAndSignalEvent(const syncer::WorkCallback& work,
+ syncer::ScopedEventSignal scoped_event_signal,
+ syncer::SyncerError* error_info) {
+ *error_info = work.Run();
+ // The event in |scoped_event_signal| is signaled at the end of this scope.
+}
+
+} // namespace
+
PasswordModelWorker::PasswordModelWorker(
const scoped_refptr<password_manager::PasswordStore>& password_store,
syncer::WorkerLoopDestructionObserver* observer)
@@ -30,19 +40,26 @@ syncer::SyncerError PasswordModelWorker::DoWorkAndWaitUntilDoneImpl(
const syncer::WorkCallback& work) {
syncer::SyncerError error = syncer::UNSET;
+ // Signaled when the task is deleted, i.e. after it runs or when it is
+ // abandoned.
+ base::WaitableEvent work_done_or_abandoned(
+ base::WaitableEvent::ResetPolicy::AUTOMATIC,
+ base::WaitableEvent::InitialState::NOT_SIGNALED);
+
bool scheduled = false;
{
base::AutoLock lock(password_store_lock_);
if (!password_store_.get())
return syncer::CANNOT_DO_WORK;
- scheduled = password_store_->ScheduleTask(
- base::Bind(&PasswordModelWorker::CallDoWorkAndSignalTask, this, work,
- work_done_or_stopped(), &error));
+ scheduled = password_store_->ScheduleTask(base::Bind(
+ &CallDoWorkAndSignalEvent, work,
+ base::Passed(syncer::ScopedEventSignal(&work_done_or_abandoned)),
+ &error));
}
if (scheduled)
- work_done_or_stopped()->Wait();
+ work_done_or_abandoned.Wait();
else
error = syncer::CANNOT_DO_WORK;
return error;
@@ -54,14 +71,6 @@ syncer::ModelSafeGroup PasswordModelWorker::GetModelSafeGroup() {
PasswordModelWorker::~PasswordModelWorker() {}
-void PasswordModelWorker::CallDoWorkAndSignalTask(
- const syncer::WorkCallback& work,
- WaitableEvent* done,
- syncer::SyncerError* error) {
- *error = work.Run();
- done->Signal();
-}
-
void PasswordModelWorker::RegisterForPasswordLoopDestruction() {
SetWorkingLoopToCurrent();
}
« no previous file with comments | « components/password_manager/sync/browser/password_model_worker.h ('k') | components/sync/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698