Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: components/sync_driver/glue/browser_thread_model_worker.cc

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/sync_driver/glue/browser_thread_model_worker.h"
6
7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/synchronization/waitable_event.h"
10
11 using base::SingleThreadTaskRunner;
12 using base::WaitableEvent;
13
14 namespace browser_sync {
15
16 BrowserThreadModelWorker::BrowserThreadModelWorker(
17 const scoped_refptr<SingleThreadTaskRunner>& runner,
18 syncer::ModelSafeGroup group,
19 syncer::WorkerLoopDestructionObserver* observer)
20 : ModelSafeWorker(observer), runner_(runner), group_(group) {}
21
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_;
27 return work.Run();
28 }
29
30 if (!runner_->PostTask(
31 FROM_HERE,
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;
36 return error;
37 }
38 work_done_or_stopped()->Wait();
39 return error;
40 }
41
42 syncer::ModelSafeGroup BrowserThreadModelWorker::GetModelSafeGroup() {
43 return group_;
44 }
45
46 BrowserThreadModelWorker::~BrowserThreadModelWorker() {}
47
48 void BrowserThreadModelWorker::RegisterForLoopDestruction() {
49 if (runner_->BelongsToCurrentThread()) {
50 SetWorkingLoopToCurrent();
51 } else {
52 runner_->PostTask(
53 FROM_HERE,
54 Bind(&BrowserThreadModelWorker::RegisterForLoopDestruction, this));
55 }
56 }
57
58 void BrowserThreadModelWorker::CallDoWorkAndSignalTask(
59 const syncer::WorkCallback& work,
60 WaitableEvent* done,
61 syncer::SyncerError* error) {
62 DCHECK(runner_->BelongsToCurrentThread());
63 if (!IsStopped())
64 *error = work.Run();
65 done->Signal();
66 }
67
68 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698