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

Side by Side Diff: chrome/browser/chromeos/login/screens/hid_detection_screen.cc

Issue 2638123002: cros: Fold HIDDetectionModel into HIDDetectionScreen. (Closed)
Patch Set: Initial upload Created 3 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/login/screens/hid_detection_screen.h" 5 #include "chrome/browser/chromeos/login/screens/hid_detection_screen.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 bool DeviceIsKeyboard(device::BluetoothDeviceType device_type) { 43 bool DeviceIsKeyboard(device::BluetoothDeviceType device_type) {
44 return device_type == device::BluetoothDeviceType::KEYBOARD || 44 return device_type == device::BluetoothDeviceType::KEYBOARD ||
45 device_type == device::BluetoothDeviceType::KEYBOARD_MOUSE_COMBO; 45 device_type == device::BluetoothDeviceType::KEYBOARD_MOUSE_COMBO;
46 } 46 }
47 47
48 } // namespace 48 } // namespace
49 49
50 namespace chromeos { 50 namespace chromeos {
51 51
52 const char HIDDetectionScreen::kContextKeyKeyboardState[] = "keyboard-state";
53 const char HIDDetectionScreen::kContextKeyMouseState[] = "mouse-state";
54 const char HIDDetectionScreen::kContextKeyPinCode[] = "keyboard-pincode";
55 const char HIDDetectionScreen::kContextKeyNumKeysEnteredExpected[] =
56 "num-keys-entered-expected";
57 const char HIDDetectionScreen::kContextKeyNumKeysEnteredPinCode[] =
58 "num-keys-entered-pincode";
59 const char HIDDetectionScreen::kContextKeyMouseDeviceName[] =
60 "mouse-device-name";
61 const char HIDDetectionScreen::kContextKeyKeyboardDeviceName[] =
62 "keyboard-device-name";
63 const char HIDDetectionScreen::kContextKeyKeyboardLabel[] =
64 "keyboard-device-label";
65 const char HIDDetectionScreen::kContextKeyContinueButtonEnabled[] =
66 "continue-button-enabled";
67
52 HIDDetectionScreen::HIDDetectionScreen(BaseScreenDelegate* base_screen_delegate, 68 HIDDetectionScreen::HIDDetectionScreen(BaseScreenDelegate* base_screen_delegate,
53 HIDDetectionView* view) 69 HIDDetectionView* view)
54 : HIDDetectionModel(base_screen_delegate), 70 : BaseScreen(base_screen_delegate, OobeScreen::SCREEN_OOBE_HID_DETECTION),
55 view_(view), 71 view_(view),
56 weak_ptr_factory_(this) { 72 weak_ptr_factory_(this) {
57 DCHECK(view_); 73 DCHECK(view_);
58 if (view_) 74 if (view_)
59 view_->Bind(*this); 75 view_->Bind(this);
60 76
61 device::BluetoothAdapterFactory::GetAdapter(base::Bind( 77 device::BluetoothAdapterFactory::GetAdapter(base::Bind(
62 &HIDDetectionScreen::InitializeAdapter, weak_ptr_factory_.GetWeakPtr())); 78 &HIDDetectionScreen::InitializeAdapter, weak_ptr_factory_.GetWeakPtr()));
63 } 79 }
64 80
65 HIDDetectionScreen::~HIDDetectionScreen() { 81 HIDDetectionScreen::~HIDDetectionScreen() {
66 adapter_initially_powered_.reset(); 82 adapter_initially_powered_.reset();
67 input_service_proxy_.RemoveObserver(this); 83 input_service_proxy_.RemoveObserver(this);
68 if (view_) 84 if (view_)
69 view_->Unbind(); 85 view_->Unbind();
70 if (discovery_session_.get()) 86 if (discovery_session_.get())
71 discovery_session_->Stop(base::Bind(&base::DoNothing), 87 discovery_session_->Stop(base::Bind(&base::DoNothing),
72 base::Bind(&base::DoNothing)); 88 base::Bind(&base::DoNothing));
73 if (adapter_.get()) 89 if (adapter_.get())
74 adapter_->RemoveObserver(this); 90 adapter_->RemoveObserver(this);
75 } 91 }
76 92
77 void HIDDetectionScreen::Show() {
78 showing_ = true;
79 GetContextEditor().SetBoolean(kContextKeyNumKeysEnteredExpected, false);
80 SendPointingDeviceNotification();
81 SendKeyboardDeviceNotification();
82
83 input_service_proxy_.AddObserver(this);
84 UpdateDevices();
85
86 if (view_)
87 view_->Show();
88 }
89
90 void HIDDetectionScreen::Hide() {
91 showing_ = false;
92 input_service_proxy_.RemoveObserver(this);
93 if (discovery_session_.get())
94 discovery_session_->Stop(base::Bind(&base::DoNothing),
95 base::Bind(&base::DoNothing));
96 if (view_)
97 view_->Hide();
98 }
99
100 void HIDDetectionScreen::OnContinueButtonClicked() { 93 void HIDDetectionScreen::OnContinueButtonClicked() {
101
102 ContinueScenarioType scenario_type; 94 ContinueScenarioType scenario_type;
103 if (!pointing_device_id_.empty() && !keyboard_device_id_.empty()) 95 if (!pointing_device_id_.empty() && !keyboard_device_id_.empty())
104 scenario_type = All_DEVICES_DETECTED; 96 scenario_type = All_DEVICES_DETECTED;
105 else if (pointing_device_id_.empty()) 97 else if (pointing_device_id_.empty())
106 scenario_type = KEYBOARD_DEVICE_ONLY_DETECTED; 98 scenario_type = KEYBOARD_DEVICE_ONLY_DETECTED;
107 else 99 else
108 scenario_type = POINTING_DEVICE_ONLY_DETECTED; 100 scenario_type = POINTING_DEVICE_ONLY_DETECTED;
109 101
110 UMA_HISTOGRAM_ENUMERATION( 102 UMA_HISTOGRAM_ENUMERATION(
111 "HIDDetection.OOBEDevicesDetectedOnContinuePressed", 103 "HIDDetection.OOBEDevicesDetectedOnContinuePressed",
112 scenario_type, 104 scenario_type,
113 CONTINUE_SCENARIO_TYPE_SIZE); 105 CONTINUE_SCENARIO_TYPE_SIZE);
114 106
115 // Switch off BT adapter if it was off before the screen and no BT device 107 // Switch off BT adapter if it was off before the screen and no BT device
116 // connected. 108 // connected.
117 const bool adapter_is_powered = 109 const bool adapter_is_powered =
118 adapter_.get() && adapter_->IsPresent() && adapter_->IsPowered(); 110 adapter_.get() && adapter_->IsPresent() && adapter_->IsPowered();
119 const bool need_switching_off = 111 const bool need_switching_off =
120 adapter_initially_powered_ && !(*adapter_initially_powered_); 112 adapter_initially_powered_ && !(*adapter_initially_powered_);
121 if (adapter_is_powered && need_switching_off) { 113 if (adapter_is_powered && need_switching_off) {
122 input_service_proxy_.GetDevices( 114 input_service_proxy_.GetDevices(
123 base::Bind(&HIDDetectionScreen::OnGetInputDevicesForPowerOff, 115 base::Bind(&HIDDetectionScreen::OnGetInputDevicesForPowerOff,
124 weak_ptr_factory_.GetWeakPtr())); 116 weak_ptr_factory_.GetWeakPtr()));
125 } 117 }
126 118
127 Finish(BaseScreenDelegate::HID_DETECTION_COMPLETED); 119 Finish(BaseScreenDelegate::HID_DETECTION_COMPLETED);
128 } 120 }
129 121
122 void HIDDetectionScreen::OnViewDestroyed(HIDDetectionView* view) {
123 if (view_ == view)
124 view_ = nullptr;
125 }
126
130 void HIDDetectionScreen::CheckIsScreenRequired( 127 void HIDDetectionScreen::CheckIsScreenRequired(
131 const base::Callback<void(bool)>& on_check_done) { 128 const base::Callback<void(bool)>& on_check_done) {
132 input_service_proxy_.GetDevices( 129 input_service_proxy_.GetDevices(
133 base::Bind(&HIDDetectionScreen::OnGetInputDevicesListForCheck, 130 base::Bind(&HIDDetectionScreen::OnGetInputDevicesListForCheck,
134 weak_ptr_factory_.GetWeakPtr(), 131 weak_ptr_factory_.GetWeakPtr(),
135 on_check_done)); 132 on_check_done));
136 } 133 }
137 134
138 void HIDDetectionScreen::OnViewDestroyed(HIDDetectionView* view) { 135 void HIDDetectionScreen::Show() {
139 if (view_ == view) 136 showing_ = true;
140 view_ = NULL; 137 GetContextEditor().SetBoolean(kContextKeyNumKeysEnteredExpected, false);
138 SendPointingDeviceNotification();
139 SendKeyboardDeviceNotification();
140
141 input_service_proxy_.AddObserver(this);
142 UpdateDevices();
143
144 if (view_)
145 view_->Show();
146 }
147
148 void HIDDetectionScreen::Hide() {
149 showing_ = false;
150 input_service_proxy_.RemoveObserver(this);
151 if (discovery_session_.get()) {
152 discovery_session_->Stop(base::Bind(&base::DoNothing),
achuithb 2017/01/18 23:19:46 curious: do you need the base::Bind here?
jdufault 2017/01/20 18:57:21 Yep; base::DoNothing is just an empty function.
achuithb 2017/01/20 19:18:38 I meant, just passing in the function pointer does
jdufault 2017/01/20 19:25:37 Right :(
153 base::Bind(&base::DoNothing));
154 }
155 if (view_)
156 view_->Hide();
141 } 157 }
142 158
143 void HIDDetectionScreen::RequestPinCode(device::BluetoothDevice* device) { 159 void HIDDetectionScreen::RequestPinCode(device::BluetoothDevice* device) {
144 VLOG(1) << "RequestPinCode id = " << device->GetDeviceID() 160 VLOG(1) << "RequestPinCode id = " << device->GetDeviceID()
145 << " name = " << device->GetNameForDisplay(); 161 << " name = " << device->GetNameForDisplay();
146 device->CancelPairing(); 162 device->CancelPairing();
147 } 163 }
148 164
149 void HIDDetectionScreen::RequestPasskey(device::BluetoothDevice* device) { 165 void HIDDetectionScreen::RequestPasskey(device::BluetoothDevice* device) {
150 VLOG(1) << "RequestPassKey id = " << device->GetDeviceID() 166 VLOG(1) << "RequestPassKey id = " << device->GetDeviceID()
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 scoped_refptr<device::BluetoothAdapter> 562 scoped_refptr<device::BluetoothAdapter>
547 HIDDetectionScreen::GetAdapterForTesting() { 563 HIDDetectionScreen::GetAdapterForTesting() {
548 return adapter_; 564 return adapter_;
549 } 565 }
550 566
551 void HIDDetectionScreen::SetAdapterInitialPoweredForTesting(bool powered) { 567 void HIDDetectionScreen::SetAdapterInitialPoweredForTesting(bool powered) {
552 adapter_initially_powered_.reset(new bool(powered)); 568 adapter_initially_powered_.reset(new bool(powered));
553 } 569 }
554 570
555 } // namespace chromeos 571 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698