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 |