Peter Qiu | 326b6cf | 2015-09-02 11:11:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Peter Qiu | bfd410e | 2015-01-09 15:14:20 -0800 | [diff] [blame] | 16 | |
| 17 | #ifndef APMANAGER_EVENT_DISPATCHER_H_ |
| 18 | #define APMANAGER_EVENT_DISPATCHER_H_ |
| 19 | |
| 20 | #include <base/callback.h> |
| 21 | #include <base/lazy_instance.h> |
| 22 | |
| 23 | namespace apmanager { |
| 24 | |
| 25 | // Singleton class for dispatching tasks to current message loop. |
| 26 | class EventDispatcher { |
| 27 | public: |
| 28 | virtual ~EventDispatcher(); |
| 29 | |
| 30 | // This is a singleton. Use EventDispatcher::GetInstance()->Foo(). |
| 31 | static EventDispatcher* GetInstance(); |
| 32 | |
| 33 | // These are thin wrappers around calls of the same name in |
| 34 | // <base/message_loop_proxy.h> |
| 35 | virtual bool PostTask(const base::Closure& task); |
| 36 | virtual bool PostDelayedTask(const base::Closure& task, |
| 37 | int64_t delay_ms); |
| 38 | |
| 39 | protected: |
| 40 | EventDispatcher(); |
| 41 | |
| 42 | private: |
| 43 | friend struct base::DefaultLazyInstanceTraits<EventDispatcher>; |
| 44 | |
| 45 | DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
| 46 | }; |
| 47 | |
| 48 | } // namespace apmanager |
| 49 | |
| 50 | #endif // APMANAGER_EVENT_DISPATCHER_H_ |