CEF has several threads, such as tid_ui, such as Tid_render, each of which has a specific meaning, and the specific category is defined in Cef_types.h, with the following excerpt:
typedef enum {//BROWSER process THREADS-only available in the BROWSER process. The main thread in the browser. This would be the same as the main//application thread if Cefinitialize () are called with A//Cefsettings.multi_threade D_message_loop value of FALSE. TID_UI,////used to interact with the database. tid_db,////used to interact with the file system. Tid_file,////used for the FILE system operations that block user interactions. Responsiveness of this thread affects users. Tid_file_user_blocking,////used to launch and terminate browser processes. Tid_process_launcher,////used to handle slow HTTP cache operations. Tid_cache,/////used to process IPC and network messages. tid_io,//Render Process THREADS-only available in the render process. The main thread in the renderer. Used for all WebKit and V8 interaction. Tid_renderer,} cef_thread_id_t;
For descriptions of these threads, see the comments in the code above, and you can also join here: https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage#markdown-header-threads.
If we want to perform a task on a thread, such as when you want to pop up a window in the browser process, execute your code on the TID_UI thread. Similar tasks can be done through ceftask. Very simply, Cef_task.h has a ceftask interface declaration, we inherit it, and then use the Cefposttask.
The code resembles the following:
#include "include/cef_task.h"void doSomethingOnUIThread(){ MessageBox(...);}class SomeTask : public CefTask{ IMPLEMENT_REFCOUNTING(SomeTask);public: void Execute() { doSomethingOnUIThread(); }};void doSomething(){ if (CefCurrentlyOn(TID_UI)) { doSomethingOnUIThread(); } else { CefRefPtr<SomeTask> t = new SomeTask; CefPostTask(TID_UI, t); }}
If you do not want to write a class to implement the Ceftask interface, CEF has some assistive means to help you. Let's look at the following code snippet:
if (!CefCurrentlyOn(TID_UI)) { // Execute on the UI thread. CefPostTask(TID_UI, base::Bind(&ClientHandler::CloseAllBrowsers, this, force_close)); return;}
This is cefsimple, it uses base::bind to generate a functor, using a similar STL-like bind, including the "Include/base/cef_bind.h" header file.
That's it.
Other reference articles are described in my column: "CEF and Ppapi development ".
Perform a task on a specified CEF thread