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

Side by Side Diff: ui/display/fake_display_delegate.cc

Issue 2527263002: Add delay to FakeDisplayDelegate::Configure(). (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
« no previous file with comments | « ui/display/fake_display_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/display/fake_display_delegate.h" 5 #include "ui/display/fake_display_delegate.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/hash.h" 13 #include "base/hash.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/time/time.h"
18 #include "ui/display/display.h" 19 #include "ui/display/display.h"
19 #include "ui/display/display_switches.h" 20 #include "ui/display/display_switches.h"
20 #include "ui/display/types/display_constants.h" 21 #include "ui/display/types/display_constants.h"
21 #include "ui/display/types/native_display_observer.h" 22 #include "ui/display/types/native_display_observer.h"
22 #include "ui/display/util/display_util.h" 23 #include "ui/display/util/display_util.h"
23 24
24 namespace display { 25 namespace display {
25 26
26 namespace { 27 namespace {
27 28
28 // The EDID specification marks the top bit of the manufacturer id as reserved. 29 // The EDID specification marks the top bit of the manufacturer id as reserved.
29 const uint16_t kReservedManufacturerID = 1 << 15; 30 const uint16_t kReservedManufacturerID = 1 << 15;
30 31
31 // A random product name hash. 32 // A random product name hash.
32 const uint32_t kProductCodeHash = base::Hash("Very Generic Display"); 33 const uint32_t kProductCodeHash = base::Hash("Very Generic Display");
33 34
35 // Delay for Configure() in milliseconds.
36 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
37
34 } // namespace 38 } // namespace
35 39
36 FakeDisplayDelegate::FakeDisplayDelegate() {} 40 FakeDisplayDelegate::FakeDisplayDelegate() {}
37 41
38 FakeDisplayDelegate::~FakeDisplayDelegate() {} 42 FakeDisplayDelegate::~FakeDisplayDelegate() {}
39 43
40 int64_t FakeDisplayDelegate::AddDisplay(const gfx::Size& display_size) { 44 int64_t FakeDisplayDelegate::AddDisplay(const gfx::Size& display_size) {
41 DCHECK(!display_size.IsEmpty()); 45 DCHECK(!display_size.IsEmpty());
42 46
43 if (next_display_id_ == 0xFF) { 47 if (next_display_id_ == 0xFF) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 callback.Run(displays); 139 callback.Run(displays);
136 } 140 }
137 141
138 void FakeDisplayDelegate::AddMode(const ui::DisplaySnapshot& output, 142 void FakeDisplayDelegate::AddMode(const ui::DisplaySnapshot& output,
139 const ui::DisplayMode* mode) {} 143 const ui::DisplayMode* mode) {}
140 144
141 void FakeDisplayDelegate::Configure(const ui::DisplaySnapshot& output, 145 void FakeDisplayDelegate::Configure(const ui::DisplaySnapshot& output,
142 const ui::DisplayMode* mode, 146 const ui::DisplayMode* mode,
143 const gfx::Point& origin, 147 const gfx::Point& origin,
144 const ui::ConfigureCallback& callback) { 148 const ui::ConfigureCallback& callback) {
145 // Check the display mode is appropriate for the display snapshot. 149 bool configure_success = false;
146 for (const auto& existing_mode : output.modes()) { 150
147 if (existing_mode.get() == mode) { 151 if (!mode) {
148 callback.Run(true); 152 // This is a request to turn off the display.
149 return; 153 configure_success = true;
154 } else {
155 // Check that |mode| is appropriate for the display snapshot.
156 for (const auto& existing_mode : output.modes()) {
157 if (existing_mode.get() == mode) {
158 configure_success = true;
159 break;
160 }
150 } 161 }
151 } 162 }
152 163
153 callback.Run(false); 164 configure_callback_ = base::Bind(callback, configure_success);
165 configure_timer_.Start(
166 FROM_HERE, base::TimeDelta::FromMilliseconds(kConfigureDisplayDelayMs),
167 this, &FakeDisplayDelegate::ConfigureDone);
154 } 168 }
155 169
156 void FakeDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {} 170 void FakeDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {}
157 171
158 void FakeDisplayDelegate::GetHDCPState( 172 void FakeDisplayDelegate::GetHDCPState(
159 const ui::DisplaySnapshot& output, 173 const ui::DisplaySnapshot& output,
160 const ui::GetHDCPStateCallback& callback) { 174 const ui::GetHDCPStateCallback& callback) {
161 callback.Run(false, ui::HDCP_STATE_UNDESIRED); 175 callback.Run(false, ui::HDCP_STATE_UNDESIRED);
162 } 176 }
163 177
(...skipping 26 matching lines...) Expand all
190 204
191 void FakeDisplayDelegate::AddObserver(ui::NativeDisplayObserver* observer) { 205 void FakeDisplayDelegate::AddObserver(ui::NativeDisplayObserver* observer) {
192 observers_.AddObserver(observer); 206 observers_.AddObserver(observer);
193 } 207 }
194 208
195 void FakeDisplayDelegate::RemoveObserver(ui::NativeDisplayObserver* observer) { 209 void FakeDisplayDelegate::RemoveObserver(ui::NativeDisplayObserver* observer) {
196 observers_.RemoveObserver(observer); 210 observers_.RemoveObserver(observer);
197 } 211 }
198 212
199 FakeDisplayController* FakeDisplayDelegate::GetFakeDisplayController() { 213 FakeDisplayController* FakeDisplayDelegate::GetFakeDisplayController() {
200 return static_cast<FakeDisplayController*>(this); 214 return this;
201 } 215 }
202 216
203 bool FakeDisplayDelegate::InitializeFromSpecString(const std::string& str) { 217 bool FakeDisplayDelegate::InitializeFromSpecString(const std::string& str) {
204 // Start without any displays. 218 // Start without any displays.
205 if (str == "none") 219 if (str == "none")
206 return true; 220 return true;
207 221
208 // Split on commas and parse each display string. 222 // Split on commas and parse each display string.
209 for (const std::string& part : base::SplitString( 223 for (const std::string& part : base::SplitString(
210 str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 224 str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
(...skipping 14 matching lines...) Expand all
225 } 239 }
226 240
227 void FakeDisplayDelegate::OnConfigurationChanged() { 241 void FakeDisplayDelegate::OnConfigurationChanged() {
228 if (!initialized_) 242 if (!initialized_)
229 return; 243 return;
230 244
231 for (ui::NativeDisplayObserver& observer : observers_) 245 for (ui::NativeDisplayObserver& observer : observers_)
232 observer.OnConfigurationChanged(); 246 observer.OnConfigurationChanged();
233 } 247 }
234 248
249 void FakeDisplayDelegate::ConfigureDone() {
250 DCHECK(!configure_callback_.is_null());
251 configure_callback_.Run();
252 configure_callback_.Reset();
253 }
254
235 } // namespace display 255 } // namespace display
OLDNEW
« 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