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

Unified Diff: ui/display/fake_display_delegate.cc

Issue 2527263002: Add delay to FakeDisplayDelegate::Configure(). (Closed)
Patch Set: Created 4 years, 1 month 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 | « ui/display/fake_display_delegate.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/display/fake_display_delegate.cc
diff --git a/ui/display/fake_display_delegate.cc b/ui/display/fake_display_delegate.cc
index 5d202d4560c7660f5fdbea19f148fbdc30591d93..d11106dd95e920f9ab3ea82bad7be76117ebde6e 100644
--- a/ui/display/fake_display_delegate.cc
+++ b/ui/display/fake_display_delegate.cc
@@ -15,6 +15,7 @@
#include "base/memory/ptr_util.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
+#include "base/time/time.h"
#include "ui/display/display.h"
#include "ui/display/display_switches.h"
#include "ui/display/types/display_constants.h"
@@ -31,6 +32,9 @@ const uint16_t kReservedManufacturerID = 1 << 15;
// A random product name hash.
const uint32_t kProductCodeHash = base::Hash("Very Generic Display");
+// Delay for Configure() in milliseconds.
+constexpr int64_t kConfigureDisplayDelayMs = 200;
rjkroege 2016/11/29 19:12:32 idea: how about making it a random variable? To be
kylechar 2016/11/29 21:51:41 That would neat to enable but I don't think tests
kylechar 2016/12/01 03:43:09 Will land as is for now. I'll add random delay opt
+
} // namespace
FakeDisplayDelegate::FakeDisplayDelegate() {}
@@ -142,15 +146,25 @@ void FakeDisplayDelegate::Configure(const ui::DisplaySnapshot& output,
const ui::DisplayMode* mode,
const gfx::Point& origin,
const ui::ConfigureCallback& callback) {
- // Check the display mode is appropriate for the display snapshot.
- for (const auto& existing_mode : output.modes()) {
- if (existing_mode.get() == mode) {
- callback.Run(true);
- return;
+ bool configure_success = false;
+
+ if (!mode) {
+ // This is a request to turn off the display.
+ configure_success = true;
+ } else {
+ // Check that |mode| is appropriate for the display snapshot.
+ for (const auto& existing_mode : output.modes()) {
+ if (existing_mode.get() == mode) {
+ configure_success = true;
+ break;
+ }
}
}
- callback.Run(false);
+ configure_callback_ = base::Bind(callback, configure_success);
+ configure_timer_.Start(
+ FROM_HERE, base::TimeDelta::FromMilliseconds(kConfigureDisplayDelayMs),
+ this, &FakeDisplayDelegate::ConfigureDone);
}
void FakeDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {}
@@ -197,7 +211,7 @@ void FakeDisplayDelegate::RemoveObserver(ui::NativeDisplayObserver* observer) {
}
FakeDisplayController* FakeDisplayDelegate::GetFakeDisplayController() {
- return static_cast<FakeDisplayController*>(this);
+ return this;
}
bool FakeDisplayDelegate::InitializeFromSpecString(const std::string& str) {
@@ -232,4 +246,10 @@ void FakeDisplayDelegate::OnConfigurationChanged() {
observer.OnConfigurationChanged();
}
+void FakeDisplayDelegate::ConfigureDone() {
+ DCHECK(!configure_callback_.is_null());
+ configure_callback_.Run();
+ configure_callback_.Reset();
+}
+
} // namespace display
« no previous file with comments | « ui/display/fake_display_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698