blob: bdd500fe2c9448401ea9c6f3565953795e89d6dd [file] [log] [blame]
fgorski05d507c2014-09-10 17:28:101// 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"
avi26062922015-12-26 00:14:1811#include "base/macros.h"
fgorski05d507c2014-09-10 17:28:1012
13namespace gcm {
14
15// Helper class to save tasks to run until we're ready to execute them.
16class GCMDelayedTaskController {
17 public:
18 GCMDelayedTaskController();
19 ~GCMDelayedTaskController();
20
21 // Adds a task that will be invoked once we're ready.
danakjb534bf72019-05-02 17:10:1422 void AddTask(base::OnceClosure task);
fgorski05d507c2014-09-10 17:28:1023
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
danakjb534bf72019-05-02 17:10:1436 std::vector<base::OnceClosure> delayed_tasks_;
fgorski05d507c2014-09-10 17:28:1037
38 DISALLOW_COPY_AND_ASSIGN(GCMDelayedTaskController);
39};
40
41} // namespace gcm
42
43#endif // COMPONENTS_GCM_DRIVER_GCM_DELAYED_TASK_CONTROLLER_H_