Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h" |
| 6 | 6 |
| 7 #include "ash/display/display_configuration_controller.h" | 7 #include "ash/display/window_tree_host_manager.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "content/public/browser/browser_thread.h" | |
| 9 #include "ui/display/display.h" | 10 #include "ui/display/display.h" |
| 10 #include "ui/display/display_layout.h" | 11 #include "ui/display/display_layout.h" |
| 11 #include "ui/display/manager/display_manager.h" | 12 #include "ui/display/manager/display_manager.h" |
| 12 #include "ui/display/screen.h" | 13 #include "ui/display/screen.h" |
| 13 | 14 |
| 15 using content::BrowserThread; | |
| 16 | |
| 14 namespace chromeos { | 17 namespace chromeos { |
| 15 | 18 |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| 18 bool TouchSupportAvailable(const display::Display& display) { | 21 bool TouchSupportAvailable(const display::Display& display) { |
| 19 return display.touch_support() == | 22 return display.touch_support() == |
| 20 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE; | 23 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE; |
| 21 } | 24 } |
| 22 | 25 |
| 23 } // namespace | 26 } // namespace |
| 24 | 27 |
| 25 OobeDisplayChooser::OobeDisplayChooser() {} | 28 OobeDisplayChooser::OobeDisplayChooser() : weak_ptr_factory_(this) {} |
| 26 | 29 |
| 27 OobeDisplayChooser::~OobeDisplayChooser() {} | 30 OobeDisplayChooser::~OobeDisplayChooser() {} |
| 28 | 31 |
| 29 void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() { | 32 void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() { |
| 33 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 34 | |
| 35 if (display_switch_requested_) | |
|
oshima
2017/05/17 16:56:18
Instead, can you check if the weak_ptr_factory_ ha
| |
| 36 return; | |
| 37 | |
| 30 display::Display primary_display = | 38 display::Display primary_display = |
| 31 display::Screen::GetScreen()->GetPrimaryDisplay(); | 39 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 32 | 40 |
| 33 if (primary_display.is_valid() && !TouchSupportAvailable(primary_display)) | 41 if (primary_display.is_valid() && !TouchSupportAvailable(primary_display)) { |
| 34 MoveToTouchDisplay(); | 42 display_switch_requested_ = true; |
| 43 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 44 base::Bind(&OobeDisplayChooser::MoveToTouchDisplay, | |
| 45 weak_ptr_factory_.GetWeakPtr())); | |
| 46 } | |
| 35 } | 47 } |
| 36 | 48 |
| 37 void OobeDisplayChooser::MoveToTouchDisplay() { | 49 void OobeDisplayChooser::MoveToTouchDisplay() { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 51 | |
| 52 display_switch_requested_ = false; | |
| 53 | |
| 38 const display::Displays& displays = | 54 const display::Displays& displays = |
| 39 ash::Shell::Get()->display_manager()->active_only_display_list(); | 55 ash::Shell::Get()->display_manager()->active_only_display_list(); |
| 40 | 56 |
| 41 if (displays.size() <= 1) | 57 if (displays.size() <= 1) |
| 42 return; | 58 return; |
| 43 | 59 |
| 44 for (const display::Display& display : displays) { | 60 for (const display::Display& display : displays) { |
| 45 if (TouchSupportAvailable(display)) { | 61 if (TouchSupportAvailable(display)) { |
| 46 ash::Shell::Get() | 62 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
| 47 ->display_configuration_controller() | 63 display.id()); |
| 48 ->SetPrimaryDisplayId(display.id()); | |
| 49 break; | 64 break; |
| 50 } | 65 } |
| 51 } | 66 } |
| 52 } | 67 } |
| 53 | 68 |
| 54 } // namespace chromeos | 69 } // namespace chromeos |
| OLD | NEW |