Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / sync / glue / password_model_worker.cc
blob17ba62ee2d24f596530aa1aa481ac1e455bbe0f7
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"
7 #include "base/bind.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,
27 this));
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));
45 if (scheduled)
46 work_done_or_stopped()->Wait();
47 else
48 error = syncer::CANNOT_DO_WORK;
49 return error;
52 syncer::ModelSafeGroup PasswordModelWorker::GetModelSafeGroup() {
53 return syncer::GROUP_PASSWORD;
56 PasswordModelWorker::~PasswordModelWorker() {}
58 void PasswordModelWorker::CallDoWorkAndSignalTask(
59 const syncer::WorkCallback& work,
60 WaitableEvent* done,
61 syncer::SyncerError *error) {
62 *error = work.Run();
63 done->Signal();
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