[go: nahoru, domu]

blob: 3ee078a406490a9cb3ba35ab0ead37c9abfeb210 [file] [log] [blame]
Avi Drissman3f7a9d82022-09-08 20:55:421// Copyright 2014 The Chromium Authors
vmpstr@chromium.orgafb84fc2014-05-29 01:47:532// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CC_BASE_UNIQUE_NOTIFIER_H_
6#define CC_BASE_UNIQUE_NOTIFIER_H_
7
Avi Drissman453cf7a72023-01-07 00:52:178#include "base/functional/callback.h"
Keishi Hattori0e45c022021-11-27 09:25:529#include "base/memory/raw_ptr.h"
vmpstr@chromium.orgafb84fc2014-05-29 01:47:5310#include "base/memory/weak_ptr.h"
chrishtrac41ff92017-03-17 05:07:3011#include "cc/base/base_export.h"
vmpstr@chromium.orgafb84fc2014-05-29 01:47:5312
13namespace base {
14class SequencedTaskRunner;
15} // namespace base
16
17namespace cc {
18
Xu Xingd36a6cd2018-09-26 01:56:0219// Callers must ensure that they only schedule the notifier on the same thread
20// that the provided |task_runner| runs on.
chrishtrac41ff92017-03-17 05:07:3021class CC_BASE_EXPORT UniqueNotifier {
vmpstr@chromium.orgafb84fc2014-05-29 01:47:5322 public:
23 // Configure this notifier to issue the |closure| notification when scheduled.
24 UniqueNotifier(base::SequencedTaskRunner* task_runner,
kylechar4bb144d2019-01-11 20:42:0725 base::RepeatingClosure closure);
Vladimir Levinf06d1cd72019-03-13 18:24:1026 UniqueNotifier(const UniqueNotifier&) = delete;
vmpstr@chromium.orgafb84fc2014-05-29 01:47:5327
28 // Destroying the notifier will ensure that no further notifications will
29 // happen from this class.
30 ~UniqueNotifier();
31
Vladimir Levinf06d1cd72019-03-13 18:24:1032 UniqueNotifier& operator=(const UniqueNotifier&) = delete;
33
vmpstr@chromium.orgafb84fc2014-05-29 01:47:5334 // Schedule a notification to be run. If another notification is already
35 // pending, then only one notification will take place.
36 void Schedule();
37
vmpstr8c53b7f92015-07-01 21:47:4738 // Cancel a pending notification, if one was scheduled.
39 void Cancel();
40
vmpstr@chromium.orgafb84fc2014-05-29 01:47:5341 private:
42 void Notify();
43
dchengfba633142014-08-28 18:56:3344 // TODO(dcheng): How come this doesn't need to hold a ref to the task runner?
Keishi Hattori0e45c022021-11-27 09:25:5245 const raw_ptr<base::SequencedTaskRunner> task_runner_;
kylechar4bb144d2019-01-11 20:42:0746 const base::RepeatingClosure closure_;
ericrk9c57a2d2016-08-22 19:39:5647
48 // Lock should be held before modifying |notification_pending_|.
49 base::Lock lock_;
vmpstr@chromium.orgafb84fc2014-05-29 01:47:5350 bool notification_pending_;
51
Jeremy Roman31f36b72019-07-09 16:33:4152 base::WeakPtrFactory<UniqueNotifier> weak_ptr_factory_{this};
vmpstr@chromium.orgafb84fc2014-05-29 01:47:5353};
54
55} // namespace cc
56
57#endif // CC_BASE_UNIQUE_NOTIFIER_H_