Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3385)

Unified Diff: cc/base/delayed_unique_notifier.h

Issue 296043005: cc: Add UniqueNotifier to cc/base. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cc/base/delayed_unique_notifier.cc » ('j') | cc/base/delayed_unique_notifier_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/delayed_unique_notifier.h
diff --git a/cc/base/delayed_unique_notifier.h b/cc/base/delayed_unique_notifier.h
new file mode 100644
index 0000000000000000000000000000000000000000..d639ebc9a30baca627ec5be990c1cfdb1a08f32e
--- /dev/null
+++ b/cc/base/delayed_unique_notifier.h
@@ -0,0 +1,54 @@
+// 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_DELAYED_UNIQUE_NOTIFIER_H_
+#define CC_BASE_DELAYED_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 DelayedUniqueNotifier {
+ public:
+ // Configure this notifier to issue the |closure| notification in |delay| time
+ // from Schedule() call.
+ DelayedUniqueNotifier(base::SequencedTaskRunner* task_runner,
+ const base::Closure& closure,
+ const base::TimeDelta& delay);
+
+ // Destroying the notifier will ensure that no further notifications will
+ // happen from this class.
+ ~DelayedUniqueNotifier();
+
+ // Schedule a notification to be run. If another notification is already
+ // pending, then it will happen in (at least) given delay from now. That is,
+ // if delay is 16ms and a notification has been scheduled 10ms ago (ie, it
+ // should trigger in no less than 6ms), then calling schedule will ensure that
+ // the only notification that arrives will happen in (at least) 16ms from now.
+ void Schedule();
+
+ // Cancel any previously scheduled runs.
+ void Cancel();
+
+ private:
+ void NotifyIfTime();
+
+ base::SequencedTaskRunner* task_runner_;
+ base::Closure closure_;
+ base::TimeDelta delay_;
+ base::TimeTicks next_notification_time_;
+ bool notification_pending_;
+
+ base::WeakPtrFactory<DelayedUniqueNotifier> weak_ptr_factory_;
+};
+
+} // namespace cc
+
+#endif // CC_BASE_DELAYED_UNIQUE_NOTIFIER_H_
« no previous file with comments | « no previous file | cc/base/delayed_unique_notifier.cc » ('j') | cc/base/delayed_unique_notifier_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698