1 // Copyright (c) 2016 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_SHARED_BROWSER_MAIN_MESSAGE_LOOP_EXTERNAL_PUMP_H_ 6 #define CEF_TESTS_SHARED_BROWSER_MAIN_MESSAGE_LOOP_EXTERNAL_PUMP_H_ 7 #pragma once 8 9 #include "tests/shared/browser/main_message_loop_std.h" 10 11 namespace client { 12 13 // This MessageLoop implementation simulates the embedding of CEF into an 14 // existing host application that runs its own message loop. The scheduling 15 // implementation provided by this class is very simplistic and does not handle 16 // all cases (for example, nested message loops on Windows will not function 17 // correctly). See comments in Chromium's platform-specific 18 // base/message_loop/message_pump_* source files for additional guidance when 19 // implementing CefBrowserProcessHandler::OnScheduleMessagePumpWork() in your 20 // application. Run cefclient or ceftests with the 21 // "--external-message-pump" command-line flag to test this mode. 22 class MainMessageLoopExternalPump : public MainMessageLoopStd { 23 public: 24 // Creates the singleton instance of this object. Must be called on the main 25 // application thread. 26 static std::unique_ptr<MainMessageLoopExternalPump> Create(); 27 28 // Returns the singleton instance of this object. Safe to call from any 29 // thread. 30 static MainMessageLoopExternalPump* Get(); 31 32 // Called from CefBrowserProcessHandler::OnScheduleMessagePumpWork() on any 33 // thread. The platform subclass must implement this method and schedule a 34 // call to OnScheduleWork() on the main application thread. 35 virtual void OnScheduleMessagePumpWork(int64 delay_ms) = 0; 36 37 protected: 38 // Only allow deletion via std::unique_ptr. 39 friend std::default_delete<MainMessageLoopExternalPump>; 40 41 // Construct and destruct this object on the main application thread. 42 MainMessageLoopExternalPump(); 43 ~MainMessageLoopExternalPump(); 44 45 // The platform subclass calls this method on the main application thread in 46 // response to the OnScheduleMessagePumpWork() call. 47 void OnScheduleWork(int64 delay_ms); 48 49 // The platform subclass calls this method on the main application thread when 50 // the pending work timer times out. 51 void OnTimerTimeout(); 52 53 // Control the pending work timer in the platform subclass. Only called on 54 // the main application thread. 55 virtual void SetTimer(int64 delay_ms) = 0; 56 virtual void KillTimer() = 0; 57 virtual bool IsTimerPending() = 0; 58 59 private: 60 // Handle work processing. 61 void DoWork(); 62 bool PerformMessageLoopWork(); 63 64 bool is_active_; 65 bool reentrancy_detected_; 66 }; 67 68 } // namespace client 69 70 #endif // CEF_TESTS_SHARED_BROWSER_MAIN_MESSAGE_LOOP_EXTERNAL_PUMP_H_ 71