summaryrefslogtreecommitdiffstats
path: root/cc/base
diff options
context:
space:
mode:
authorvmpstr <vmpstr@chromium.org>2015-07-01 14:47:47 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-01 21:48:14 +0000
commit8c53b7f9ca19b3d5d695e76bb9d0c08d634e493c (patch)
tree7d16cce2861347bafe69b3d0122eb3bf0e928d29 /cc/base
parenta00726eba3b60a8c0d45ec2f021eb0243ed61fe7 (diff)
downloadchromium_src-8c53b7f9ca19b3d5d695e76bb9d0c08d634e493c.zip
chromium_src-8c53b7f9ca19b3d5d695e76bb9d0c08d634e493c.tar.gz
chromium_src-8c53b7f9ca19b3d5d695e76bb9d0c08d634e493c.tar.bz2
cc: Add cancel functionality to unique notifier.
This patch adds a Cancel function to UniqueNotifier that can be used to cancel a task. Currently the only way to get this behavior is to destroy the UniqueNotifier. R=enne CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1218173007 Cr-Commit-Position: refs/heads/master@{#337120}
Diffstat (limited to 'cc/base')
-rw-r--r--cc/base/unique_notifier.cc7
-rw-r--r--cc/base/unique_notifier.h3
-rw-r--r--cc/base/unique_notifier_unittest.cc16
3 files changed, 25 insertions, 1 deletions
diff --git a/cc/base/unique_notifier.cc b/cc/base/unique_notifier.cc
index 0656c6d..eb0b09a 100644
--- a/cc/base/unique_notifier.cc
+++ b/cc/base/unique_notifier.cc
@@ -22,6 +22,10 @@ UniqueNotifier::UniqueNotifier(base::SequencedTaskRunner* task_runner,
UniqueNotifier::~UniqueNotifier() {
}
+void UniqueNotifier::Cancel() {
+ notification_pending_ = false;
+}
+
void UniqueNotifier::Schedule() {
if (notification_pending_)
return;
@@ -33,6 +37,9 @@ void UniqueNotifier::Schedule() {
}
void UniqueNotifier::Notify() {
+ if (!notification_pending_)
+ return;
+
// Note that the order here is important in case closure schedules another
// run.
notification_pending_ = false;
diff --git a/cc/base/unique_notifier.h b/cc/base/unique_notifier.h
index 9a4a02c..3cbc22a 100644
--- a/cc/base/unique_notifier.h
+++ b/cc/base/unique_notifier.h
@@ -29,6 +29,9 @@ class CC_EXPORT UniqueNotifier {
// pending, then only one notification will take place.
void Schedule();
+ // Cancel a pending notification, if one was scheduled.
+ void Cancel();
+
private:
void Notify();
diff --git a/cc/base/unique_notifier_unittest.cc b/cc/base/unique_notifier_unittest.cc
index 7b52512..b53b52a 100644
--- a/cc/base/unique_notifier_unittest.cc
+++ b/cc/base/unique_notifier_unittest.cc
@@ -50,12 +50,26 @@ TEST_F(UniqueNotifierTest, Schedule) {
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, NotificationCount());
+ // Schedule and cancel.
+ notifier.Schedule();
+ notifier.Cancel();
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(2, NotificationCount());
+
+ notifier.Schedule();
+ notifier.Cancel();
+ notifier.Schedule();
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(3, NotificationCount());
+
notifier.Schedule();
}
// Notifier went out of scope, so we don't expect to get a notification.
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(2, NotificationCount());
+ EXPECT_EQ(3, NotificationCount());
}
} // namespace