message_pump_android.h (1768B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style license that can be 5 // found in the LICENSE file. 6 7 #ifndef BASE_MESSAGE_PUMP_ANDROID_H_ 8 #define BASE_MESSAGE_PUMP_ANDROID_H_ 9 10 #include "base/message_pump.h" 11 #include "base/time.h" 12 13 namespace base { 14 15 // This class implements a MessagePump needed for TYPE_UI MessageLoops on 16 // Android 17 class MessagePumpForUI : public MessagePump { 18 public: 19 MessagePumpForUI(); 20 ~MessagePumpForUI(); 21 22 virtual void Run(Delegate* delegate); 23 virtual void Quit(); 24 virtual void ScheduleWork(); 25 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); 26 27 // Internal methods used for processing the pump callbacks. They are 28 // public for simplicity but should not be used directly. 29 // HandleDispatch is called after the poll has completed. 30 void HandleDispatch(); 31 32 private: 33 // We may make recursive calls to Run, so we save state that needs to be 34 // separate between them in this structure type. 35 struct RunState { 36 Delegate* delegate; 37 38 // Used to flag that the current Run() invocation should return ASAP. 39 bool should_quit; 40 41 // Used to count how many Run() invocations are on the stack. 42 int run_depth; 43 44 // Used internally for controlling whether we want a message pump 45 // iteration to be blocking or not. 46 bool more_work_is_plausible; 47 }; 48 49 RunState* state_; 50 51 // This is the time when we need to do delayed work. 52 TimeTicks delayed_work_time_; 53 54 bool work_scheduled; 55 56 DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); 57 }; 58 59 } // namespace base 60 61 #endif // BASE_MESSAGE_PUMP_ANDROID_H_