cc: Remove tile and scale specific code from raster source
[chromium-blink-merge.git] / base / message_loop / message_pump_glib.h
blob9f4457141d7096f7ed9760922099e2f0b727567b
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_
8 #include "base/base_export.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_pump.h"
11 #include "base/observer_list.h"
12 #include "base/time/time.h"
14 typedef struct _GMainContext GMainContext;
15 typedef struct _GPollFD GPollFD;
16 typedef struct _GSource GSource;
18 namespace base {
20 // This class implements a base MessagePump needed for TYPE_UI MessageLoops on
21 // platforms using GLib.
22 class BASE_EXPORT MessagePumpGlib : public MessagePump {
23 public:
24 MessagePumpGlib();
25 ~MessagePumpGlib() override;
27 // Internal methods used for processing the pump callbacks. They are
28 // public for simplicity but should not be used directly. HandlePrepare
29 // is called during the prepare step of glib, and returns a timeout that
30 // will be passed to the poll. HandleCheck is called after the poll
31 // has completed, and returns whether or not HandleDispatch should be called.
32 // HandleDispatch is called if HandleCheck returned true.
33 int HandlePrepare();
34 bool HandleCheck();
35 void HandleDispatch();
37 // Overridden from MessagePump:
38 void Run(Delegate* delegate) override;
39 void Quit() override;
40 void ScheduleWork() override;
41 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
43 private:
44 bool ShouldQuit() const;
46 // We may make recursive calls to Run, so we save state that needs to be
47 // separate between them in this structure type.
48 struct RunState;
50 RunState* state_;
52 // This is a GLib structure that we can add event sources to. We use the
53 // default GLib context, which is the one to which all GTK events are
54 // dispatched.
55 GMainContext* context_;
57 // This is the time when we need to do delayed work.
58 TimeTicks delayed_work_time_;
60 // The work source. It is shared by all calls to Run and destroyed when
61 // the message pump is destroyed.
62 GSource* work_source_;
64 // We use a wakeup pipe to make sure we'll get out of the glib polling phase
65 // when another thread has scheduled us to do some work. There is a glib
66 // mechanism g_main_context_wakeup, but this won't guarantee that our event's
67 // Dispatch() will be called.
68 int wakeup_pipe_read_;
69 int wakeup_pipe_write_;
70 // Use a scoped_ptr to avoid needing the definition of GPollFD in the header.
71 scoped_ptr<GPollFD> wakeup_gpollfd_;
73 DISALLOW_COPY_AND_ASSIGN(MessagePumpGlib);
76 } // namespace base
78 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_