Commit 0a102872 authored by vmpstr@chromium.org's avatar vmpstr@chromium.org

cc: Add HasPendingNotification to delayed unique notifier.

It would be nice to know if a notification is pending, so this patch
adds this ability. This would be used in RenewTreePriority to detect
whether we should be in smoothness mode or same priority mode. That is,
if we have an expiration from smoothness pending, then we should still
be in smoothness mode.

R=reveman

Review URL: https://codereview.chromium.org/302003004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273780 0039d316-1c4b-4281-b951-d872f2087c98
parent b73427e7
......@@ -43,6 +43,10 @@ void DelayedUniqueNotifier::Cancel() {
next_notification_time_ = base::TimeTicks();
}
bool DelayedUniqueNotifier::HasPendingNotification() const {
return notification_pending_ && !next_notification_time_.is_null();
}
base::TimeTicks DelayedUniqueNotifier::Now() const {
return base::TimeTicks::Now();
}
......
......@@ -37,6 +37,9 @@ class CC_EXPORT DelayedUniqueNotifier {
// Cancel any previously scheduled runs.
void Cancel();
// Returns true if a notification is currently scheduled to run.
bool HasPendingNotification() const;
protected:
// Virtual for testing.
virtual base::TimeTicks Now() const;
......
......@@ -192,7 +192,7 @@ TEST_F(DelayedUniqueNotifierTest, RescheduleDelay) {
EXPECT_EQ(1, NotificationCount());
}
TEST_F(DelayedUniqueNotifierTest, Cancel) {
TEST_F(DelayedUniqueNotifierTest, CancelAndHasPendingNotification) {
base::TimeDelta delay = base::TimeDelta::FromInternalValue(20);
TestNotifier notifier(
task_runner_,
......@@ -206,9 +206,11 @@ TEST_F(DelayedUniqueNotifierTest, Cancel) {
notifier.Now() + base::TimeDelta::FromInternalValue(10);
notifier.SetNow(schedule_time);
notifier.Schedule();
EXPECT_TRUE(notifier.HasPendingNotification());
// Cancel the run.
notifier.Cancel();
EXPECT_FALSE(notifier.HasPendingNotification());
std::deque<base::TestPendingTask> tasks = TakePendingTasks();
......@@ -218,11 +220,13 @@ TEST_F(DelayedUniqueNotifierTest, Cancel) {
// Time to run, but a canceled task!
tasks[0].task.Run();
EXPECT_EQ(0, NotificationCount());
EXPECT_FALSE(notifier.HasPendingNotification());
tasks = TakePendingTasks();
EXPECT_EQ(0u, tasks.size());
notifier.Schedule();
EXPECT_TRUE(notifier.HasPendingNotification());
tasks = TakePendingTasks();
ASSERT_EQ(1u, tasks.size());
......@@ -231,14 +235,18 @@ TEST_F(DelayedUniqueNotifierTest, Cancel) {
// Advance the time.
notifier.SetNow(notifier.Now() + delay);
// This should run since it wasn't scheduled.
// This should run since it wasn't canceled.
tasks[0].task.Run();
EXPECT_EQ(1, NotificationCount());
EXPECT_FALSE(notifier.HasPendingNotification());
for (int i = 0; i < 10; ++i)
for (int i = 0; i < 10; ++i) {
notifier.Schedule();
EXPECT_TRUE(notifier.HasPendingNotification());
notifier.Cancel();
EXPECT_FALSE(notifier.HasPendingNotification());
}
notifier.Cancel();
tasks = TakePendingTasks();
ASSERT_EQ(1u, tasks.size());
......@@ -251,6 +259,7 @@ TEST_F(DelayedUniqueNotifierTest, Cancel) {
tasks = TakePendingTasks();
EXPECT_EQ(0u, tasks.size());
EXPECT_FALSE(notifier.HasPendingNotification());
}
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment