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/browser_thread_model_worker.h"
8 #include "base/synchronization/waitable_event.h"
9 #include "content/public/browser/browser_thread.h"
11 using base::WaitableEvent
;
12 using content::BrowserThread
;
14 namespace browser_sync
{
16 BrowserThreadModelWorker::BrowserThreadModelWorker(
17 BrowserThread::ID thread
, syncer::ModelSafeGroup group
,
18 syncer::WorkerLoopDestructionObserver
* observer
)
19 : ModelSafeWorker(observer
),
20 thread_(thread
), group_(group
) {
23 syncer::SyncerError
BrowserThreadModelWorker::DoWorkAndWaitUntilDoneImpl(
24 const syncer::WorkCallback
& work
) {
25 syncer::SyncerError error
= syncer::UNSET
;
26 if (BrowserThread::CurrentlyOn(thread_
)) {
27 DLOG(WARNING
) << "Already on thread " << thread_
;
31 if (!BrowserThread::PostTask(
34 base::Bind(&BrowserThreadModelWorker::CallDoWorkAndSignalTask
,
36 work_done_or_stopped(), &error
))) {
37 DLOG(WARNING
) << "Failed to post task to thread " << thread_
;
38 error
= syncer::CANNOT_DO_WORK
;
41 work_done_or_stopped()->Wait();
45 syncer::ModelSafeGroup
BrowserThreadModelWorker::GetModelSafeGroup() {
49 BrowserThreadModelWorker::~BrowserThreadModelWorker() {}
51 void BrowserThreadModelWorker::RegisterForLoopDestruction() {
52 if (BrowserThread::CurrentlyOn(thread_
)) {
53 SetWorkingLoopToCurrent();
55 BrowserThread::PostTask(
57 Bind(&BrowserThreadModelWorker::RegisterForLoopDestruction
, this));
61 void BrowserThreadModelWorker::CallDoWorkAndSignalTask(
62 const syncer::WorkCallback
& work
,
64 syncer::SyncerError
* error
) {
65 DCHECK_CURRENTLY_ON(thread_
);
71 DatabaseModelWorker::DatabaseModelWorker(
72 syncer::WorkerLoopDestructionObserver
* observer
)
73 : BrowserThreadModelWorker(BrowserThread::DB
, syncer::GROUP_DB
, observer
) {
76 void DatabaseModelWorker::CallDoWorkAndSignalTask(
77 const syncer::WorkCallback
& work
,
79 syncer::SyncerError
* error
) {
80 BrowserThreadModelWorker::CallDoWorkAndSignalTask(work
, done
, error
);
83 DatabaseModelWorker::~DatabaseModelWorker() {}
85 FileModelWorker::FileModelWorker(
86 syncer::WorkerLoopDestructionObserver
* observer
)
87 : BrowserThreadModelWorker(BrowserThread::FILE, syncer::GROUP_FILE
,
91 void FileModelWorker::CallDoWorkAndSignalTask(
92 const syncer::WorkCallback
& work
,
94 syncer::SyncerError
* error
) {
95 BrowserThreadModelWorker::CallDoWorkAndSignalTask(work
, done
, error
);
98 FileModelWorker::~FileModelWorker() {}
100 } // namespace browser_sync