Commit 20cd03e4 authored by kylechar's avatar kylechar Committed by Commit bot

Add delay to FakeDisplayDelegate::Configure().

Display configuration takes some time on real devices. Add in a 200ms
delay from when Configure() is called to when the callback is triggered
so off device timing is similar to on device timing.

BUG=none

Review-Url: https://codereview.chromium.org/2527263002
Cr-Commit-Position: refs/heads/master@{#435553}
parent f1cc4784
......@@ -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;
} // 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
......@@ -9,8 +9,10 @@
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/timer/timer.h"
#include "ui/display/display_export.h"
#include "ui/display/fake_display_snapshot.h"
#include "ui/display/types/fake_display_controller.h"
......@@ -122,10 +124,17 @@ class DISPLAY_EXPORT FakeDisplayDelegate : public ui::NativeDisplayDelegate,
void OnConfigurationChanged();
private:
// Performs callback for Configure().
void ConfigureDone();
base::ObserverList<ui::NativeDisplayObserver> observers_;
std::vector<std::unique_ptr<ui::DisplaySnapshot>> displays_;
// If |Initialize()| has been called.
// Add delay before finished Configure().
base::OneShotTimer configure_timer_;
base::Closure configure_callback_;
// If Initialize() has been called.
bool initialized_ = false;
// The next available display id.
......
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