1 // Copyright (c) 2013 Marshall A. Greenblatt. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 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 12 // distribution. 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. 17 // 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. 29 // 30 // --------------------------------------------------------------------------- 31 // 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. 35 // 36 37 #ifndef CEF_INCLUDE_CEF_TASK_H_ 38 #define CEF_INCLUDE_CEF_TASK_H_ 39 40 #include "include/cef_base.h" 41 42 typedef cef_thread_id_t CefThreadId; 43 44 /// 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. 51 /// 52 /*--cef(source=client,no_debugct_check)--*/ 53 class CefTask : public virtual CefBaseRefCounted { 54 public: 55 /// 56 // Method that will be executed on the target thread. 57 /// 58 /*--cef()--*/ 59 virtual void Execute() = 0; 60 }; 61 62 /// 63 // Class that asynchronously executes tasks on the associated thread. It is safe 64 // to call the methods of this class on any thread. 65 // 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). 70 /// 71 /*--cef(source=library)--*/ 72 class CefTaskRunner : public virtual CefBaseRefCounted { 73 public: 74 /// 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. 78 /// 79 /*--cef()--*/ 80 static CefRefPtr<CefTaskRunner> GetForCurrentThread(); 81 82 /// 83 // Returns the task runner for the specified CEF thread. 84 /// 85 /*--cef()--*/ 86 static CefRefPtr<CefTaskRunner> GetForThread(CefThreadId threadId); 87 88 /// 89 // Returns true if this object is pointing to the same task runner as |that| 90 // object. 91 /// 92 /*--cef()--*/ 93 virtual bool IsSame(CefRefPtr<CefTaskRunner> that) = 0; 94 95 /// 96 // Returns true if this task runner belongs to the current thread. 97 /// 98 /*--cef()--*/ 99 virtual bool BelongsToCurrentThread() = 0; 100 101 /// 102 // Returns true if this task runner is for the specified CEF thread. 103 /// 104 /*--cef()--*/ 105 virtual bool BelongsToThread(CefThreadId threadId) = 0; 106 107 /// 108 // Post a task for execution on the thread associated with this task runner. 109 // Execution will occur asynchronously. 110 /// 111 /*--cef()--*/ 112 virtual bool PostTask(CefRefPtr<CefTask> task) = 0; 113 114 /// 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 118 // specified delay. 119 /// 120 /*--cef()--*/ 121 virtual bool PostDelayedTask(CefRefPtr<CefTask> task, int64 delay_ms) = 0; 122 }; 123 124 /// 125 // Returns true if called on the specified thread. Equivalent to using 126 // CefTaskRunner::GetForThread(threadId)->BelongsToCurrentThread(). 127 /// 128 /*--cef()--*/ 129 bool CefCurrentlyOn(CefThreadId threadId); 130 131 /// 132 // Post a task for execution on the specified thread. Equivalent to 133 // using CefTaskRunner::GetForThread(threadId)->PostTask(task). 134 /// 135 /*--cef()--*/ 136 bool CefPostTask(CefThreadId threadId, CefRefPtr<CefTask> task); 137 138 /// 139 // Post a task for delayed execution on the specified thread. Equivalent to 140 // using CefTaskRunner::GetForThread(threadId)->PostDelayedTask(task, delay_ms). 141 /// 142 /*--cef()--*/ 143 bool CefPostDelayedTask(CefThreadId threadId, 144 CefRefPtr<CefTask> task, 145 int64 delay_ms); 146 147 #endif // CEF_INCLUDE_CEF_TASK_H_ 148