summaryrefslogtreecommitdiffstats
path: root/ui/display/chromeos
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 08:37:15 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 08:37:15 +0000
commitc53949a81a266c674cd1db0c951c7d7f49c8ac22 (patch)
tree9901c7f82b6646c6c0d3f1ed174ca7a984af018d /ui/display/chromeos
parent87ad2e5f411c04e6ba8bfdd66569c36935569e84 (diff)
downloadchromium_src-c53949a81a266c674cd1db0c951c7d7f49c8ac22.zip
chromium_src-c53949a81a266c674cd1db0c951c7d7f49c8ac22.tar.gz
chromium_src-c53949a81a266c674cd1db0c951c7d7f49c8ac22.tar.bz2
Check cache only durnig startup
- Made the expiration time longer (7s) - Removed AvoidNotificationOnDuplicateEvent test as it's testing basically the same thing as ForceUpdateAfterCacheExpiration. - this is formatted by "git cl format" BUG=350603 TEST=ForceUpdateAfterCacheExpiration has been updated Review URL: https://codereview.chromium.org/227433008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/display/chromeos')
-rw-r--r--ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc17
-rw-r--r--ui/display/chromeos/x11/native_display_event_dispatcher_x11.h7
-rw-r--r--ui/display/chromeos/x11/native_display_event_dispatcher_x11_unittest.cc51
3 files changed, 32 insertions, 43 deletions
diff --git a/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc b/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc
index 363fdb2..d42f561 100644
--- a/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc
+++ b/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc
@@ -13,14 +13,16 @@
namespace ui {
// static
-const int NativeDisplayEventDispatcherX11::kCachedOutputsExpirationMs = 5000;
+const int NativeDisplayEventDispatcherX11::kUseCacheAfterStartupMs = 7000;
NativeDisplayEventDispatcherX11::NativeDisplayEventDispatcherX11(
NativeDisplayDelegateX11::HelperDelegate* delegate,
int xrandr_event_base)
: delegate_(delegate),
xrandr_event_base_(xrandr_event_base),
- tick_clock_(new base::DefaultTickClock) {}
+ tick_clock_(new base::DefaultTickClock) {
+ startup_time_ = tick_clock_->NowTicks();
+}
NativeDisplayEventDispatcherX11::~NativeDisplayEventDispatcherX11() {}
@@ -58,10 +60,10 @@ uint32_t NativeDisplayEventDispatcherX11::DispatchEvent(
<< " mode=" << output_change_event->mode
<< " action=" << (connected ? "connected" : "disconnected");
- bool force_notify = last_notified_time_.is_null() ||
- (tick_clock_->NowTicks() - last_notified_time_).InMilliseconds() >=
- kCachedOutputsExpirationMs;
- if (!force_notify) {
+ bool check_cache = (tick_clock_->NowTicks() - startup_time_)
+ .InMilliseconds() <= kUseCacheAfterStartupMs;
+
+ if (check_cache) {
bool found_changed_output = false;
const std::vector<DisplaySnapshot*>& cached_outputs =
delegate_->GetCachedOutputs();
@@ -91,8 +93,6 @@ uint32_t NativeDisplayEventDispatcherX11::DispatchEvent(
}
}
- last_notified_time_ = tick_clock_->NowTicks();
-
delegate_->NotifyDisplayObservers();
return ui::POST_DISPATCH_PERFORM_DEFAULT;
@@ -101,6 +101,7 @@ uint32_t NativeDisplayEventDispatcherX11::DispatchEvent(
void NativeDisplayEventDispatcherX11::SetTickClockForTest(
scoped_ptr<base::TickClock> tick_clock) {
tick_clock_ = tick_clock.Pass();
+ startup_time_ = tick_clock_->NowTicks();
}
} // namespace ui
diff --git a/ui/display/chromeos/x11/native_display_event_dispatcher_x11.h b/ui/display/chromeos/x11/native_display_event_dispatcher_x11.h
index 9418813..e490074 100644
--- a/ui/display/chromeos/x11/native_display_event_dispatcher_x11.h
+++ b/ui/display/chromeos/x11/native_display_event_dispatcher_x11.h
@@ -30,8 +30,8 @@ class DISPLAY_EXPORT NativeDisplayEventDispatcherX11
void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock);
- // How long the cached output is valid.
- static const int kCachedOutputsExpirationMs;
+ // How long the cached output is valid after startup.
+ static const int kUseCacheAfterStartupMs;
private:
NativeDisplayDelegateX11::HelperDelegate* delegate_; // Not owned.
@@ -40,8 +40,7 @@ class DISPLAY_EXPORT NativeDisplayEventDispatcherX11
// decoding events regarding output add/remove.
int xrandr_event_base_;
- // The last time display observers were notified.
- base::TimeTicks last_notified_time_;
+ base::TimeTicks startup_time_;
scoped_ptr<base::TickClock> tick_clock_;
diff --git a/ui/display/chromeos/x11/native_display_event_dispatcher_x11_unittest.cc b/ui/display/chromeos/x11/native_display_event_dispatcher_x11_unittest.cc
index 9854ac8..d5cd5b1 100644
--- a/ui/display/chromeos/x11/native_display_event_dispatcher_x11_unittest.cc
+++ b/ui/display/chromeos/x11/native_display_event_dispatcher_x11_unittest.cc
@@ -18,9 +18,10 @@ namespace ui {
namespace {
-const DisplayModeX11 kDefaultDisplayMode(gfx::Size(1, 1), false, 60.0f, 20);
-
DisplaySnapshotX11* CreateOutput(RROutput output, RRCrtc crtc) {
+ static const DisplayModeX11* kDefaultDisplayMode =
+ new DisplayModeX11(gfx::Size(1, 1), false, 60.0f, 20);
+
DisplaySnapshotX11* snapshot = new DisplaySnapshotX11(
0,
false,
@@ -30,8 +31,8 @@ DisplaySnapshotX11* CreateOutput(RROutput output, RRCrtc crtc) {
false,
false,
std::string(),
- std::vector<const DisplayMode*>(1, &kDefaultDisplayMode),
- &kDefaultDisplayMode,
+ std::vector<const DisplayMode*>(1, kDefaultDisplayMode),
+ kDefaultDisplayMode,
NULL,
output,
crtc,
@@ -176,19 +177,6 @@ TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationAfterSecondEvent) {
EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers());
}
-TEST_F(NativeDisplayEventDispatcherX11Test, AvoidNotificationOnDuplicateEvent) {
- ScopedVector<DisplaySnapshot> outputs;
- outputs.push_back(CreateOutput(1, 10));
- helper_delegate_->set_cached_outputs(outputs.get());
-
- // Very first event will not be ignored.
- DispatchOutputChangeEvent(1, 10, 20, true);
- EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
-
- DispatchOutputChangeEvent(1, 10, 20, true);
- EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
-}
-
TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnDisconnect) {
ScopedVector<DisplaySnapshot> outputs;
outputs.push_back(CreateOutput(1, 10));
@@ -258,7 +246,7 @@ TEST_F(NativeDisplayEventDispatcherX11Test,
ForceUpdateAfterCacheExpiration) {
// +1 to compenstate a possible rounding error.
const int kHalfOfExpirationMs =
- NativeDisplayEventDispatcherX11::kCachedOutputsExpirationMs / 2 + 1;
+ NativeDisplayEventDispatcherX11::kUseCacheAfterStartupMs / 2 + 1;
ScopedVector<DisplaySnapshot> outputs;
outputs.push_back(CreateOutput(1, 10));
@@ -267,37 +255,38 @@ TEST_F(NativeDisplayEventDispatcherX11Test,
EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers());
+ // Duplicated event will be ignored during the startup.
DispatchOutputChangeEvent(2, 11, 20, true);
- EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
-
- // Duplicated event will be ignored.
- DispatchOutputChangeEvent(2, 11, 20, true);
- EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
+ EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers());
test_tick_clock_->Advance(base::TimeDelta::FromMilliseconds(
kHalfOfExpirationMs));
// Duplicated event will still be ignored.
DispatchOutputChangeEvent(2, 11, 20, true);
- EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
+ EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers());
- // Duplicated event does notify after expiration timeout.
+ // The startup timeout has been elapsed. Duplicated event
+ // should not be ignored.
test_tick_clock_->Advance(
base::TimeDelta::FromMilliseconds(kHalfOfExpirationMs));
DispatchOutputChangeEvent(2, 11, 20, true);
- EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers());
+ EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
- // Last update time has been updated, so next duplicated change event
- // will be ignored.
+ // Sending the same event immediately shoudldn't be ignored.
DispatchOutputChangeEvent(2, 11, 20, true);
EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers());
- // Another duplicated change event arrived within expiration time will
- // be ignored again.
+ // Advancing time further should not change the behavior.
test_tick_clock_->Advance(base::TimeDelta::FromMilliseconds(
kHalfOfExpirationMs));
DispatchOutputChangeEvent(2, 11, 20, true);
- EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers());
+ EXPECT_EQ(3, helper_delegate_->num_calls_notify_observers());
+
+ test_tick_clock_->Advance(
+ base::TimeDelta::FromMilliseconds(kHalfOfExpirationMs));
+ DispatchOutputChangeEvent(2, 11, 20, true);
+ EXPECT_EQ(4, helper_delegate_->num_calls_notify_observers());
}
} // namespace ui