1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/password_manager/sync/browser/password_model_worker.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/synchronization/waitable_event.h"
10 #include "components/password_manager/core/browser/password_store.h"
12 using base::WaitableEvent
;
14 namespace browser_sync
{
16 PasswordModelWorker::PasswordModelWorker(
17 const scoped_refptr
<password_manager::PasswordStore
>& password_store
,
18 syncer::WorkerLoopDestructionObserver
* observer
)
19 : syncer::ModelSafeWorker(observer
), password_store_(password_store
) {
20 DCHECK(password_store
.get());
23 void PasswordModelWorker::RegisterForLoopDestruction() {
24 base::AutoLock
lock(password_store_lock_
);
25 password_store_
->ScheduleTask(base::Bind(
26 &PasswordModelWorker::RegisterForPasswordLoopDestruction
, this));
29 syncer::SyncerError
PasswordModelWorker::DoWorkAndWaitUntilDoneImpl(
30 const syncer::WorkCallback
& work
) {
31 syncer::SyncerError error
= syncer::UNSET
;
33 bool scheduled
= false;
35 base::AutoLock
lock(password_store_lock_
);
36 if (!password_store_
.get())
37 return syncer::CANNOT_DO_WORK
;
39 scheduled
= password_store_
->ScheduleTask(
40 base::Bind(&PasswordModelWorker::CallDoWorkAndSignalTask
, this, work
,
41 work_done_or_stopped(), &error
));
45 work_done_or_stopped()->Wait();
47 error
= syncer::CANNOT_DO_WORK
;
51 syncer::ModelSafeGroup
PasswordModelWorker::GetModelSafeGroup() {
52 return syncer::GROUP_PASSWORD
;
55 PasswordModelWorker::~PasswordModelWorker() {}
57 void PasswordModelWorker::CallDoWorkAndSignalTask(
58 const syncer::WorkCallback
& work
,
60 syncer::SyncerError
* error
) {
65 void PasswordModelWorker::RegisterForPasswordLoopDestruction() {
66 SetWorkingLoopToCurrent();
69 void PasswordModelWorker::RequestStop() {
70 ModelSafeWorker::RequestStop();
72 base::AutoLock
lock(password_store_lock_
);
73 password_store_
= NULL
;
76 } // namespace browser_sync