OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/options/chromeos/bluetooth_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 const char kConfirmPasskey[] = "bluetoothConfirmPasskey"; | 48 const char kConfirmPasskey[] = "bluetoothConfirmPasskey"; |
49 | 49 |
50 // An invalid |entered| value to represent the "undefined" value. | 50 // An invalid |entered| value to represent the "undefined" value. |
51 const int kInvalidEntered = 0xFFFF; | 51 const int kInvalidEntered = 0xFFFF; |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 namespace chromeos { | 55 namespace chromeos { |
56 namespace options { | 56 namespace options { |
57 | 57 |
58 BluetoothOptionsHandler::BluetoothOptionsHandler() : | 58 BluetoothOptionsHandler::BluetoothOptionsHandler() |
59 discovering_(false), | 59 : pairing_device_passkey_(1000000), |
60 pairing_device_passkey_(1000000), | 60 pairing_device_entered_(kInvalidEntered), |
61 pairing_device_entered_(kInvalidEntered), | 61 weak_ptr_factory_(this) { |
62 weak_ptr_factory_(this) { | |
63 } | 62 } |
64 | 63 |
65 BluetoothOptionsHandler::~BluetoothOptionsHandler() { | 64 BluetoothOptionsHandler::~BluetoothOptionsHandler() { |
66 if (discovering_) { | |
67 adapter_->StopDiscovering( | |
68 base::Bind(&base::DoNothing), | |
69 base::Bind(&base::DoNothing)); | |
70 discovering_ = false; | |
71 } | |
72 if (adapter_.get()) | 65 if (adapter_.get()) |
73 adapter_->RemoveObserver(this); | 66 adapter_->RemoveObserver(this); |
74 } | 67 } |
75 | 68 |
76 void BluetoothOptionsHandler::GetLocalizedValues( | 69 void BluetoothOptionsHandler::GetLocalizedValues( |
77 base::DictionaryValue* localized_strings) { | 70 base::DictionaryValue* localized_strings) { |
78 DCHECK(localized_strings); | 71 DCHECK(localized_strings); |
79 | 72 |
80 static OptionsStringResource resources[] = { | 73 static OptionsStringResource resources[] = { |
81 { "bluetooth", IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH }, | 74 { "bluetooth", IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH }, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 weak_ptr_factory_.GetWeakPtr())); | 221 weak_ptr_factory_.GetWeakPtr())); |
229 } | 222 } |
230 | 223 |
231 void BluetoothOptionsHandler::EnableChangeError() { | 224 void BluetoothOptionsHandler::EnableChangeError() { |
232 VLOG(1) << "Failed to change power state."; | 225 VLOG(1) << "Failed to change power state."; |
233 ReportError("bluetoothChangePowerFailed", std::string()); | 226 ReportError("bluetoothChangePowerFailed", std::string()); |
234 } | 227 } |
235 | 228 |
236 void BluetoothOptionsHandler::FindDevicesCallback( | 229 void BluetoothOptionsHandler::FindDevicesCallback( |
237 const base::ListValue* args) { | 230 const base::ListValue* args) { |
238 if (!discovering_) { | 231 if (discovery_session_.get() && discovery_session_->IsActive()) { |
239 discovering_ = true; | 232 VLOG(1) << "Already have an active discovery session."; |
240 adapter_->StartDiscovering( | 233 return; |
241 base::Bind(&base::DoNothing), | |
242 base::Bind(&BluetoothOptionsHandler::FindDevicesError, | |
243 weak_ptr_factory_.GetWeakPtr())); | |
244 } | 234 } |
235 adapter_->StartDiscoverySession( | |
236 base::Bind(&BluetoothOptionsHandler::OnStartDiscoverySession, | |
237 weak_ptr_factory_.GetWeakPtr()), | |
238 base::Bind(&BluetoothOptionsHandler::FindDevicesError, | |
239 weak_ptr_factory_.GetWeakPtr())); | |
240 } | |
241 | |
242 void BluetoothOptionsHandler::OnStartDiscoverySession( | |
243 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | |
244 discovery_session_ = discovery_session.Pass(); | |
keybuk
2014/02/28 21:29:28
Doesn't this need the same logic as Aura, what if
armansito
2014/02/28 22:52:02
It certainly does. Done.
| |
245 } | 245 } |
246 | 246 |
247 void BluetoothOptionsHandler::FindDevicesError() { | 247 void BluetoothOptionsHandler::FindDevicesError() { |
248 VLOG(1) << "Failed to start discovery."; | 248 VLOG(1) << "Failed to start discovery."; |
249 ReportError("bluetoothStartDiscoveryFailed", std::string()); | 249 ReportError("bluetoothStartDiscoveryFailed", std::string()); |
250 } | 250 } |
251 | 251 |
252 void BluetoothOptionsHandler::UpdateDeviceCallback( | 252 void BluetoothOptionsHandler::UpdateDeviceCallback( |
253 const base::ListValue* args) { | 253 const base::ListValue* args) { |
254 std::string address; | 254 std::string address; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 ReportError("bluetoothDisconnectFailed", address); | 395 ReportError("bluetoothDisconnectFailed", address); |
396 } | 396 } |
397 | 397 |
398 void BluetoothOptionsHandler::ForgetError(const std::string& address) { | 398 void BluetoothOptionsHandler::ForgetError(const std::string& address) { |
399 VLOG(1) << "Failed to disconnect and unpair device: " << address; | 399 VLOG(1) << "Failed to disconnect and unpair device: " << address; |
400 ReportError("bluetoothForgetFailed", address); | 400 ReportError("bluetoothForgetFailed", address); |
401 } | 401 } |
402 | 402 |
403 void BluetoothOptionsHandler::StopDiscoveryCallback( | 403 void BluetoothOptionsHandler::StopDiscoveryCallback( |
404 const base::ListValue* args) { | 404 const base::ListValue* args) { |
405 if (discovering_) { | 405 if (!discovery_session_.get() || !discovery_session_->IsActive()) { |
406 adapter_->StopDiscovering( | 406 VLOG(1) << "No active discovery session."; |
407 base::Bind(&base::DoNothing), | 407 return; |
408 base::Bind(&BluetoothOptionsHandler::StopDiscoveryError, | |
409 weak_ptr_factory_.GetWeakPtr())); | |
410 discovering_ = false; | |
411 } | 408 } |
409 discovery_session_->Stop( | |
410 base::Bind(&base::DoNothing), | |
411 base::Bind(&BluetoothOptionsHandler::StopDiscoveryError, | |
412 weak_ptr_factory_.GetWeakPtr())); | |
412 } | 413 } |
413 | 414 |
414 void BluetoothOptionsHandler::StopDiscoveryError() { | 415 void BluetoothOptionsHandler::StopDiscoveryError() { |
415 VLOG(1) << "Failed to stop discovery."; | 416 VLOG(1) << "Failed to stop discovery."; |
416 ReportError("bluetoothStopDiscoveryFailed", std::string()); | 417 ReportError("bluetoothStopDiscoveryFailed", std::string()); |
417 } | 418 } |
418 | 419 |
419 void BluetoothOptionsHandler::GetPairedDevicesCallback( | 420 void BluetoothOptionsHandler::GetPairedDevicesCallback( |
420 const base::ListValue* args) { | 421 const base::ListValue* args) { |
421 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 422 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 void BluetoothOptionsHandler::DeviceConnecting( | 568 void BluetoothOptionsHandler::DeviceConnecting( |
568 device::BluetoothDevice* device) { | 569 device::BluetoothDevice* device) { |
569 DCHECK(device); | 570 DCHECK(device); |
570 base::DictionaryValue params; | 571 base::DictionaryValue params; |
571 params.SetString("pairing", kStartConnecting); | 572 params.SetString("pairing", kStartConnecting); |
572 SendDeviceNotification(device, ¶ms); | 573 SendDeviceNotification(device, ¶ms); |
573 } | 574 } |
574 | 575 |
575 } // namespace options | 576 } // namespace options |
576 } // namespace chromeos | 577 } // namespace chromeos |
OLD | NEW |