| 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/extensions/api/bluetooth/bluetooth_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
| 6 | 6 |
| 7 #if defined(OS_CHROMEOS) | 7 #if defined(OS_CHROMEOS) |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 const char kCouldNotGetLocalOutOfBandPairingData[] = | 48 const char kCouldNotGetLocalOutOfBandPairingData[] = |
| 49 "Could not get local Out Of Band Pairing Data"; | 49 "Could not get local Out Of Band Pairing Data"; |
| 50 const char kCouldNotSetOutOfBandPairingData[] = | 50 const char kCouldNotSetOutOfBandPairingData[] = |
| 51 "Could not set Out Of Band Pairing Data"; | 51 "Could not set Out Of Band Pairing Data"; |
| 52 const char kFailedToConnect[] = "Connection failed"; | 52 const char kFailedToConnect[] = "Connection failed"; |
| 53 const char kInvalidDevice[] = "Invalid device"; | 53 const char kInvalidDevice[] = "Invalid device"; |
| 54 const char kInvalidUuid[] = "Invalid UUID"; | 54 const char kInvalidUuid[] = "Invalid UUID"; |
| 55 const char kServiceDiscoveryFailed[] = "Service discovery failed"; | 55 const char kServiceDiscoveryFailed[] = "Service discovery failed"; |
| 56 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; | 56 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; |
| 57 const char kStartDiscoveryFailed[] = | 57 const char kStartDiscoveryFailed[] = "Starting discovery failed"; |
| 58 "Starting discovery failed, or already discovering"; | |
| 59 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; | 58 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; |
| 60 | 59 |
| 61 } // namespace | 60 } // namespace |
| 62 | 61 |
| 63 namespace Connect = extensions::api::experimental_bluetooth::Connect; | 62 namespace Connect = extensions::api::experimental_bluetooth::Connect; |
| 64 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect; | 63 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect; |
| 65 namespace GetDevices = extensions::api::experimental_bluetooth::GetDevices; | 64 namespace GetDevices = extensions::api::experimental_bluetooth::GetDevices; |
| 66 namespace GetServices = extensions::api::experimental_bluetooth::GetServices; | 65 namespace GetServices = extensions::api::experimental_bluetooth::GetServices; |
| 67 namespace Read = extensions::api::experimental_bluetooth::Read; | 66 namespace Read = extensions::api::experimental_bluetooth::Read; |
| 68 namespace SetOutOfBandPairingData = | 67 namespace SetOutOfBandPairingData = |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() { | 451 bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() { |
| 453 GetMutableAdapter(profile())->ReadLocalOutOfBandPairingData( | 452 GetMutableAdapter(profile())->ReadLocalOutOfBandPairingData( |
| 454 base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback, | 453 base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback, |
| 455 this), | 454 this), |
| 456 base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback, | 455 base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback, |
| 457 this)); | 456 this)); |
| 458 return true; | 457 return true; |
| 459 } | 458 } |
| 460 | 459 |
| 461 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { | 460 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { |
| 461 GetEventRouter(profile())->SetResponsibleForDiscovery(true); |
| 462 SendResponse(true); | 462 SendResponse(true); |
| 463 } | 463 } |
| 464 | 464 |
| 465 void BluetoothStartDiscoveryFunction::OnErrorCallback() { | 465 void BluetoothStartDiscoveryFunction::OnErrorCallback() { |
| 466 SetError(kStartDiscoveryFailed); | 466 SetError(kStartDiscoveryFailed); |
| 467 SendResponse(false); | 467 SendResponse(false); |
| 468 } | 468 } |
| 469 | 469 |
| 470 bool BluetoothStartDiscoveryFunction::RunImpl() { | 470 bool BluetoothStartDiscoveryFunction::RunImpl() { |
| 471 GetEventRouter(profile())->SetSendDiscoveryEvents(true); | 471 GetEventRouter(profile())->SetSendDiscoveryEvents(true); |
| 472 | 472 |
| 473 // BluetoothAdapter will throw an error if we SetDiscovering(true) when | 473 // If the adapter is already discovering, there is nothing else to do. |
| 474 // discovery is already in progress | |
| 475 if (GetMutableAdapter(profile())->IsDiscovering()) { | 474 if (GetMutableAdapter(profile())->IsDiscovering()) { |
| 476 SendResponse(true); | 475 SendResponse(true); |
| 477 return true; | 476 return true; |
| 478 } | 477 } |
| 479 | 478 |
| 480 GetMutableAdapter(profile())->SetDiscovering(true, | 479 GetMutableAdapter(profile())->SetDiscovering(true, |
| 481 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), | 480 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), |
| 482 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); | 481 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); |
| 483 return true; | 482 return true; |
| 484 } | 483 } |
| 485 | 484 |
| 486 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { | 485 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { |
| 487 SendResponse(true); | 486 SendResponse(true); |
| 488 } | 487 } |
| 489 | 488 |
| 490 void BluetoothStopDiscoveryFunction::OnErrorCallback() { | 489 void BluetoothStopDiscoveryFunction::OnErrorCallback() { |
| 491 SetError(kStopDiscoveryFailed); | 490 SetError(kStopDiscoveryFailed); |
| 492 SendResponse(false); | 491 SendResponse(false); |
| 493 } | 492 } |
| 494 | 493 |
| 495 bool BluetoothStopDiscoveryFunction::RunImpl() { | 494 bool BluetoothStopDiscoveryFunction::RunImpl() { |
| 496 GetEventRouter(profile())->SetSendDiscoveryEvents(false); | 495 GetEventRouter(profile())->SetSendDiscoveryEvents(false); |
| 497 GetMutableAdapter(profile())->SetDiscovering(false, | 496 if (GetEventRouter(profile())->IsResponsibleForDiscovery()) { |
| 498 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 497 GetMutableAdapter(profile())->SetDiscovering(false, |
| 499 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 498 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
| 499 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
| 500 } |
| 500 return true; | 501 return true; |
| 501 } | 502 } |
| 502 | 503 |
| 503 #else | 504 #else |
| 504 | 505 |
| 505 // ----------------------------------------------------------------------------- | 506 // ----------------------------------------------------------------------------- |
| 506 // NIY stubs | 507 // NIY stubs |
| 507 // ----------------------------------------------------------------------------- | 508 // ----------------------------------------------------------------------------- |
| 508 bool BluetoothIsAvailableFunction::RunImpl() { | 509 bool BluetoothIsAvailableFunction::RunImpl() { |
| 509 NOTREACHED() << "Not implemented yet"; | 510 NOTREACHED() << "Not implemented yet"; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 #endif | 588 #endif |
| 588 | 589 |
| 589 BluetoothReadFunction::BluetoothReadFunction() {} | 590 BluetoothReadFunction::BluetoothReadFunction() {} |
| 590 BluetoothReadFunction::~BluetoothReadFunction() {} | 591 BluetoothReadFunction::~BluetoothReadFunction() {} |
| 591 | 592 |
| 592 BluetoothWriteFunction::BluetoothWriteFunction() {} | 593 BluetoothWriteFunction::BluetoothWriteFunction() {} |
| 593 BluetoothWriteFunction::~BluetoothWriteFunction() {} | 594 BluetoothWriteFunction::~BluetoothWriteFunction() {} |
| 594 | 595 |
| 595 } // namespace api | 596 } // namespace api |
| 596 } // namespace extensions | 597 } // namespace extensions |
| OLD | NEW |