summaryrefslogtreecommitdiffstats
path: root/chromium/cc/base/unique_notifier.h
blob: 4752f6f6955684d10adaf8de1317a943f9244a4d (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 CC_BASE_UNIQUE_NOTIFIER_H_
#define CC_BASE_UNIQUE_NOTIFIER_H_

#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "cc/base/cc_export.h"

namespace base {
class SequencedTaskRunner;
}  // namespace base

namespace cc {

class CC_EXPORT UniqueNotifier {
 public:
  // Configure this notifier to issue the |closure| notification when scheduled.
  UniqueNotifier(base::SequencedTaskRunner* task_runner,
                 const base::Closure& closure);

  // Destroying the notifier will ensure that no further notifications will
  // happen from this class.
  ~UniqueNotifier();

  // Schedule a notification to be run. If another notification is already
  // pending, then only one notification will take place.
  void Schedule();

 private:
  void Notify();

  base::SequencedTaskRunner* task_runner_;
  base::Closure closure_;
  bool notification_pending_;

  base::WeakPtrFactory<UniqueNotifier> weak_ptr_factory_;
};

}  // namespace cc

#endif  // CC_BASE_UNIQUE_NOTIFIER_H_