• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2014 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 are only available to applications that link
33 // against the libcef_dll_wrapper target.
34 //
35 
36 #ifndef CEF_INCLUDE_WRAPPER_CEF_CLOSURE_TASK_H_
37 #define CEF_INCLUDE_WRAPPER_CEF_CLOSURE_TASK_H_
38 #pragma once
39 
40 #include "include/base/cef_callback_forward.h"
41 #include "include/cef_task.h"
42 
43 ///
44 // Helpers for asynchronously executing a base::[Once|Repeating]Closure (bound
45 // function or method) on a CEF thread. Creation of a
46 // base::[Once|Repeating]Closure can be facilitated using
47 // base::Bind[Once|Repeating]. See include/base/cef_callback.h for complete
48 // usage instructions.
49 //
50 // To use these helpers you should include this header and the header that
51 // defines base::Bind[Once|Repeating].
52 //
53 // #include "include/base/cef_callback.h"
54 // #include "include/wrapper/cef_closure_task.h"
55 //
56 // Example of executing a bound function:
57 //
58 // // Define a function.
59 // void MyFunc(int arg) { /* do something with |arg| on the UI thread */ }
60 //
61 // // Post a task that will execute MyFunc on the UI thread and pass an |arg|
62 // // value of 5.
63 // CefPostTask(TID_UI, base::BindOnce(&MyFunc, 5));
64 //
65 // Example of executing a bound method:
66 //
67 // // Define a class.
68 // class MyClass : public CefBaseRefCounted {
69 //  public:
70 //   MyClass() {}
71 //   void MyMethod(int arg) { /* do something with |arg| on the UI thread */ }
72 //  private:
73 //   IMPLEMENT_REFCOUNTING(MyClass);
74 // };
75 //
76 // // Create an instance of MyClass.
77 // CefRefPtr<MyClass> instance = new MyClass();
78 //
79 // // Post a task that will execute MyClass::MyMethod on the UI thread and pass
80 // // an |arg| value of 5. |instance| will be kept alive until after the task
81 // // completes.
82 // CefPostTask(TID_UI, base::BindOnce(&MyClass::MyMethod, instance, 5));
83 ///
84 
85 ///
86 // Create a CefTask that wraps a base::[Once|Repeating]Closure. Can be used in
87 // combination with CefTaskRunner.
88 ///
89 CefRefPtr<CefTask> CefCreateClosureTask(base::OnceClosure closure);
90 CefRefPtr<CefTask> CefCreateClosureTask(const base::RepeatingClosure& closure);
91 
92 ///
93 // Post a base::[Once|Repeating]Closure for execution on the specified thread.
94 ///
95 bool CefPostTask(CefThreadId threadId, base::OnceClosure closure);
96 bool CefPostTask(CefThreadId threadId, const base::RepeatingClosure& closure);
97 
98 ///
99 // Post a base::[Once|Repeating]Closure for delayed execution on the specified
100 // thread.
101 ///
102 bool CefPostDelayedTask(CefThreadId threadId,
103                         base::OnceClosure closure,
104                         int64 delay_ms);
105 bool CefPostDelayedTask(CefThreadId threadId,
106                         const base::RepeatingClosure& closure,
107                         int64 delay_ms);
108 
109 #endif  // CEF_INCLUDE_WRAPPER_CEF_CLOSURE_TASK_H_
110