• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015 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_WIN_H_
6 #define CEF_TESTS_CEFCLIENT_BROWSER_MAIN_MESSAGE_LOOP_MULTITHREADED_WIN_H_
7 #pragma once
8 
9 #include <windows.h>
10 #include <queue>
11 
12 #include "include/base/cef_lock.h"
13 #include "include/base/cef_platform_thread.h"
14 #include "tests/shared/browser/main_message_loop.h"
15 
16 namespace client {
17 
18 // Represents the main message loop in the browser process when using multi-
19 // threaded message loop mode on Windows. In this mode there is no Chromium
20 // message loop running on the main application thread. Instead, this
21 // implementation utilizes a hidden message window for running tasks.
22 class MainMessageLoopMultithreadedWin : public MainMessageLoop {
23  public:
24   MainMessageLoopMultithreadedWin();
25   ~MainMessageLoopMultithreadedWin();
26 
27   // MainMessageLoop methods.
28   int Run() override;
29   void Quit() override;
30   void PostTask(CefRefPtr<CefTask> task) override;
31   bool RunsTasksOnCurrentThread() const override;
32   void SetCurrentModelessDialog(HWND hWndDialog) override;
33 
34  private:
35   // Create the message window.
36   static HWND CreateMessageWindow(HINSTANCE hInstance);
37 
38   // Window procedure for the message window.
39   static LRESULT CALLBACK MessageWndProc(HWND hWnd,
40                                          UINT message,
41                                          WPARAM wParam,
42                                          LPARAM lParam);
43 
44   void PostTaskInternal(CefRefPtr<CefTask> task);
45 
46   base::PlatformThreadId thread_id_;
47   UINT task_message_id_;
48 
49   // Only accessed on the main thread.
50   HWND dialog_hwnd_;
51 
52   base::Lock lock_;
53 
54   // Must be protected by |lock_|.
55   HWND message_hwnd_;
56   std::queue<CefRefPtr<CefTask>> queued_tasks_;
57 
58   DISALLOW_COPY_AND_ASSIGN(MainMessageLoopMultithreadedWin);
59 };
60 
61 }  // namespace client
62 
63 #endif  // CEF_TESTS_CEFCLIENT_BROWSER_MAIN_MESSAGE_LOOP_MULTITHREADED_WIN_H_
64