Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / sync / glue / browser_thread_model_worker.cc
blobf3faa34ff13a3232c23b9390c0af265023e198f6
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"
7 #include "base/bind.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_;
28 return work.Run();
31 if (!BrowserThread::PostTask(
32 thread_,
33 FROM_HERE,
34 base::Bind(&BrowserThreadModelWorker::CallDoWorkAndSignalTask,
35 this, work,
36 work_done_or_stopped(), &error))) {
37 DLOG(WARNING) << "Failed to post task to thread " << thread_;
38 error = syncer::CANNOT_DO_WORK;
39 return error;
41 work_done_or_stopped()->Wait();
42 return error;
45 syncer::ModelSafeGroup BrowserThreadModelWorker::GetModelSafeGroup() {
46 return group_;
49 BrowserThreadModelWorker::~BrowserThreadModelWorker() {}
51 void BrowserThreadModelWorker::RegisterForLoopDestruction() {
52 if (BrowserThread::CurrentlyOn(thread_)) {
53 SetWorkingLoopToCurrent();
54 } else {
55 BrowserThread::PostTask(
56 thread_, FROM_HERE,
57 Bind(&BrowserThreadModelWorker::RegisterForLoopDestruction, this));
61 void BrowserThreadModelWorker::CallDoWorkAndSignalTask(
62 const syncer::WorkCallback& work,
63 WaitableEvent* done,
64 syncer::SyncerError* error) {
65 DCHECK_CURRENTLY_ON(thread_);
66 if (!IsStopped())
67 *error = work.Run();
68 done->Signal();
71 DatabaseModelWorker::DatabaseModelWorker(
72 syncer::WorkerLoopDestructionObserver* observer)
73 : BrowserThreadModelWorker(BrowserThread::DB, syncer::GROUP_DB, observer) {
76 void DatabaseModelWorker::CallDoWorkAndSignalTask(
77 const syncer::WorkCallback& work,
78 WaitableEvent* done,
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,
88 observer) {
91 void FileModelWorker::CallDoWorkAndSignalTask(
92 const syncer::WorkCallback& work,
93 WaitableEvent* done,
94 syncer::SyncerError* error) {
95 BrowserThreadModelWorker::CallDoWorkAndSignalTask(work, done, error);
98 FileModelWorker::~FileModelWorker() {}
100 } // namespace browser_sync