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

Side by Side Diff: ash/display/resolution_notification_controller.cc

Issue 2799963003: Fix errors in display resolution change notifications (Closed)
Patch Set: Update commit message Created 3 years, 8 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/display/resolution_notification_controller.h" 5 #include "ash/display/resolution_notification_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/resources/grit/ash_resources.h" 9 #include "ash/resources/grit/ash_resources.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ResolutionNotificationController::ResolutionNotificationController() { 155 ResolutionNotificationController::ResolutionNotificationController() {
156 Shell::Get()->window_tree_host_manager()->AddObserver(this); 156 Shell::Get()->window_tree_host_manager()->AddObserver(this);
157 display::Screen::GetScreen()->AddObserver(this); 157 display::Screen::GetScreen()->AddObserver(this);
158 } 158 }
159 159
160 ResolutionNotificationController::~ResolutionNotificationController() { 160 ResolutionNotificationController::~ResolutionNotificationController() {
161 Shell::Get()->window_tree_host_manager()->RemoveObserver(this); 161 Shell::Get()->window_tree_host_manager()->RemoveObserver(this);
162 display::Screen::GetScreen()->RemoveObserver(this); 162 display::Screen::GetScreen()->RemoveObserver(this);
163 } 163 }
164 164
165 void ResolutionNotificationController::PrepareNotification( 165 bool ResolutionNotificationController::PrepareNotificationAndSetDisplayMode(
166 int64_t display_id, 166 int64_t display_id,
167 const scoped_refptr<display::ManagedDisplayMode>& old_resolution, 167 const scoped_refptr<display::ManagedDisplayMode>& old_resolution,
168 const scoped_refptr<display::ManagedDisplayMode>& new_resolution, 168 const scoped_refptr<display::ManagedDisplayMode>& new_resolution,
169 const base::Closure& accept_callback) { 169 const base::Closure& accept_callback) {
170 DCHECK(old_resolution); 170 DCHECK(old_resolution);
171 DCHECK(new_resolution); 171 DCHECK(new_resolution);
172 172
173 DCHECK(!display::Display::IsInternalDisplayId(display_id)); 173 display::DisplayManager* const display_manager =
174 Shell::Get()->display_manager();
175 if (display::Display::IsInternalDisplayId(display_id)) {
176 // We don't show notifications to confirm/revert the resolution change in
177 // the case of an internal display.
178 return display_manager->SetDisplayMode(display_id, new_resolution);
179 }
180
174 // If multiple resolution changes are invoked for the same display, 181 // If multiple resolution changes are invoked for the same display,
175 // the original resolution for the first resolution change has to be used 182 // the original resolution for the first resolution change has to be used
176 // instead of the specified |old_resolution|. 183 // instead of the specified |old_resolution|.
177 scoped_refptr<display::ManagedDisplayMode> original_resolution; 184 scoped_refptr<display::ManagedDisplayMode> original_resolution;
178 if (change_info_ && change_info_->display_id == display_id) { 185 if (change_info_ && change_info_->display_id == display_id) {
179 DCHECK(change_info_->new_resolution->size() == old_resolution->size()); 186 DCHECK(change_info_->new_resolution->size() == old_resolution->size());
180 original_resolution = change_info_->old_resolution; 187 original_resolution = change_info_->old_resolution;
181 } 188 }
182 189
183 if (change_info_ && change_info_->display_id != display_id) { 190 if (change_info_ && change_info_->display_id != display_id) {
184 // Preparing the notification for a new resolution change of another display 191 // Preparing the notification for a new resolution change of another display
185 // before the previous one was accepted. We decided that it's safer to 192 // before the previous one was accepted. We decided that it's safer to
186 // revert the previous resolution change since the user didn't explicitly 193 // revert the previous resolution change since the user didn't explicitly
187 // accept it, and we have no way of knowing for sure that it worked. 194 // accept it, and we have no way of knowing for sure that it worked.
188 RevertResolutionChange(false /* display_was_removed */); 195 RevertResolutionChange(false /* display_was_removed */);
189 } 196 }
190 197
191 change_info_.reset(new ResolutionChangeInfo(display_id, old_resolution, 198 change_info_.reset(new ResolutionChangeInfo(display_id, old_resolution,
192 new_resolution, accept_callback)); 199 new_resolution, accept_callback));
193 if (original_resolution && !original_resolution->size().IsEmpty()) 200 if (original_resolution && !original_resolution->size().IsEmpty())
194 change_info_->old_resolution = original_resolution; 201 change_info_->old_resolution = original_resolution;
202
203 if (!display_manager->SetDisplayMode(display_id, new_resolution)) {
204 // Discard the prepared notification data since we failed to set the new
205 // resolution.
206 change_info_.reset();
207 return false;
208 }
209
210 return true;
195 } 211 }
196 212
197 bool ResolutionNotificationController::DoesNotificationTimeout() { 213 bool ResolutionNotificationController::DoesNotificationTimeout() {
198 return change_info_ && change_info_->timeout_count > 0; 214 return change_info_ && change_info_->timeout_count > 0;
199 } 215 }
200 216
201 void ResolutionNotificationController::CreateOrUpdateNotification( 217 void ResolutionNotificationController::CreateOrUpdateNotification(
202 bool enable_spoken_feedback) { 218 bool enable_spoken_feedback) {
203 message_center::MessageCenter* message_center = 219 message_center::MessageCenter* message_center =
204 message_center::MessageCenter::Get(); 220 message_center::MessageCenter::Get();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 change_info_->timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this, 342 change_info_->timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this,
327 &ResolutionNotificationController::OnTimerTick); 343 &ResolutionNotificationController::OnTimerTick);
328 } 344 }
329 } 345 }
330 346
331 void ResolutionNotificationController::SuppressTimerForTest() { 347 void ResolutionNotificationController::SuppressTimerForTest() {
332 g_use_timer = false; 348 g_use_timer = false;
333 } 349 }
334 350
335 } // namespace ash 351 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/resolution_notification_controller.h ('k') | ash/display/resolution_notification_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698