fgorski | 05d507c | 2014-09-10 17:28:10 | [diff] [blame] | 1 | // Copyright 2014 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. |
| 4 | |
| 5 | #ifndef COMPONENTS_GCM_DRIVER_GCM_DELAYED_TASK_CONTROLLER_H_ |
| 6 | #define COMPONENTS_GCM_DRIVER_GCM_DELAYED_TASK_CONTROLLER_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "base/callback.h" |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 11 | #include "base/macros.h" |
fgorski | 05d507c | 2014-09-10 17:28:10 | [diff] [blame] | 12 | |
| 13 | namespace gcm { |
| 14 | |
| 15 | // Helper class to save tasks to run until we're ready to execute them. |
| 16 | class GCMDelayedTaskController { |
| 17 | public: |
| 18 | GCMDelayedTaskController(); |
| 19 | ~GCMDelayedTaskController(); |
| 20 | |
| 21 | // Adds a task that will be invoked once we're ready. |
danakj | b534bf7 | 2019-05-02 17:10:14 | [diff] [blame] | 22 | void AddTask(base::OnceClosure task); |
fgorski | 05d507c | 2014-09-10 17:28:10 | [diff] [blame] | 23 | |
| 24 | // Sets ready status, which will release all of the pending tasks. |
| 25 | void SetReady(); |
| 26 | |
| 27 | // Returns true if it is ready to perform tasks. |
| 28 | bool CanRunTaskWithoutDelay() const; |
| 29 | |
| 30 | private: |
| 31 | void RunTasks(); |
| 32 | |
| 33 | // Flag that indicates that controlled component is ready. |
| 34 | bool ready_; |
| 35 | |
danakj | b534bf7 | 2019-05-02 17:10:14 | [diff] [blame] | 36 | std::vector<base::OnceClosure> delayed_tasks_; |
fgorski | 05d507c | 2014-09-10 17:28:10 | [diff] [blame] | 37 | |
| 38 | DISALLOW_COPY_AND_ASSIGN(GCMDelayedTaskController); |
| 39 | }; |
| 40 | |
| 41 | } // namespace gcm |
| 42 | |
| 43 | #endif // COMPONENTS_GCM_DRIVER_GCM_DELAYED_TASK_CONTROLLER_H_ |