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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc

Issue 184953002: Migrate Chrome OS Bluetooth UI to the new discovery API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by derat@ and keybuk@. Created 6 years, 9 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
OLDNEW
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
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 : should_run_device_discovery_(false),
60 pairing_device_passkey_(1000000), 60 pairing_device_passkey_(1000000),
61 pairing_device_entered_(kInvalidEntered), 61 pairing_device_entered_(kInvalidEntered),
62 weak_ptr_factory_(this) { 62 weak_ptr_factory_(this) {
63 } 63 }
64 64
65 BluetoothOptionsHandler::~BluetoothOptionsHandler() { 65 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()) 66 if (adapter_.get())
73 adapter_->RemoveObserver(this); 67 adapter_->RemoveObserver(this);
74 } 68 }
75 69
76 void BluetoothOptionsHandler::GetLocalizedValues( 70 void BluetoothOptionsHandler::GetLocalizedValues(
77 base::DictionaryValue* localized_strings) { 71 base::DictionaryValue* localized_strings) {
78 DCHECK(localized_strings); 72 DCHECK(localized_strings);
79 73
80 static OptionsStringResource resources[] = { 74 static OptionsStringResource resources[] = {
81 { "bluetooth", IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH }, 75 { "bluetooth", IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH },
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 weak_ptr_factory_.GetWeakPtr())); 222 weak_ptr_factory_.GetWeakPtr()));
229 } 223 }
230 224
231 void BluetoothOptionsHandler::EnableChangeError() { 225 void BluetoothOptionsHandler::EnableChangeError() {
232 VLOG(1) << "Failed to change power state."; 226 VLOG(1) << "Failed to change power state.";
233 ReportError("bluetoothChangePowerFailed", std::string()); 227 ReportError("bluetoothChangePowerFailed", std::string());
234 } 228 }
235 229
236 void BluetoothOptionsHandler::FindDevicesCallback( 230 void BluetoothOptionsHandler::FindDevicesCallback(
237 const base::ListValue* args) { 231 const base::ListValue* args) {
238 if (!discovering_) { 232 if (discovery_session_.get() && discovery_session_->IsActive()) {
239 discovering_ = true; 233 VLOG(1) << "Already have an active discovery session.";
240 adapter_->StartDiscovering( 234 return;
241 base::Bind(&base::DoNothing),
242 base::Bind(&BluetoothOptionsHandler::FindDevicesError,
243 weak_ptr_factory_.GetWeakPtr()));
244 } 235 }
236 should_run_device_discovery_ = true;
237 adapter_->StartDiscoverySession(
238 base::Bind(&BluetoothOptionsHandler::OnStartDiscoverySession,
239 weak_ptr_factory_.GetWeakPtr()),
240 base::Bind(&BluetoothOptionsHandler::FindDevicesError,
241 weak_ptr_factory_.GetWeakPtr()));
242 }
243
244 void BluetoothOptionsHandler::OnStartDiscoverySession(
245 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
246 // If the discovery session was returned after a request to stop discovery
247 // (e.g. the "Add Device" dialog was dismissed), don't claim the discovery
248 // session and let it clean up.
249 if (!should_run_device_discovery_)
250 return;
251 discovery_session_ = discovery_session.Pass();
245 } 252 }
246 253
247 void BluetoothOptionsHandler::FindDevicesError() { 254 void BluetoothOptionsHandler::FindDevicesError() {
248 VLOG(1) << "Failed to start discovery."; 255 VLOG(1) << "Failed to start discovery.";
249 ReportError("bluetoothStartDiscoveryFailed", std::string()); 256 ReportError("bluetoothStartDiscoveryFailed", std::string());
250 } 257 }
251 258
252 void BluetoothOptionsHandler::UpdateDeviceCallback( 259 void BluetoothOptionsHandler::UpdateDeviceCallback(
253 const base::ListValue* args) { 260 const base::ListValue* args) {
254 std::string address; 261 std::string address;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 ReportError("bluetoothDisconnectFailed", address); 402 ReportError("bluetoothDisconnectFailed", address);
396 } 403 }
397 404
398 void BluetoothOptionsHandler::ForgetError(const std::string& address) { 405 void BluetoothOptionsHandler::ForgetError(const std::string& address) {
399 VLOG(1) << "Failed to disconnect and unpair device: " << address; 406 VLOG(1) << "Failed to disconnect and unpair device: " << address;
400 ReportError("bluetoothForgetFailed", address); 407 ReportError("bluetoothForgetFailed", address);
401 } 408 }
402 409
403 void BluetoothOptionsHandler::StopDiscoveryCallback( 410 void BluetoothOptionsHandler::StopDiscoveryCallback(
404 const base::ListValue* args) { 411 const base::ListValue* args) {
405 if (discovering_) { 412 should_run_device_discovery_ = false;
406 adapter_->StopDiscovering( 413 if (!discovery_session_.get() || !discovery_session_->IsActive()) {
407 base::Bind(&base::DoNothing), 414 VLOG(1) << "No active discovery session.";
408 base::Bind(&BluetoothOptionsHandler::StopDiscoveryError, 415 return;
409 weak_ptr_factory_.GetWeakPtr()));
410 discovering_ = false;
411 } 416 }
417 discovery_session_->Stop(
418 base::Bind(&base::DoNothing),
419 base::Bind(&BluetoothOptionsHandler::StopDiscoveryError,
420 weak_ptr_factory_.GetWeakPtr()));
412 } 421 }
413 422
414 void BluetoothOptionsHandler::StopDiscoveryError() { 423 void BluetoothOptionsHandler::StopDiscoveryError() {
415 VLOG(1) << "Failed to stop discovery."; 424 VLOG(1) << "Failed to stop discovery.";
416 ReportError("bluetoothStopDiscoveryFailed", std::string()); 425 ReportError("bluetoothStopDiscoveryFailed", std::string());
417 } 426 }
418 427
419 void BluetoothOptionsHandler::GetPairedDevicesCallback( 428 void BluetoothOptionsHandler::GetPairedDevicesCallback(
420 const base::ListValue* args) { 429 const base::ListValue* args) {
421 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 430 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 void BluetoothOptionsHandler::DeviceConnecting( 576 void BluetoothOptionsHandler::DeviceConnecting(
568 device::BluetoothDevice* device) { 577 device::BluetoothDevice* device) {
569 DCHECK(device); 578 DCHECK(device);
570 base::DictionaryValue params; 579 base::DictionaryValue params;
571 params.SetString("pairing", kStartConnecting); 580 params.SetString("pairing", kStartConnecting);
572 SendDeviceNotification(device, &params); 581 SendDeviceNotification(device, &params);
573 } 582 }
574 583
575 } // namespace options 584 } // namespace options
576 } // namespace chromeos 585 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h ('k') | device/bluetooth/bluetooth_adapter_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698