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 // Don't (potentially) queue a second task to run MoveToTouchDisplay if one |
| 36 // already is queued. |
| 37 if (weak_ptr_factory_.HasWeakPtrs()) |
| 38 return; |
| 39 |
30 display::Display primary_display = | 40 display::Display primary_display = |
31 display::Screen::GetScreen()->GetPrimaryDisplay(); | 41 display::Screen::GetScreen()->GetPrimaryDisplay(); |
32 | 42 |
33 if (primary_display.is_valid() && !TouchSupportAvailable(primary_display)) | 43 if (primary_display.is_valid() && !TouchSupportAvailable(primary_display)) { |
34 MoveToTouchDisplay(); | 44 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 45 base::Bind(&OobeDisplayChooser::MoveToTouchDisplay, |
| 46 weak_ptr_factory_.GetWeakPtr())); |
| 47 } |
35 } | 48 } |
36 | 49 |
37 void OobeDisplayChooser::MoveToTouchDisplay() { | 50 void OobeDisplayChooser::MoveToTouchDisplay() { |
| 51 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 52 |
38 const display::Displays& displays = | 53 const display::Displays& displays = |
39 ash::Shell::Get()->display_manager()->active_only_display_list(); | 54 ash::Shell::Get()->display_manager()->active_only_display_list(); |
40 | 55 |
41 if (displays.size() <= 1) | 56 if (displays.size() <= 1) |
42 return; | 57 return; |
43 | 58 |
44 for (const display::Display& display : displays) { | 59 for (const display::Display& display : displays) { |
45 if (TouchSupportAvailable(display)) { | 60 if (TouchSupportAvailable(display)) { |
46 ash::Shell::Get() | 61 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
47 ->display_configuration_controller() | 62 display.id()); |
48 ->SetPrimaryDisplayId(display.id()); | |
49 break; | 63 break; |
50 } | 64 } |
51 } | 65 } |
52 } | 66 } |
53 | 67 |
54 } // namespace chromeos | 68 } // namespace chromeos |
OLD | NEW |