This source file includes following definitions.
- CallDoWorkAndSignalCallback
- RegisterForLoopDestruction
- DoWorkAndWaitUntilDoneImpl
- GetModelSafeGroup
#include "chrome/browser/sync/glue/ui_model_worker.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/message_loop/message_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/thread_restrictions.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
namespace browser_sync {
namespace {
void CallDoWorkAndSignalCallback(const syncer::WorkCallback& work,
base::WaitableEvent* work_done,
syncer::SyncerError* error_info) {
if (work.is_null()) {
return;
}
*error_info = work.Run();
work_done->Signal();
}
}
UIModelWorker::UIModelWorker(syncer::WorkerLoopDestructionObserver* observer)
: syncer::ModelSafeWorker(observer) {
}
void UIModelWorker::RegisterForLoopDestruction() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::MessageLoop::current()->AddDestructionObserver(this);
SetWorkingLoopToCurrent();
}
syncer::SyncerError UIModelWorker::DoWorkAndWaitUntilDoneImpl(
const syncer::WorkCallback& work) {
syncer::SyncerError error_info;
if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
DLOG(WARNING) << "DoWorkAndWaitUntilDone called from "
<< "ui_loop_. Probably a nested invocation?";
return work.Run();
}
if (!BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&CallDoWorkAndSignalCallback,
work, work_done_or_stopped(), &error_info))) {
DLOG(WARNING) << "Could not post work to UI loop.";
error_info = syncer::CANNOT_DO_WORK;
return error_info;
}
work_done_or_stopped()->Wait();
return error_info;
}
syncer::ModelSafeGroup UIModelWorker::GetModelSafeGroup() {
return syncer::GROUP_UI;
}
UIModelWorker::~UIModelWorker() {
}
}