2011-12-23 18:36:30 +01:00
|
|
|
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "include/cef_task.h"
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/cef_thread.h"
|
2012-02-17 15:51:20 +01:00
|
|
|
#include "base/bind.h"
|
2011-12-23 18:36:30 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
int GetThreadId(CefThreadId threadId) {
|
|
|
|
switch (threadId) {
|
2011-12-23 18:36:30 +01:00
|
|
|
case TID_UI: return CefThread::UI;
|
|
|
|
case TID_IO: return CefThread::IO;
|
|
|
|
case TID_FILE: return CefThread::FILE;
|
|
|
|
};
|
|
|
|
NOTREACHED();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
} // namespace
|
2011-12-23 18:36:30 +01:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefCurrentlyOn(CefThreadId threadId) {
|
2011-12-23 18:36:30 +01:00
|
|
|
int id = GetThreadId(threadId);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (id < 0)
|
2011-12-23 18:36:30 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return CefThread::CurrentlyOn(static_cast<CefThread::ID>(id));
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefPostTask(CefThreadId threadId, CefRefPtr<CefTask> task) {
|
2011-12-23 18:36:30 +01:00
|
|
|
int id = GetThreadId(threadId);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (id < 0)
|
2011-12-23 18:36:30 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return CefThread::PostTask(static_cast<CefThread::ID>(id), FROM_HERE,
|
2012-02-17 15:51:20 +01:00
|
|
|
base::Bind(&CefTask::Execute, task, threadId));
|
2011-12-23 18:36:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr<CefTask> task,
|
2012-01-10 00:46:23 +01:00
|
|
|
int64 delay_ms) {
|
2011-12-23 18:36:30 +01:00
|
|
|
int id = GetThreadId(threadId);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (id < 0)
|
2011-12-23 18:36:30 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return CefThread::PostDelayedTask(static_cast<CefThread::ID>(id), FROM_HERE,
|
2012-02-17 15:51:20 +01:00
|
|
|
base::Bind(&CefTask::Execute, task, threadId), delay_ms);
|
2011-12-23 18:36:30 +01:00
|
|
|
}
|