1 // Copyright (c) 2012 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 "chrome/browser/sync/glue/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(
26 base::Bind(&PasswordModelWorker::RegisterForPasswordLoopDestruction
,
30 syncer::SyncerError
PasswordModelWorker::DoWorkAndWaitUntilDoneImpl(
31 const syncer::WorkCallback
& work
) {
32 syncer::SyncerError error
= syncer::UNSET
;
34 bool scheduled
= false;
36 base::AutoLock
lock(password_store_lock_
);
37 if (!password_store_
.get())
38 return syncer::CANNOT_DO_WORK
;
40 scheduled
= password_store_
->ScheduleTask(
41 base::Bind(&PasswordModelWorker::CallDoWorkAndSignalTask
,
42 this, work
, work_done_or_stopped(), &error
));
46 work_done_or_stopped()->Wait();
48 error
= syncer::CANNOT_DO_WORK
;
52 syncer::ModelSafeGroup
PasswordModelWorker::GetModelSafeGroup() {
53 return syncer::GROUP_PASSWORD
;
56 PasswordModelWorker::~PasswordModelWorker() {}
58 void PasswordModelWorker::CallDoWorkAndSignalTask(
59 const syncer::WorkCallback
& work
,
61 syncer::SyncerError
*error
) {
66 void PasswordModelWorker::RegisterForPasswordLoopDestruction() {
67 SetWorkingLoopToCurrent();
70 void PasswordModelWorker::RequestStop() {
71 ModelSafeWorker::RequestStop();
73 base::AutoLock
lock(password_store_lock_
);
74 password_store_
= NULL
;
77 } // namespace browser_sync