// 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" #include "cef_thread.h" namespace { int GetThreadId(CefThreadId threadId) { switch(threadId) { case TID_UI: return CefThread::UI; case TID_IO: return CefThread::IO; case TID_FILE: return CefThread::FILE; }; NOTREACHED(); return -1; } } // anonymous bool CefCurrentlyOn(CefThreadId threadId) { int id = GetThreadId(threadId); if(id < 0) return false; return CefThread::CurrentlyOn(static_cast(id)); } class CefTaskHelper : public Task { public: CefTaskHelper(CefRefPtr task, CefThreadId threadId) : task_(task), thread_id_(threadId) {} virtual void Run() { task_->Execute(thread_id_); } private: CefRefPtr task_; CefThreadId thread_id_; DISALLOW_COPY_AND_ASSIGN(CefTaskHelper); }; bool CefPostTask(CefThreadId threadId, CefRefPtr task) { int id = GetThreadId(threadId); if(id < 0) return false; return CefThread::PostTask(static_cast(id), FROM_HERE, new CefTaskHelper(task, threadId)); } bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr task, long delay_ms) { int id = GetThreadId(threadId); if(id < 0) return false; return CefThread::PostDelayedTask(static_cast(id), FROM_HERE, new CefTaskHelper(task, threadId), delay_ms); }