Chromium Code Reviews| Index: cc/base/unique_notifier.h |
| diff --git a/cc/base/unique_notifier.h b/cc/base/unique_notifier.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..65a663feb2767cf53aeb1b994fc213c4c18d520e |
| --- /dev/null |
| +++ b/cc/base/unique_notifier.h |
| @@ -0,0 +1,52 @@ |
| +// 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 in |delay| time |
| + // from Schedule() call. Note that 0 delay is also acceptable, which will post |
| + // the task to be run as soon as possible. |
| + UniqueNotifier(const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
|
reveman
2014/05/21 17:03:37
no need to pass ownership here, base::SequencedTas
vmpstr
2014/05/21 17:41:02
Done.
|
| + const base::Closure& closure, |
| + const base::TimeDelta& delay); |
|
reveman
2014/05/21 17:03:37
I would prefer if we had two classes (UniqueNotifi
vmpstr
2014/05/21 17:41:02
I don't think deriving from each other would make
|
| + |
| + // 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 it will happen in given delay from now. That is, if delay is |
| + // 16ms and a notification has been scheduled 10ms ago (ie, it should trigger |
| + // in 6ms), then calling schedule will ensure that the only notification that |
| + // arrives will happen in 16ms from now. |
| + void Schedule(); |
| + |
| + private: |
| + void NotifyIfTime(); |
| + |
| + scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| + base::Closure closure_; |
| + base::TimeDelta delay_; |
| + base::TimeTicks next_notification_time_; |
| + bool notification_pending_; |
| + |
| + base::WeakPtrFactory<UniqueNotifier> weak_ptr_factory_; |
| +}; |
| + |
| +} // namespace cc |
| + |
| +#endif // CC_BASE_UNIQUE_NOTIFIER_H_ |