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

Side by Side Diff: device/bluetooth/bluetooth_device_experimental_chromeos.cc

Issue 14199010: Bluetooth: call DeviceChanged observer method on IsConnecting() change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "device/bluetooth/bluetooth_device_experimental_chromeos.h" 5 #include "device/bluetooth/bluetooth_device_experimental_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chromeos/dbus/dbus_thread_manager.h" 8 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" 9 #include "chromeos/dbus/experimental_bluetooth_adapter_client.h"
10 #include "chromeos/dbus/experimental_bluetooth_agent_manager_client.h" 10 #include "chromeos/dbus/experimental_bluetooth_agent_manager_client.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 bool BluetoothDeviceExperimentalChromeOS::ExpectingConfirmation() const { 133 bool BluetoothDeviceExperimentalChromeOS::ExpectingConfirmation() const {
134 return !confirmation_callback_.is_null(); 134 return !confirmation_callback_.is_null();
135 } 135 }
136 136
137 void BluetoothDeviceExperimentalChromeOS::Connect( 137 void BluetoothDeviceExperimentalChromeOS::Connect(
138 BluetoothDevice::PairingDelegate* pairing_delegate, 138 BluetoothDevice::PairingDelegate* pairing_delegate,
139 const base::Closure& callback, 139 const base::Closure& callback,
140 const ConnectErrorCallback& error_callback) { 140 const ConnectErrorCallback& error_callback) {
141 ++num_connecting_calls_; 141 if (num_connecting_calls_++ == 0)
142 adapter_->NotifyDeviceChanged(this);
143
142 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ 144 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_
143 << " in progress"; 145 << " in progress";
144 146
145 if (IsPaired() || IsConnected() || !pairing_delegate || !IsPairable()) { 147 if (IsPaired() || IsConnected() || !pairing_delegate || !IsPairable()) {
146 // No need to pair, or unable to, skip straight to connection. 148 // No need to pair, or unable to, skip straight to connection.
147 ConnectInternal(callback, error_callback); 149 ConnectInternal(callback, error_callback);
148 } else { 150 } else {
149 // Initiate high-security connection with pairing. 151 // Initiate high-security connection with pairing.
150 DCHECK(!pairing_delegate_); 152 DCHECK(!pairing_delegate_);
151 DCHECK(agent_.get() == NULL); 153 DCHECK(agent_.get() == NULL);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 weak_ptr_factory_.GetWeakPtr(), 387 weak_ptr_factory_.GetWeakPtr(),
386 callback), 388 callback),
387 base::Bind( 389 base::Bind(
388 &BluetoothDeviceExperimentalChromeOS::OnConnectError, 390 &BluetoothDeviceExperimentalChromeOS::OnConnectError,
389 weak_ptr_factory_.GetWeakPtr(), 391 weak_ptr_factory_.GetWeakPtr(),
390 error_callback)); 392 error_callback));
391 } 393 }
392 394
393 void BluetoothDeviceExperimentalChromeOS::OnConnect( 395 void BluetoothDeviceExperimentalChromeOS::OnConnect(
394 const base::Closure& callback) { 396 const base::Closure& callback) {
395 --num_connecting_calls_; 397 if (--num_connecting_calls_ == 0)
398 adapter_->NotifyDeviceChanged(this);
399
396 DCHECK(num_connecting_calls_ >= 0); 400 DCHECK(num_connecting_calls_ >= 0);
397 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ 401 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_
398 << " still in progress"; 402 << " still in progress";
399 403
400 SetTrusted(); 404 SetTrusted();
401 405
402 callback.Run(); 406 callback.Run();
403 } 407 }
404 408
405 void BluetoothDeviceExperimentalChromeOS::OnConnectError( 409 void BluetoothDeviceExperimentalChromeOS::OnConnectError(
406 const ConnectErrorCallback& error_callback, 410 const ConnectErrorCallback& error_callback,
407 const std::string& error_name, 411 const std::string& error_name,
408 const std::string& error_message) { 412 const std::string& error_message) {
409 --num_connecting_calls_; 413 if (--num_connecting_calls_ == 0)
414 adapter_->NotifyDeviceChanged(this);
415
410 DCHECK(num_connecting_calls_ >= 0); 416 DCHECK(num_connecting_calls_ >= 0);
411 LOG(WARNING) << object_path_.value() << ": Failed to connect device: " 417 LOG(WARNING) << object_path_.value() << ": Failed to connect device: "
412 << error_name << ": " << error_message; 418 << error_name << ": " << error_message;
413 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ 419 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_
414 << " still in progress"; 420 << " still in progress";
415 421
416 // Determine the error code from error_name. 422 // Determine the error code from error_name.
417 ConnectErrorCode error_code = ERROR_UNKNOWN; 423 ConnectErrorCode error_code = ERROR_UNKNOWN;
418 if (error_name == bluetooth_adapter::kErrorFailed) { 424 if (error_name == bluetooth_adapter::kErrorFailed) {
419 error_code = ERROR_FAILED; 425 error_code = ERROR_FAILED;
(...skipping 20 matching lines...) Expand all
440 base::Bind( 446 base::Bind(
441 &BluetoothDeviceExperimentalChromeOS::OnPairError, 447 &BluetoothDeviceExperimentalChromeOS::OnPairError,
442 weak_ptr_factory_.GetWeakPtr(), 448 weak_ptr_factory_.GetWeakPtr(),
443 error_callback)); 449 error_callback));
444 } 450 }
445 451
446 void BluetoothDeviceExperimentalChromeOS::OnRegisterAgentError( 452 void BluetoothDeviceExperimentalChromeOS::OnRegisterAgentError(
447 const ConnectErrorCallback& error_callback, 453 const ConnectErrorCallback& error_callback,
448 const std::string& error_name, 454 const std::string& error_name,
449 const std::string& error_message) { 455 const std::string& error_message) {
450 --num_connecting_calls_; 456 if (--num_connecting_calls_ == 0)
457 adapter_->NotifyDeviceChanged(this);
458
451 DCHECK(num_connecting_calls_ >= 0); 459 DCHECK(num_connecting_calls_ >= 0);
452 LOG(WARNING) << object_path_.value() << ": Failed to register agent: " 460 LOG(WARNING) << object_path_.value() << ": Failed to register agent: "
453 << error_name << ": " << error_message; 461 << error_name << ": " << error_message;
454 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ 462 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_
455 << " still in progress"; 463 << " still in progress";
456 464
457 UnregisterAgent(); 465 UnregisterAgent();
458 466
459 // Determine the error code from error_name. 467 // Determine the error code from error_name.
460 ConnectErrorCode error_code = ERROR_UNKNOWN; 468 ConnectErrorCode error_code = ERROR_UNKNOWN;
461 if (error_name == bluetooth_adapter::kErrorAlreadyExists) 469 if (error_name == bluetooth_adapter::kErrorAlreadyExists)
462 error_code = ERROR_INPROGRESS; 470 error_code = ERROR_INPROGRESS;
463 471
464 error_callback.Run(error_code); 472 error_callback.Run(error_code);
465 } 473 }
466 474
467 void BluetoothDeviceExperimentalChromeOS::OnPair( 475 void BluetoothDeviceExperimentalChromeOS::OnPair(
468 const base::Closure& callback, 476 const base::Closure& callback,
469 const ConnectErrorCallback& error_callback) { 477 const ConnectErrorCallback& error_callback) {
470 VLOG(1) << object_path_.value() << ": Paired"; 478 VLOG(1) << object_path_.value() << ": Paired";
471 UnregisterAgent(); 479 UnregisterAgent();
472 SetTrusted(); 480 SetTrusted();
473 ConnectInternal(callback, error_callback); 481 ConnectInternal(callback, error_callback);
474 } 482 }
475 483
476 void BluetoothDeviceExperimentalChromeOS::OnPairError( 484 void BluetoothDeviceExperimentalChromeOS::OnPairError(
477 const ConnectErrorCallback& error_callback, 485 const ConnectErrorCallback& error_callback,
478 const std::string& error_name, 486 const std::string& error_name,
479 const std::string& error_message) { 487 const std::string& error_message) {
480 --num_connecting_calls_; 488 if (--num_connecting_calls_ == 0)
489 adapter_->NotifyDeviceChanged(this);
490
481 DCHECK(num_connecting_calls_ >= 0); 491 DCHECK(num_connecting_calls_ >= 0);
482 LOG(WARNING) << object_path_.value() << ": Failed to pair device: " 492 LOG(WARNING) << object_path_.value() << ": Failed to pair device: "
483 << error_name << ": " << error_message; 493 << error_name << ": " << error_message;
484 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ 494 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_
485 << " still in progress"; 495 << " still in progress";
486 496
487 UnregisterAgent(); 497 UnregisterAgent();
488 498
489 // Determine the error code from error_name. 499 // Determine the error code from error_name.
490 ConnectErrorCode error_code = ERROR_UNKNOWN; 500 ConnectErrorCode error_code = ERROR_UNKNOWN;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 if (!confirmation_callback_.is_null()) { 613 if (!confirmation_callback_.is_null()) {
604 confirmation_callback_.Run(status); 614 confirmation_callback_.Run(status);
605 confirmation_callback_.Reset(); 615 confirmation_callback_.Reset();
606 callback_run = true; 616 callback_run = true;
607 } 617 }
608 618
609 return callback_run; 619 return callback_run;
610 } 620 }
611 621
612 } // namespace chromeos 622 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698