• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2018 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_MAIN_MESSAGE_LOOP_MULTITHREADED_GTK_H_
6 #define CEF_TESTS_CEFCLIENT_BROWSER_MAIN_MESSAGE_LOOP_MULTITHREADED_GTK_H_
7 #pragma once
8 
9 #include <queue>
10 
11 #include <gdk/gdk.h>
12 
13 #include "include/base/cef_lock.h"
14 #include "include/base/cef_platform_thread.h"
15 #include "tests/shared/browser/main_message_loop.h"
16 
17 namespace client {
18 
19 // Represents the main message loop in the browser process when using multi-
20 // threaded message loop mode on Linux. In this mode there is no Chromium
21 // message loop running on the main application thread. Instead, this
22 // implementation utilizes a Glib context for running tasks.
23 class MainMessageLoopMultithreadedGtk : public MainMessageLoop {
24  public:
25   MainMessageLoopMultithreadedGtk();
26   ~MainMessageLoopMultithreadedGtk();
27 
28   // MainMessageLoop methods.
29   int Run() override;
30   void Quit() override;
31   void PostTask(CefRefPtr<CefTask> task) override;
32   bool RunsTasksOnCurrentThread() const override;
33 
34  private:
35   static int TriggerRunTasks(void* self);
36   void RunTasks();
37   void DoQuit();
38 
39   base::PlatformThreadId thread_id_;
40 
41   GMainContext* main_context_;
42   GMainLoop* main_loop_;
43 
44   base::Lock lock_;
45 
46   // Must be protected by |lock_|.
47   std::queue<CefRefPtr<CefTask>> queued_tasks_;
48 
49   DISALLOW_COPY_AND_ASSIGN(MainMessageLoopMultithreadedGtk);
50 };
51 
52 }  // namespace client
53 
54 #endif  // CEF_TESTS_CEFCLIENT_BROWSER_MAIN_MESSAGE_LOOP_MULTITHREADED_GTK_H_
55