1 // Copyright (c) 2013 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
13 // * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // ---------------------------------------------------------------------------
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
37 #ifndef CEF_INCLUDE_CEF_TASK_H_
38 #define CEF_INCLUDE_CEF_TASK_H_
40 #include "include/cef_base.h"
42 typedef cef_thread_id_t CefThreadId;
45 // Implement this interface for asynchronous task execution. If the task is
46 // posted successfully and if the associated message loop is still running then
47 // the Execute() method will be called on the target thread. If the task fails
48 // to post then the task object may be destroyed on the source thread instead of
49 // the target thread. For this reason be cautious when performing work in the
50 // task object destructor.
52 /*--cef(source=client)--*/
53 class CefTask : public virtual CefBase {
56 // Method that will be executed on the target thread.
59 virtual void Execute() =0;
63 // Class that asynchronously executes tasks on the associated thread. It is safe
64 // to call the methods of this class on any thread.
66 // CEF maintains multiple internal threads that are used for handling different
67 // types of tasks in different processes. The cef_thread_id_t definitions in
68 // cef_types.h list the common CEF threads. Task runners are also available for
69 // other CEF threads as appropriate (for example, V8 WebWorker threads).
71 /*--cef(source=library)--*/
72 class CefTaskRunner : public virtual CefBase {
75 // Returns the task runner for the current thread. Only CEF threads will have
76 // task runners. An empty reference will be returned if this method is called
77 // on an invalid thread.
80 static CefRefPtr<CefTaskRunner> GetForCurrentThread();
83 // Returns the task runner for the specified CEF thread.
86 static CefRefPtr<CefTaskRunner> GetForThread(CefThreadId threadId);
89 // Returns true if this object is pointing to the same task runner as |that|
93 virtual bool IsSame(CefRefPtr<CefTaskRunner> that) =0;
96 // Returns true if this task runner belongs to the current thread.
99 virtual bool BelongsToCurrentThread() =0;
102 // Returns true if this task runner is for the specified CEF thread.
105 virtual bool BelongsToThread(CefThreadId threadId) =0;
108 // Post a task for execution on the thread associated with this task runner.
109 // Execution will occur asynchronously.
112 virtual bool PostTask(CefRefPtr<CefTask> task) =0;
115 // Post a task for delayed execution on the thread associated with this task
116 // runner. Execution will occur asynchronously. Delayed tasks are not
117 // supported on V8 WebWorker threads and will be executed without the
121 virtual bool PostDelayedTask(CefRefPtr<CefTask> task, int64 delay_ms) =0;
126 // Returns true if called on the specified thread. Equivalent to using
127 // CefTaskRunner::GetForThread(threadId)->BelongsToCurrentThread().
130 bool CefCurrentlyOn(CefThreadId threadId);
133 // Post a task for execution on the specified thread. Equivalent to
134 // using CefTaskRunner::GetForThread(threadId)->PostTask(task).
137 bool CefPostTask(CefThreadId threadId, CefRefPtr<CefTask> task);
140 // Post a task for delayed execution on the specified thread. Equivalent to
141 // using CefTaskRunner::GetForThread(threadId)->PostDelayedTask(task, delay_ms).
144 bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr<CefTask> task,
148 #endif // CEF_INCLUDE_CEF_TASK_H_