Hello,
I am writing a shared library on linux which will launch different CEF browsers IN PROCESS whenever it receives say 'Launch' command with a url. Here's a rough example of how I expect it to work :
1) If I receive 'LAUNCH 123 google.com' command, I want to launch cef with url google.com and associate that cef instance with id 123
2) If I receive 'LAUNCH 334 spotify.com' command, I want to launch cef with url spotify.com and associate that cef instance with id 334
3) If I receive 'DELETE 123' command, I want to stop the cef browser that was associated with id 123 but the 334 instance should keep running
I'd be launching them in offscreen rendering mode and use my own graphical toolkit to render the buffer on-screen.
I was trying out different approaches for a simple case of having 2 cef browsers and below is my observation :
1. Creating two threads. Each thread calls CefInitialize and CefRunMessageLoop. Each thread has its own SimpleApp object and OnContextInitialized creates its own SimpleHandler. In this method, I see that only 1 thread executes which calls OnContextInitialized and SimpleHandler's OnPaint. Second thread exits because CefRunMessageLoop returns immediately.
2. Creating two threads but this time I implemented my own message loop. So similar to #1, each thread calls CefInitialize and calls Run on my message loop
a. When settings.multi_threaded_message_loop = false (default)
Only 1 thread gets callback to OnContextInitialized but none of the threads get call to SimpleHandler constructor. Both the threads keep running the message
loop but no CefTasks are found in the queue.
b. When settings.multi_threaded_message_loop = true
Both threads successfully call CefInitialize and run the message loop. A separate thread gets created that gets a callback to OnContextInitialized and on this
thread, browser gets created successfully and SimpleHandler's OnPaint gets called.
3. Call CefInitialize once on the main thread. Create two threads that only call CefRunMessageLoop
Both threads call CefRunMessageLoop and CefRunMessageLoop returns immediately. Both threads exit.
4. Call CefInitialize once on the main thread. Create two threads that only call my message loop.
a. When settings.multi_threaded_message_loop = false (default)
None of the threads get OnContextInitialized callback. Both message loops run but no tasks found.
b. When settings.multi_threaded_message_loop = true
A separate thread is created that gets OnContextInitialized callback and Browser object gets created. SimpleHandler callbacks come on that thread. The
two threads that I created are running message loops but no tasks are found.
So based on above observation, what do you think would be the right way to make sure I can get my test app working?
Is there a way where I can have each cef player live in its own thread so that it's easy to do the bookkeeping?
Would appreciate your insight.