| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/password_manager/sync/browser/password_model_worker.h" | 5 #include "components/password_manager/sync/browser/password_model_worker.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/callback.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "components/password_manager/core/browser/password_store.h" | 10 #include "components/password_manager/core/browser/password_store.h" |
| 11 #include "components/sync/base/scoped_event_signal.h" | 11 #include "components/sync/base/scoped_event_signal.h" |
| 12 | 12 |
| 13 namespace browser_sync { | 13 namespace browser_sync { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 void CallDoWorkAndSignalEvent(const syncer::WorkCallback& work, | 17 void CallDoWorkAndSignalEvent(const syncer::WorkCallback& work, |
| 18 syncer::ScopedEventSignal scoped_event_signal, | 18 syncer::ScopedEventSignal scoped_event_signal, |
| 19 syncer::SyncerError* error_info) { | 19 syncer::SyncerError* error_info) { |
| 20 *error_info = work.Run(); | 20 *error_info = work.Run(); |
| 21 // The event in |scoped_event_signal| is signaled at the end of this scope. | 21 // The event in |scoped_event_signal| is signaled at the end of this scope. |
| 22 } | 22 } |
| 23 | 23 |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 PasswordModelWorker::PasswordModelWorker( | 26 PasswordModelWorker::PasswordModelWorker( |
| 27 const scoped_refptr<password_manager::PasswordStore>& password_store, | 27 const scoped_refptr<password_manager::PasswordStore>& password_store) |
| 28 syncer::WorkerLoopDestructionObserver* observer) | 28 : password_store_(password_store) { |
| 29 : syncer::ModelSafeWorker(observer), password_store_(password_store) { | |
| 30 DCHECK(password_store.get()); | 29 DCHECK(password_store.get()); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void PasswordModelWorker::RegisterForLoopDestruction() { | |
| 34 base::AutoLock lock(password_store_lock_); | |
| 35 password_store_->ScheduleTask(base::Bind( | |
| 36 &PasswordModelWorker::RegisterForPasswordLoopDestruction, this)); | |
| 37 } | |
| 38 | |
| 39 syncer::SyncerError PasswordModelWorker::DoWorkAndWaitUntilDoneImpl( | 32 syncer::SyncerError PasswordModelWorker::DoWorkAndWaitUntilDoneImpl( |
| 40 const syncer::WorkCallback& work) { | 33 const syncer::WorkCallback& work) { |
| 41 syncer::SyncerError error = syncer::UNSET; | 34 syncer::SyncerError error = syncer::UNSET; |
| 42 | 35 |
| 43 // Signaled when the task is deleted, i.e. after it runs or when it is | 36 // Signaled when the task is deleted, i.e. after it runs or when it is |
| 44 // abandoned. | 37 // abandoned. |
| 45 base::WaitableEvent work_done_or_abandoned( | 38 base::WaitableEvent work_done_or_abandoned( |
| 46 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 39 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 47 base::WaitableEvent::InitialState::NOT_SIGNALED); | 40 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 48 | 41 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 64 error = syncer::CANNOT_DO_WORK; | 57 error = syncer::CANNOT_DO_WORK; |
| 65 return error; | 58 return error; |
| 66 } | 59 } |
| 67 | 60 |
| 68 syncer::ModelSafeGroup PasswordModelWorker::GetModelSafeGroup() { | 61 syncer::ModelSafeGroup PasswordModelWorker::GetModelSafeGroup() { |
| 69 return syncer::GROUP_PASSWORD; | 62 return syncer::GROUP_PASSWORD; |
| 70 } | 63 } |
| 71 | 64 |
| 72 PasswordModelWorker::~PasswordModelWorker() {} | 65 PasswordModelWorker::~PasswordModelWorker() {} |
| 73 | 66 |
| 74 void PasswordModelWorker::RegisterForPasswordLoopDestruction() { | |
| 75 SetWorkingLoopToCurrent(); | |
| 76 } | |
| 77 | |
| 78 void PasswordModelWorker::RequestStop() { | 67 void PasswordModelWorker::RequestStop() { |
| 79 ModelSafeWorker::RequestStop(); | 68 ModelSafeWorker::RequestStop(); |
| 80 | 69 |
| 81 base::AutoLock lock(password_store_lock_); | 70 base::AutoLock lock(password_store_lock_); |
| 82 password_store_ = NULL; | 71 password_store_ = NULL; |
| 83 } | 72 } |
| 84 | 73 |
| 85 } // namespace browser_sync | 74 } // namespace browser_sync |
| OLD | NEW |