diff options
author | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 15:03:51 +0000 |
---|---|---|
committer | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 15:03:51 +0000 |
commit | 0ed307aca2af5b12705d7a2d8c749bd73f7d9947 (patch) | |
tree | 0cd152aeee41059751072540cbb5741b424be410 | |
parent | 500057e7dc62bc041d248c03e10e73165d044e3e (diff) | |
download | chromium_src-0ed307aca2af5b12705d7a2d8c749bd73f7d9947.zip chromium_src-0ed307aca2af5b12705d7a2d8c749bd73f7d9947.tar.gz chromium_src-0ed307aca2af5b12705d7a2d8c749bd73f7d9947.tar.bz2 |
bluetooth.connect uses BluetoothDevice::ConnectToProfile() instead of BluetoothDevice::ConnectToService().
BUG=229636
Review URL: https://chromiumcodereview.appspot.com/14748004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197921 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 54 insertions, 56 deletions
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc index 2057f37..a8f9bdb 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc @@ -28,6 +28,7 @@ using device::BluetoothAdapter; using device::BluetoothDevice; +using device::BluetoothProfile; using device::BluetoothServiceRecord; using device::BluetoothSocket; @@ -131,7 +132,7 @@ bool BluetoothAddProfileFunction::RunImpl() { return false; } - device::BluetoothProfile::Options options; + BluetoothProfile::Options options; if (params->profile.name.get()) options.name = *params->profile.name.get(); if (params->profile.channel.get()) @@ -161,13 +162,13 @@ bool BluetoothAddProfileFunction::RunImpl() { } void BluetoothAddProfileFunction::RegisterProfile( - const device::BluetoothProfile::Options& options, - const device::BluetoothProfile::ProfileCallback& callback) { - device::BluetoothProfile::Register(uuid_, options, callback); + const BluetoothProfile::Options& options, + const BluetoothProfile::ProfileCallback& callback) { + BluetoothProfile::Register(uuid_, options, callback); } void BluetoothAddProfileFunction::OnProfileRegistered( - device::BluetoothProfile* bluetooth_profile) { + BluetoothProfile* bluetooth_profile) { if (!bluetooth_profile) { SetError(kProfileRegistrationFailed); SendResponse(false); @@ -359,23 +360,13 @@ bool BluetoothGetServicesFunction::DoWork( return true; } -void BluetoothConnectFunction::ConnectToServiceCallback( - const BluetoothDevice* device, - const std::string& service_uuid, - scoped_refptr<BluetoothSocket> socket) { - if (socket.get()) { - int socket_id = GetEventRouter(profile())->RegisterSocket(socket); +void BluetoothConnectFunction::OnSuccessCallback() { + SendResponse(true); +} - bluetooth::Socket result_socket; - bluetooth::BluetoothDeviceToApiDevice(*device, &result_socket.device); - result_socket.profile.uuid = service_uuid; - result_socket.id = socket_id; - SetResult(result_socket.ToValue().release()); - SendResponse(true); - } else { - SetError(kFailedToConnect); - SendResponse(false); - } +void BluetoothConnectFunction::OnErrorCallback() { + SetError(kFailedToConnect); + SendResponse(false); } bool BluetoothConnectFunction::DoWork(scoped_refptr<BluetoothAdapter> adapter) { @@ -407,11 +398,18 @@ bool BluetoothConnectFunction::DoWork(scoped_refptr<BluetoothAdapter> adapter) { std::string uuid = device::bluetooth_utils::CanonicalUuid( options.profile.uuid); - device->ConnectToService(uuid, - base::Bind(&BluetoothConnectFunction::ConnectToServiceCallback, - this, - device, - uuid)); + BluetoothProfile* bluetooth_profile = + GetEventRouter(profile())->GetProfile(uuid); + if (!bluetooth_profile) { + SetError(kProfileNotFound); + SendResponse(false); + return false; + } + + device->ConnectToProfile( + bluetooth_profile, + base::Bind(&BluetoothConnectFunction::OnSuccessCallback, this), + base::Bind(&BluetoothConnectFunction::OnErrorCallback, this)); return true; } diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h index 5a8230f..afe37d36 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.h +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.h @@ -157,10 +157,8 @@ class BluetoothConnectFunction : public BluetoothExtensionFunction { virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) OVERRIDE; private: - void ConnectToServiceCallback( - const device::BluetoothDevice* device, - const std::string& service_uuid, - scoped_refptr<device::BluetoothSocket> socket); + void OnSuccessCallback(); + void OnErrorCallback(); }; class BluetoothDisconnectFunction : public SyncExtensionFunction { diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc index d172c8b..41ff365 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc @@ -136,6 +136,13 @@ static bool CallClosure(const base::Closure& callback) { return true; } +static void CallConnectToProfileCallback( + BluetoothProfile* profile, + const base::Closure& callback, + const BluetoothDevice::ErrorCallback& error_callback) { + callback.Run(); +} + static void CallDiscoveryCallback( const base::Closure& callback, const BluetoothAdapter::ErrorCallback& error_callback) { @@ -154,21 +161,6 @@ static void CallOutOfBandPairingDataCallback( callback.Run(GetOutOfBandPairingData()); } -template <bool Value> -static void CallProvidesServiceCallback( - const std::string& name, - const BluetoothDevice::ProvidesServiceCallback& callback) { - callback.Run(Value); -} - -static void CallConnectToServiceCallback( - const std::string& name, - const BluetoothDevice::SocketCallback& callback) { - scoped_refptr<device::MockBluetoothSocket> socket = - new device::MockBluetoothSocket(); - callback.Run(socket); -} - } // namespace IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Profiles) { @@ -594,11 +586,14 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Permissions) { PermissionsRequestFunction::SetAutoConfirmForTests(true); PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); + event_router()->AddProfile( + "00001101-0000-1000-8000-00805f9b34fb", profile1_.get()); + EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress())) .WillOnce(testing::Return(device1_.get())); EXPECT_CALL(*device1_, - ConnectToService(testing::_, testing::_)) - .WillOnce(testing::Invoke(CallConnectToServiceCallback)); + ConnectToProfile(testing::_, testing::_, testing::_)) + .WillOnce(testing::Invoke(CallConnectToProfileCallback)); EXPECT_TRUE(RunExtensionTest("bluetooth/permissions")) << message_; } diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc index 02331e2..17f31d7 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc @@ -119,6 +119,15 @@ bool ExtensionBluetoothEventRouter::HasProfile(const std::string& uuid) const { return bluetooth_profile_map_.find(uuid) != bluetooth_profile_map_.end(); } +device::BluetoothProfile* ExtensionBluetoothEventRouter::GetProfile( + const std::string& uuid) const { + BluetoothProfileMap::const_iterator iter = bluetooth_profile_map_.find(uuid); + if (iter != bluetooth_profile_map_.end()) + return iter->second; + + return NULL; +} + scoped_refptr<device::BluetoothSocket> ExtensionBluetoothEventRouter::GetSocket(int id) { SocketMap::iterator socket_entry = socket_map_.find(id); diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h index 3225c76..2040869 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h @@ -68,6 +68,10 @@ class ExtensionBluetoothEventRouter // registered. bool HasProfile(const std::string& uuid) const; + // Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL + // if the BluetoothProfile with |uuid| does not exist. + device::BluetoothProfile* GetProfile(const std::string& uuid) const; + // Get the BluetoothSocket corresponding to |id|. scoped_refptr<device::BluetoothSocket> GetSocket(int id); diff --git a/chrome/common/extensions/api/bluetooth.idl b/chrome/common/extensions/api/bluetooth.idl index a0e2edf..f7d66cf 100644 --- a/chrome/common/extensions/api/bluetooth.idl +++ b/chrome/common/extensions/api/bluetooth.idl @@ -223,10 +223,9 @@ namespace bluetooth { // Connect to a service on a device. // |options| : The options for the connection. - // |callback| : Called when the connection is established with a Socket - // that can be used to communicate with |device|. + // |callback| : Called to indicate success or failure. static void connect(ConnectOptions options, - SocketCallback callback); + ResultCallback callback); // Close a Bluetooth connection. // |options| : The options for this function. diff --git a/chrome/test/data/extensions/api_test/bluetooth/permissions/runtest.js b/chrome/test/data/extensions/api_test/bluetooth/permissions/runtest.js index 0e1fc12..d918e32 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/permissions/runtest.js +++ b/chrome/test/data/extensions/api_test/bluetooth/permissions/runtest.js @@ -39,12 +39,7 @@ chrome.test.runTests([ chrome.bluetooth.connect( {device: kDevice, profile: kProfile}, - pass(function(bluetoothSocket) { - chrome.bluetooth.disconnect( - {socket: bluetoothSocket}, - pass(function(){}) - ); - })); + pass(function() {})); })); }, function permissionDenied() { |