1 // Copyright 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 "components/sync_driver/glue/browser_thread_model_worker.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/synchronization/waitable_event.h"
11 using base::SingleThreadTaskRunner
;
12 using base::WaitableEvent
;
14 namespace browser_sync
{
16 BrowserThreadModelWorker::BrowserThreadModelWorker(
17 const scoped_refptr
<SingleThreadTaskRunner
>& runner
,
18 syncer::ModelSafeGroup group
,
19 syncer::WorkerLoopDestructionObserver
* observer
)
20 : ModelSafeWorker(observer
), runner_(runner
), group_(group
) {}
22 syncer::SyncerError
BrowserThreadModelWorker::DoWorkAndWaitUntilDoneImpl(
23 const syncer::WorkCallback
& work
) {
24 syncer::SyncerError error
= syncer::UNSET
;
25 if (runner_
->BelongsToCurrentThread()) {
26 DLOG(WARNING
) << "Already on thread " << runner_
;
30 if (!runner_
->PostTask(
32 base::Bind(&BrowserThreadModelWorker::CallDoWorkAndSignalTask
, this,
33 work
, work_done_or_stopped(), &error
))) {
34 DLOG(WARNING
) << "Failed to post task to runner " << runner_
;
35 error
= syncer::CANNOT_DO_WORK
;
38 work_done_or_stopped()->Wait();
42 syncer::ModelSafeGroup
BrowserThreadModelWorker::GetModelSafeGroup() {
46 BrowserThreadModelWorker::~BrowserThreadModelWorker() {}
48 void BrowserThreadModelWorker::RegisterForLoopDestruction() {
49 if (runner_
->BelongsToCurrentThread()) {
50 SetWorkingLoopToCurrent();
54 Bind(&BrowserThreadModelWorker::RegisterForLoopDestruction
, this));
58 void BrowserThreadModelWorker::CallDoWorkAndSignalTask(
59 const syncer::WorkCallback
& work
,
61 syncer::SyncerError
* error
) {
62 DCHECK(runner_
->BelongsToCurrentThread());
68 } // namespace browser_sync