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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.cc

Issue 448153002: BT adapter is switched to initial state after HID screen if no BT devices connected. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.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 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/ui/webui/chromeos/login/hid_detection_screen_handler.h" 5 #include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 namespace chromeos { 67 namespace chromeos {
68 68
69 HIDDetectionScreenHandler::HIDDetectionScreenHandler( 69 HIDDetectionScreenHandler::HIDDetectionScreenHandler(
70 CoreOobeActor* core_oobe_actor) 70 CoreOobeActor* core_oobe_actor)
71 : BaseScreenHandler(kJsScreenPath), 71 : BaseScreenHandler(kJsScreenPath),
72 delegate_(NULL), 72 delegate_(NULL),
73 core_oobe_actor_(core_oobe_actor), 73 core_oobe_actor_(core_oobe_actor),
74 show_on_init_(false), 74 show_on_init_(false),
75 mouse_is_pairing_(false), 75 mouse_is_pairing_(false),
76 pointing_device_connect_type_(InputDeviceInfo::TYPE_UNKNOWN),
76 keyboard_is_pairing_(false), 77 keyboard_is_pairing_(false),
78 keyboard_device_connect_type_(InputDeviceInfo::TYPE_UNKNOWN),
77 switch_on_adapter_when_ready_(false), 79 switch_on_adapter_when_ready_(false),
78 weak_ptr_factory_(this) { 80 weak_ptr_factory_(this) {
79 } 81 }
80 82
81 HIDDetectionScreenHandler::~HIDDetectionScreenHandler() { 83 HIDDetectionScreenHandler::~HIDDetectionScreenHandler() {
84 adapter_initially_powered_.reset();
82 if (adapter_.get()) 85 if (adapter_.get())
83 adapter_->RemoveObserver(this); 86 adapter_->RemoveObserver(this);
84 input_service_proxy_.RemoveObserver(this); 87 input_service_proxy_.RemoveObserver(this);
85 if (delegate_) 88 if (delegate_)
86 delegate_->OnActorDestroyed(this); 89 delegate_->OnActorDestroyed(this);
87 } 90 }
88 91
89 void HIDDetectionScreenHandler::OnStartDiscoverySession( 92 void HIDDetectionScreenHandler::OnStartDiscoverySession(
90 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { 93 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
91 VLOG(1) << "BT Discovery session started"; 94 VLOG(1) << "BT Discovery session started";
92 discovery_session_ = discovery_session.Pass(); 95 discovery_session_ = discovery_session.Pass();
93 UpdateDevices(); 96 UpdateDevices();
94 } 97 }
95 98
96 void HIDDetectionScreenHandler::SetPoweredError() { 99 void HIDDetectionScreenHandler::SetPoweredError() {
97 LOG(ERROR) << "Failed to power BT adapter"; 100 LOG(ERROR) << "Failed to power BT adapter";
98 } 101 }
99 102
103 void HIDDetectionScreenHandler::SetPoweredOffError() {
104 LOG(ERROR) << "Failed to power off BT adapter";
105 }
106
100 void HIDDetectionScreenHandler::FindDevicesError() { 107 void HIDDetectionScreenHandler::FindDevicesError() {
101 VLOG(1) << "Failed to start Bluetooth discovery."; 108 VLOG(1) << "Failed to start Bluetooth discovery.";
102 } 109 }
103 110
104 void HIDDetectionScreenHandler::Show() { 111 void HIDDetectionScreenHandler::Show() {
105 if (!page_is_ready()) { 112 if (!page_is_ready()) {
106 show_on_init_ = true; 113 show_on_init_ = true;
107 return; 114 return;
108 } 115 }
109 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode)) 116 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableDemoMode))
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 else if (pointing_device_id_.empty()) 196 else if (pointing_device_id_.empty())
190 scenario_type = KEYBOARD_DEVICE_ONLY_DETECTED; 197 scenario_type = KEYBOARD_DEVICE_ONLY_DETECTED;
191 else 198 else
192 scenario_type = POINTING_DEVICE_ONLY_DETECTED; 199 scenario_type = POINTING_DEVICE_ONLY_DETECTED;
193 200
194 UMA_HISTOGRAM_ENUMERATION( 201 UMA_HISTOGRAM_ENUMERATION(
195 "HIDDetection.OOBEDevicesDetectedOnContinuePressed", 202 "HIDDetection.OOBEDevicesDetectedOnContinuePressed",
196 scenario_type, 203 scenario_type,
197 CONTINUE_SCENARIO_TYPE_SIZE); 204 CONTINUE_SCENARIO_TYPE_SIZE);
198 205
206 // Switch off BT adapter if it was off before the screen and no BT device
207 // connected.
208 if (adapter_ && adapter_->IsPresent() && adapter_->IsPowered() &&
209 !(pointing_device_connect_type_ == InputDeviceInfo::TYPE_BLUETOOTH ||
210 keyboard_device_connect_type_ == InputDeviceInfo::TYPE_BLUETOOTH) &&
211 adapter_initially_powered_ && !(*adapter_initially_powered_)) {
212 VLOG(1) << "Switching off BT adapter after HID OOBE screen as unused.";
213 adapter_->SetPowered(
214 false,
215 base::Bind(&base::DoNothing),
216 base::Bind(&HIDDetectionScreenHandler::SetPoweredOffError,
217 weak_ptr_factory_.GetWeakPtr()));
218 }
219
199 core_oobe_actor_->StopDemoModeDetection(); 220 core_oobe_actor_->StopDemoModeDetection();
200 if (delegate_) 221 if (delegate_)
201 delegate_->OnExit(); 222 delegate_->OnExit();
202 } 223 }
203 224
204 void HIDDetectionScreenHandler::InitializeAdapter( 225 void HIDDetectionScreenHandler::InitializeAdapter(
205 scoped_refptr<device::BluetoothAdapter> adapter) { 226 scoped_refptr<device::BluetoothAdapter> adapter) {
206 adapter_ = adapter; 227 adapter_ = adapter;
207 CHECK(adapter_.get()); 228 CHECK(adapter_.get());
208 229
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // There is never any circumstance where this will be called, since the 300 // There is never any circumstance where this will be called, since the
280 // HID detection screen handler will only be used for outgoing pairing 301 // HID detection screen handler will only be used for outgoing pairing
281 // requests, but play it safe. 302 // requests, but play it safe.
282 VLOG(1) << "Authorize pairing"; 303 VLOG(1) << "Authorize pairing";
283 device->ConfirmPairing(); 304 device->ConfirmPairing();
284 } 305 }
285 306
286 void HIDDetectionScreenHandler::AdapterPresentChanged( 307 void HIDDetectionScreenHandler::AdapterPresentChanged(
287 device::BluetoothAdapter* adapter, bool present) { 308 device::BluetoothAdapter* adapter, bool present) {
288 if (present && switch_on_adapter_when_ready_) { 309 if (present && switch_on_adapter_when_ready_) {
310 VLOG(1) << "Switching on BT adapter on HID OOBE screen.";
311 adapter_initially_powered_.reset(new bool(adapter_->IsPowered()));
289 adapter_->SetPowered( 312 adapter_->SetPowered(
290 true, 313 true,
291 base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession, 314 base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession,
292 weak_ptr_factory_.GetWeakPtr()), 315 weak_ptr_factory_.GetWeakPtr()),
293 base::Bind(&HIDDetectionScreenHandler::SetPoweredError, 316 base::Bind(&HIDDetectionScreenHandler::SetPoweredError,
294 weak_ptr_factory_.GetWeakPtr())); 317 weak_ptr_factory_.GetWeakPtr()));
295 } 318 }
296 } 319 }
297 320
298 void HIDDetectionScreenHandler::TryPairingAsPointingDevice( 321 void HIDDetectionScreenHandler::TryPairingAsPointingDevice(
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 446 }
424 } 447 }
425 448
426 void HIDDetectionScreenHandler::TryInitiateBTDevicesUpdate() { 449 void HIDDetectionScreenHandler::TryInitiateBTDevicesUpdate() {
427 if ((pointing_device_id_.empty() || keyboard_device_id_.empty()) && 450 if ((pointing_device_id_.empty() || keyboard_device_id_.empty()) &&
428 adapter_) { 451 adapter_) {
429 if (!adapter_->IsPresent()) { 452 if (!adapter_->IsPresent()) {
430 // Switch on BT adapter later when it's available. 453 // Switch on BT adapter later when it's available.
431 switch_on_adapter_when_ready_ = true; 454 switch_on_adapter_when_ready_ = true;
432 } else if (!adapter_->IsPowered()) { 455 } else if (!adapter_->IsPowered()) {
456 VLOG(1) << "Switching on BT adapter on HID OOBE screen.";
457 adapter_initially_powered_.reset(new bool(false));
433 adapter_->SetPowered( 458 adapter_->SetPowered(
434 true, 459 true,
435 base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession, 460 base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession,
436 weak_ptr_factory_.GetWeakPtr()), 461 weak_ptr_factory_.GetWeakPtr()),
437 base::Bind(&HIDDetectionScreenHandler::SetPoweredError, 462 base::Bind(&HIDDetectionScreenHandler::SetPoweredError,
438 weak_ptr_factory_.GetWeakPtr())); 463 weak_ptr_factory_.GetWeakPtr()));
439 } else { 464 } else {
440 UpdateBTDevices(); 465 UpdateBTDevices();
441 } 466 }
442 } 467 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 l10n_util::GetStringFUTF16( 583 l10n_util::GetStringFUTF16(
559 IDS_HID_DETECTION_PAIRED_BLUETOOTH_KEYBOARD, 584 IDS_HID_DETECTION_PAIRED_BLUETOOTH_KEYBOARD,
560 base::UTF8ToUTF16(keyboard_device_name_))); 585 base::UTF8ToUTF16(keyboard_device_name_)));
561 } else { 586 } else {
562 state_info.SetString("state", kUSBConnectedState); 587 state_info.SetString("state", kUSBConnectedState);
563 } 588 }
564 CallJS("setKeyboardDeviceState", state_info); 589 CallJS("setKeyboardDeviceState", state_info);
565 } 590 }
566 591
567 } // namespace chromeos 592 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698