summaryrefslogtreecommitdiff
path: root/chromium/components/gcm_driver/gcm_delayed_task_controller.h
blob: bf1e15fa86e5938a784b1a8bbd6daee521fcd18d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_GCM_DRIVER_GCM_DELAYED_TASK_CONTROLLER_H_
#define COMPONENTS_GCM_DRIVER_GCM_DELAYED_TASK_CONTROLLER_H_

#include <vector>

#include "base/callback.h"

namespace gcm {

// Helper class to save tasks to run until we're ready to execute them.
class GCMDelayedTaskController {
 public:
  GCMDelayedTaskController();

  GCMDelayedTaskController(const GCMDelayedTaskController&) = delete;
  GCMDelayedTaskController& operator=(const GCMDelayedTaskController&) = delete;

  ~GCMDelayedTaskController();

  // Adds a task that will be invoked once we're ready.
  void AddTask(base::OnceClosure task);

  // Sets ready status, which will release all of the pending tasks.
  void SetReady();

  // Returns true if it is ready to perform tasks.
  bool CanRunTaskWithoutDelay() const;

 private:
  void RunTasks();

  // Flag that indicates that controlled component is ready.
  bool ready_;

  std::vector<base::OnceClosure> delayed_tasks_;
};

}  // namespace gcm

#endif  // COMPONENTS_GCM_DRIVER_GCM_DELAYED_TASK_CONTROLLER_H_