Commit 13ccdbe1 authored by keybuk@chromium.org's avatar keybuk@chromium.org

Bluetooth: remove Profile API

This CL removes the bluetooth.addProfile and bluetooth.removeProfile
API calls, along with the associated bluetooth.onConnection event.
Apps should now use bluetoothSocket.connect() and the family of
bluetoothSocket.listenUsing*() functions instead.

Since those are only implemented on Chrome OS right now this
temporarily breaks Windows and OS X, but should make the effort of
porting those to the new API easier by removing much of the old code.

It also cleans up the bluetooth API by removing the deprecated and
non-functional socket methods now that bluetoothSocket is complete.

BUG=349475
TEST=unit_tests and browser_tests

Review URL: https://codereview.chromium.org/284183012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274000 0039d316-1c4b-4281-b951-d872f2087c98
parent bd780414
...@@ -9,15 +9,9 @@ ...@@ -9,15 +9,9 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h" #include "chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h"
#include "chrome/common/extensions/api/bluetooth.h" #include "chrome/common/extensions/api/bluetooth.h"
#include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_profile.h"
#include "device/bluetooth/bluetooth_socket.h"
#include "device/bluetooth/bluetooth_uuid.h"
#include "extensions/browser/api/api_resource_manager.h"
#include "extensions/browser/api/async_api_function.h"
#include "extensions/browser/browser_context_keyed_api_factory.h" #include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function.h" #include "extensions/browser/extension_function.h"
...@@ -30,10 +24,6 @@ namespace device { ...@@ -30,10 +24,6 @@ namespace device {
class BluetoothAdapter; class BluetoothAdapter;
} }
namespace net {
class IOBuffer;
}
namespace extensions { namespace extensions {
class BluetoothEventRouter; class BluetoothEventRouter;
...@@ -44,21 +34,6 @@ class BluetoothEventRouter; ...@@ -44,21 +34,6 @@ class BluetoothEventRouter;
class BluetoothAPI : public BrowserContextKeyedAPI, class BluetoothAPI : public BrowserContextKeyedAPI,
public EventRouter::Observer { public EventRouter::Observer {
public: public:
typedef ApiResourceManager<BluetoothApiSocket>::ApiResourceData SocketData;
struct ConnectionParams {
ConnectionParams();
~ConnectionParams();
content::BrowserThread::ID thread_id;
void* browser_context_id;
std::string extension_id;
std::string device_address;
device::BluetoothUUID uuid;
scoped_refptr<device::BluetoothSocket> socket;
scoped_refptr<SocketData> socket_data;
};
// Convenience method to get the BluetoothAPI for a browser context. // Convenience method to get the BluetoothAPI for a browser context.
static BluetoothAPI* Get(content::BrowserContext* context); static BluetoothAPI* Get(content::BrowserContext* context);
...@@ -68,7 +43,6 @@ class BluetoothAPI : public BrowserContextKeyedAPI, ...@@ -68,7 +43,6 @@ class BluetoothAPI : public BrowserContextKeyedAPI,
virtual ~BluetoothAPI(); virtual ~BluetoothAPI();
BluetoothEventRouter* event_router(); BluetoothEventRouter* event_router();
scoped_refptr<SocketData> socket_data();
// KeyedService implementation. // KeyedService implementation.
virtual void Shutdown() OVERRIDE; virtual void Shutdown() OVERRIDE;
...@@ -77,21 +51,7 @@ class BluetoothAPI : public BrowserContextKeyedAPI, ...@@ -77,21 +51,7 @@ class BluetoothAPI : public BrowserContextKeyedAPI,
virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE;
// Dispatch an event that takes a connection socket as a parameter to the
// extension that registered the profile that the socket has connected to.
void DispatchConnectionEvent(const std::string& extension_id,
const device::BluetoothUUID& profile_uuid,
const device::BluetoothDevice* device,
scoped_refptr<device::BluetoothSocket> socket);
private: private:
static void RegisterSocket(const ConnectionParams& params);
static void RegisterSocketUI(const ConnectionParams& params, int socket_id);
static void RegisterSocketWithAdapterUI(
const ConnectionParams& params,
int socket_id,
scoped_refptr<device::BluetoothAdapter> adapter);
// BrowserContextKeyedAPI implementation. // BrowserContextKeyedAPI implementation.
friend class BrowserContextKeyedAPIFactory<BluetoothAPI>; friend class BrowserContextKeyedAPIFactory<BluetoothAPI>;
static const char* service_name() { return "BluetoothAPI"; } static const char* service_name() { return "BluetoothAPI"; }
...@@ -102,7 +62,6 @@ class BluetoothAPI : public BrowserContextKeyedAPI, ...@@ -102,7 +62,6 @@ class BluetoothAPI : public BrowserContextKeyedAPI,
// Created lazily on first access. // Created lazily on first access.
scoped_ptr<BluetoothEventRouter> event_router_; scoped_ptr<BluetoothEventRouter> event_router_;
scoped_refptr<SocketData> socket_data_;
}; };
namespace api { namespace api {
...@@ -141,120 +100,6 @@ class BluetoothGetDeviceFunction : public BluetoothExtensionFunction { ...@@ -141,120 +100,6 @@ class BluetoothGetDeviceFunction : public BluetoothExtensionFunction {
virtual ~BluetoothGetDeviceFunction(); virtual ~BluetoothGetDeviceFunction();
}; };
class BluetoothAddProfileFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.addProfile", BLUETOOTH_ADDPROFILE)
BluetoothAddProfileFunction();
protected:
virtual ~BluetoothAddProfileFunction();
virtual bool RunAsync() OVERRIDE;
virtual void RegisterProfile(
const device::BluetoothProfile::Options& options,
const device::BluetoothProfile::ProfileCallback& callback);
private:
void OnProfileRegistered(device::BluetoothProfile* bluetooth_profile);
device::BluetoothUUID uuid_;
};
class BluetoothRemoveProfileFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.removeProfile",
BLUETOOTH_REMOVEPROFILE)
protected:
virtual ~BluetoothRemoveProfileFunction();
virtual bool RunSync() OVERRIDE;
};
class BluetoothConnectFunction : public BluetoothExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.connect", BLUETOOTH_CONNECT)
protected:
virtual ~BluetoothConnectFunction();
// BluetoothExtensionFunction:
virtual bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) OVERRIDE;
private:
void OnConnectedCallback(scoped_refptr<device::BluetoothAdapter> adapter,
const std::string& device_address);
void OnMonitorStartedCallback();
void OnErrorCallback(const std::string& error);
};
class BluetoothDisconnectFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.disconnect", BLUETOOTH_DISCONNECT)
protected:
virtual ~BluetoothDisconnectFunction() {}
// AsyncExtensionFunction:
virtual bool RunAsync() OVERRIDE;
};
class BluetoothSendFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.send", BLUETOOTH_WRITE)
protected:
virtual ~BluetoothSendFunction() {}
// AsyncExtensionFunction:
virtual bool RunAsync() OVERRIDE;
};
class BluetoothUpdateSocketFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.updateSocket", BLUETOOTH_UPDATE_SOCKET)
protected:
virtual ~BluetoothUpdateSocketFunction() {}
// AsyncExtensionFunction:
virtual bool RunAsync() OVERRIDE;
};
class BluetoothSetSocketPausedFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.setSocketPaused",
BLUETOOTH_SET_SOCKET_PAUSED)
protected:
virtual ~BluetoothSetSocketPausedFunction() {}
// AsyncExtensionFunction:
virtual bool RunAsync() OVERRIDE;
};
class BluetoothGetSocketFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.getSocket", BLUETOOTH_GET_SOCKET)
protected:
virtual ~BluetoothGetSocketFunction() {}
// AsyncExtensionFunction:
virtual bool RunAsync() OVERRIDE;
};
class BluetoothGetSocketsFunction : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("bluetooth.getSockets", BLUETOOTH_GET_SOCKETS)
protected:
virtual ~BluetoothGetSocketsFunction() {}
// AsyncExtensionFunction:
virtual bool RunAsync() OVERRIDE;
};
class BluetoothStartDiscoveryFunction : public BluetoothExtensionFunction { class BluetoothStartDiscoveryFunction : public BluetoothExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("bluetooth.startDiscovery", DECLARE_EXTENSION_FUNCTION("bluetooth.startDiscovery",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h"
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/common/extensions/api/bluetooth.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/bluetooth/test/mock_bluetooth_device.h"
#include "device/bluetooth/test/mock_bluetooth_profile.h"
#include "device/bluetooth/test/mock_bluetooth_socket.h"
#include "extensions/browser/event_router.h"
#include "extensions/common/extension_builder.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kTestExtensionId[] = "test extension id";
const device::BluetoothUUID kAudioProfileUuid("1234");
static KeyedService* ApiResourceManagerTestFactory(
content::BrowserContext* context) {
content::BrowserThread::ID id;
CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
return extensions::ApiResourceManager<
extensions::BluetoothApiSocket>::CreateApiResourceManagerForTest(context,
id);
}
static KeyedService* BluetoothAPITestFactory(content::BrowserContext* context) {
content::BrowserThread::ID id;
CHECK(content::BrowserThread::GetCurrentThreadIdentifier(&id));
return new extensions::BluetoothAPI(context);
}
class FakeEventRouter : public extensions::EventRouter {
public:
explicit FakeEventRouter(Profile* profile) : EventRouter(profile, NULL) {}
virtual void DispatchEventToExtension(const std::string& extension_id,
scoped_ptr<extensions::Event> event)
OVERRIDE {
extension_id_ = extension_id;
event_ = event.Pass();
}
std::string extension_id() const { return extension_id_; }
const extensions::Event* event() const { return event_.get(); }
private:
std::string extension_id_;
scoped_ptr<extensions::Event> event_;
DISALLOW_COPY_AND_ASSIGN(FakeEventRouter);
};
class FakeExtensionSystem : public extensions::TestExtensionSystem {
public:
explicit FakeExtensionSystem(Profile* profile)
: extensions::TestExtensionSystem(profile) {}
virtual extensions::EventRouter* event_router() OVERRIDE {
if (!fake_event_router_)
fake_event_router_.reset(new FakeEventRouter(profile_));
return fake_event_router_.get();
}
private:
scoped_ptr<FakeEventRouter> fake_event_router_;
DISALLOW_COPY_AND_ASSIGN(FakeExtensionSystem);
};
KeyedService* BuildFakeExtensionSystem(content::BrowserContext* profile) {
return new FakeExtensionSystem(static_cast<Profile*>(profile));
}
} // namespace
namespace extensions {
namespace bluetooth = api::bluetooth;
class ExtensionBluetoothApiTest : public testing::Test {
public:
ExtensionBluetoothApiTest()
: profile_manager_(TestingBrowserProcess::GetGlobal()),
mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>()),
test_profile_(NULL) {}
virtual void SetUp() OVERRIDE {
testing::Test::SetUp();
ASSERT_TRUE(profile_manager_.SetUp());
test_profile_ = profile_manager_.CreateTestingProfile("test");
ExtensionSystemFactory::GetInstance()->SetTestingFactoryAndUse(
test_profile_, &BuildFakeExtensionSystem);
ApiResourceManager<BluetoothApiSocket>::GetFactoryInstance()
->SetTestingFactoryAndUse(test_profile_, ApiResourceManagerTestFactory);
BluetoothAPI::GetFactoryInstance()->SetTestingFactoryAndUse(
test_profile_, BluetoothAPITestFactory);
BluetoothAPI::Get(test_profile_)->event_router()->SetAdapterForTest(
mock_adapter_);
}
virtual void TearDown() OVERRIDE {
// Some profile-dependent services rely on UI thread to clean up. We make
// sure they are properly cleaned up by running the UI message loop until
// idle.
test_profile_ = NULL;
profile_manager_.DeleteTestingProfile("test");
base::RunLoop run_loop;
run_loop.RunUntilIdle();
}
protected:
content::TestBrowserThreadBundle thread_bundle_;
TestingProfileManager profile_manager_;
scoped_refptr<testing::StrictMock<device::MockBluetoothAdapter> >
mock_adapter_;
testing::NiceMock<device::MockBluetoothProfile> mock_audio_profile_;
testing::NiceMock<device::MockBluetoothProfile> mock_health_profile_;
// Profiles are weak pointers, owned by |profile_manager_|.
TestingProfile* test_profile_;
};
TEST_F(ExtensionBluetoothApiTest, DispatchConnectionEvent) {
testing::NiceMock<device::MockBluetoothDevice> mock_device(
mock_adapter_.get(), 0, "device name", "device address", true, false);
EXPECT_CALL(*mock_adapter_, GetDevice(mock_device.GetAddress()))
.WillOnce(testing::Return(&mock_device));
scoped_refptr<testing::NiceMock<device::MockBluetoothSocket> > mock_socket(
new testing::NiceMock<device::MockBluetoothSocket>());
BluetoothAPI::Get(test_profile_)->event_router()->AddProfile(
kAudioProfileUuid, kTestExtensionId, &mock_audio_profile_);
BluetoothAPI::Get(test_profile_)->DispatchConnectionEvent(
kTestExtensionId, kAudioProfileUuid, &mock_device, mock_socket);
// Connection events are dispatched using a couple of PostTask to the UI
// thread. Waiting until idle ensures the event is dispatched to the
// receiver(s).
base::RunLoop().RunUntilIdle();
FakeEventRouter* fake_event_router =
static_cast<FakeEventRouter*>(EventRouter::Get(test_profile_));
ASSERT_TRUE(fake_event_router->event());
EXPECT_STREQ(kTestExtensionId, fake_event_router->extension_id().c_str());
EXPECT_STREQ(bluetooth::OnConnection::kEventName,
fake_event_router->event()->event_name.c_str());
base::ListValue* event_args = fake_event_router->event()->event_args.get();
base::DictionaryValue* socket_value = NULL;
ASSERT_TRUE(event_args->GetDictionary(0, &socket_value));
int socket_id;
ASSERT_TRUE(socket_value->GetInteger("id", &socket_id));
ASSERT_TRUE(BluetoothAPI::Get(test_profile_)->socket_data()->Get(
kTestExtensionId, socket_id));
std::string uuid;
ASSERT_TRUE(socket_value->GetString("uuid", &uuid));
EXPECT_STREQ(kAudioProfileUuid.canonical_value().c_str(), uuid.c_str());
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
BluetoothAPI::Get(test_profile_)->socket_data()->Remove(kTestExtensionId,
socket_id);
}
TEST_F(ExtensionBluetoothApiTest, DoNotDispatchConnectionEvent) {
testing::NiceMock<device::MockBluetoothDevice> mock_device(
mock_adapter_.get(), 0, "device name", "device address", true, false);
scoped_refptr<testing::NiceMock<device::MockBluetoothSocket> > mock_socket(
new testing::NiceMock<device::MockBluetoothSocket>());
// Connection event won't be dispatched for non-registered profiles.
BluetoothAPI::Get(test_profile_)->DispatchConnectionEvent(
kTestExtensionId, kAudioProfileUuid, &mock_device, mock_socket);
// Connection events are dispatched using a couple of PostTask to the UI
// thread. Waiting until idle ensures the event is dispatched to the
// receiver(s).
base::RunLoop().RunUntilIdle();
FakeEventRouter* fake_event_router =
static_cast<FakeEventRouter*>(EventRouter::Get(test_profile_));
EXPECT_TRUE(fake_event_router->event() == NULL);
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
}
} // namespace extensions
...@@ -19,19 +19,15 @@ ...@@ -19,19 +19,15 @@
#include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/bluetooth/test/mock_bluetooth_device.h" #include "device/bluetooth/test/mock_bluetooth_device.h"
#include "device/bluetooth/test/mock_bluetooth_discovery_session.h" #include "device/bluetooth/test/mock_bluetooth_discovery_session.h"
#include "device/bluetooth/test/mock_bluetooth_profile.h"
#include "device/bluetooth/test/mock_bluetooth_socket.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
using device::BluetoothAdapter; using device::BluetoothAdapter;
using device::BluetoothDevice; using device::BluetoothDevice;
using device::BluetoothDiscoverySession; using device::BluetoothDiscoverySession;
using device::BluetoothProfile;
using device::BluetoothUUID; using device::BluetoothUUID;
using device::MockBluetoothAdapter; using device::MockBluetoothAdapter;
using device::MockBluetoothDevice; using device::MockBluetoothDevice;
using device::MockBluetoothDiscoverySession; using device::MockBluetoothDiscoverySession;
using device::MockBluetoothProfile;
using extensions::Extension; using extensions::Extension;
namespace utils = extension_function_test_utils; namespace utils = extension_function_test_utils;
...@@ -50,8 +46,6 @@ class BluetoothApiTest : public ExtensionApiTest { ...@@ -50,8 +46,6 @@ class BluetoothApiTest : public ExtensionApiTest {
ExtensionApiTest::SetUpOnMainThread(); ExtensionApiTest::SetUpOnMainThread();
empty_extension_ = utils::CreateEmptyExtension(); empty_extension_ = utils::CreateEmptyExtension();
SetUpMockAdapter(); SetUpMockAdapter();
profile1_.reset(new testing::NiceMock<MockBluetoothProfile>());
profile2_.reset(new testing::NiceMock<MockBluetoothProfile>());
} }
virtual void CleanUpOnMainThread() OVERRIDE { virtual void CleanUpOnMainThread() OVERRIDE {
...@@ -98,8 +92,6 @@ class BluetoothApiTest : public ExtensionApiTest { ...@@ -98,8 +92,6 @@ class BluetoothApiTest : public ExtensionApiTest {
scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_; scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_;
scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device2_; scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device2_;
scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device3_; scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device3_;
scoped_ptr<testing::NiceMock<MockBluetoothProfile> > profile1_;
scoped_ptr<testing::NiceMock<MockBluetoothProfile> > profile2_;
extensions::BluetoothEventRouter* event_router() { extensions::BluetoothEventRouter* event_router() {
return bluetooth_api()->event_router(); return bluetooth_api()->event_router();
...@@ -113,29 +105,6 @@ class BluetoothApiTest : public ExtensionApiTest { ...@@ -113,29 +105,6 @@ class BluetoothApiTest : public ExtensionApiTest {
scoped_refptr<Extension> empty_extension_; scoped_refptr<Extension> empty_extension_;
}; };
class TestBluetoothAddProfileFunction
: public api::BluetoothAddProfileFunction {
public:
explicit TestBluetoothAddProfileFunction(BluetoothProfile* profile)
: BluetoothAddProfileFunction(), profile_(profile) {
}
protected:
virtual ~TestBluetoothAddProfileFunction() {
}
// BluetoothAddProfileFunction override.
virtual void RegisterProfile(
const device::BluetoothProfile::Options& options,
const device::BluetoothProfile::ProfileCallback& callback) OVERRIDE {
callback.Run(profile_);
}
private:
// TestBluetoothAddProfileFunction does not own |profile_|.
BluetoothProfile* profile_;
};
static void StopDiscoverySessionCallback(const base::Closure& callback, static void StopDiscoverySessionCallback(const base::Closure& callback,
const base::Closure& error_callback) { const base::Closure& error_callback) {
callback.Run(); callback.Run();
...@@ -143,69 +112,6 @@ static void StopDiscoverySessionCallback(const base::Closure& callback, ...@@ -143,69 +112,6 @@ static void StopDiscoverySessionCallback(const base::Closure& callback,
} // namespace } // namespace
IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Profiles) {
// Run in context of an extension that has permissions for the profiles
// we intend to register.
scoped_refptr<const Extension> extension(
LoadExtension(test_data_dir_.AppendASCII("bluetooth/profiles")));
ASSERT_TRUE(extension.get());
EXPECT_CALL(*profile1_, SetConnectionCallback(testing::_));
scoped_refptr<TestBluetoothAddProfileFunction> add_profile_function;
add_profile_function = new TestBluetoothAddProfileFunction(profile1_.get());
add_profile_function->set_extension(extension.get());
add_profile_function->set_has_callback(true);
std::string error(utils::RunFunctionAndReturnError(
add_profile_function.get(), "[{\"uuid\": \"1234\"}]", browser()));
ASSERT_TRUE(error.empty());
// Registering the profile for the same uuid again will throw an error.
add_profile_function = new TestBluetoothAddProfileFunction(profile2_.get());
add_profile_function->set_extension(extension.get());
add_profile_function->set_has_callback(true);
error = utils::RunFunctionAndReturnError(
add_profile_function.get(), "[{\"uuid\": \"1234\"}]", browser());
ASSERT_FALSE(error.empty());
add_profile_function = new TestBluetoothAddProfileFunction(profile2_.get());
add_profile_function->set_extension(extension.get());
add_profile_function->set_has_callback(true);
error = utils::RunFunctionAndReturnError(
add_profile_function.get(), "[{\"uuid\": \"5678\"}]", browser());
ASSERT_TRUE(error.empty());
scoped_refptr<api::BluetoothRemoveProfileFunction> remove_profile_function;
remove_profile_function = new api::BluetoothRemoveProfileFunction();
remove_profile_function->set_extension(extension.get());
remove_profile_function->set_has_callback(true);
error = utils::RunFunctionAndReturnError(
remove_profile_function.get(), "[{\"uuid\": \"1234\"}]", browser());
ASSERT_TRUE(error.empty());
remove_profile_function = new api::BluetoothRemoveProfileFunction();
remove_profile_function->set_extension(extension.get());
remove_profile_function->set_has_callback(true);
error = utils::RunFunctionAndReturnError(
remove_profile_function.get(), "[{\"uuid\": \"5678\"}]", browser());
ASSERT_TRUE(error.empty());
// Removing the same profile again will throw an error.
remove_profile_function = new api::BluetoothRemoveProfileFunction();
remove_profile_function->set_extension(extension.get());
remove_profile_function->set_has_callback(true);
error = utils::RunFunctionAndReturnError(
remove_profile_function.get(), "[{\"uuid\": \"5678\"}]", browser());
ASSERT_FALSE(error.empty());
// Registering a profile we don't have permission for will throw an error.
add_profile_function = new TestBluetoothAddProfileFunction(profile1_.get());
add_profile_function->set_extension(extension.get());
add_profile_function->set_has_callback(true);
error = utils::RunFunctionAndReturnError(
add_profile_function.get(), "[{\"uuid\": \"9999\"}]", browser());
ASSERT_FALSE(error.empty());
}
IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetAdapterState) { IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetAdapterState) {
EXPECT_CALL(*mock_adapter_, GetAddress()) EXPECT_CALL(*mock_adapter_, GetAddress())
.WillOnce(testing::Return(kAdapterAddress)); .WillOnce(testing::Return(kAdapterAddress));
...@@ -449,37 +355,6 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnAdapterStateChanged) { ...@@ -449,37 +355,6 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnAdapterStateChanged) {
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
} }
IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnConnection) {
ResultCatcher catcher;
catcher.RestrictToProfile(browser()->profile());
// Load and wait for setup
ExtensionTestMessageListener listener("ready", true);
scoped_refptr<const Extension> extension(
LoadExtension(test_data_dir_.AppendASCII("bluetooth/on_connection")));
ASSERT_TRUE(extension.get());
EXPECT_TRUE(listener.WaitUntilSatisfied());
scoped_refptr<device::MockBluetoothSocket> socket =
new device::MockBluetoothSocket();
EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress()))
.WillOnce(testing::Return(device1_.get()));
event_router()->AddProfile(
BluetoothUUID("1234"), extension->id(), profile1_.get());
bluetooth_api()->DispatchConnectionEvent(
extension->id(), BluetoothUUID("1234"), device1_.get(), socket);
// Connection events are dispatched using a couple of PostTask to the UI
// thread. Waiting until idle ensures the event is dispatched to the
// receiver(s).
base::RunLoop().RunUntilIdle();
listener.Reply("go");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
event_router()->RemoveProfile(BluetoothUUID("1234"));
}
IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) {
ResultCatcher catcher; ResultCatcher catcher;
catcher.RestrictToProfile(browser()->profile()); catcher.RestrictToProfile(browser()->profile());
......
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_discovery_session.h" #include "device/bluetooth/bluetooth_discovery_session.h"
#include "device/bluetooth/bluetooth_profile.h"
#include "device/bluetooth/bluetooth_socket.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/browser/extension_host.h" #include "extensions/browser/extension_host.h"
...@@ -37,12 +35,6 @@ namespace extensions { ...@@ -37,12 +35,6 @@ namespace extensions {
namespace bluetooth = api::bluetooth; namespace bluetooth = api::bluetooth;
namespace bt_private = api::bluetooth_private; namespace bt_private = api::bluetooth_private;
// A struct storing a Bluetooth profile and the extension that added it.
struct BluetoothEventRouter::ExtensionBluetoothProfileRecord {
std::string extension_id;
device::BluetoothProfile* profile;
};
BluetoothEventRouter::BluetoothEventRouter(content::BrowserContext* context) BluetoothEventRouter::BluetoothEventRouter(content::BrowserContext* context)
: browser_context_(context), : browser_context_(context),
adapter_(NULL), adapter_(NULL),
...@@ -82,31 +74,6 @@ void BluetoothEventRouter::GetAdapter( ...@@ -82,31 +74,6 @@ void BluetoothEventRouter::GetAdapter(
device::BluetoothAdapterFactory::GetAdapter(callback); device::BluetoothAdapterFactory::GetAdapter(callback);
} }
void BluetoothEventRouter::AddProfile(
const device::BluetoothUUID& uuid,
const std::string& extension_id,
device::BluetoothProfile* bluetooth_profile) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK(!HasProfile(uuid));
ExtensionBluetoothProfileRecord record = { extension_id, bluetooth_profile };
bluetooth_profile_map_[uuid] = record;
}
void BluetoothEventRouter::RemoveProfile(const device::BluetoothUUID& uuid) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
BluetoothProfileMap::iterator iter = bluetooth_profile_map_.find(uuid);
if (iter != bluetooth_profile_map_.end()) {
device::BluetoothProfile* bluetooth_profile = iter->second.profile;
bluetooth_profile_map_.erase(iter);
bluetooth_profile->Unregister();
}
}
bool BluetoothEventRouter::HasProfile(const device::BluetoothUUID& uuid) const {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
return bluetooth_profile_map_.find(uuid) != bluetooth_profile_map_.end();
}
void BluetoothEventRouter::StartDiscoverySession( void BluetoothEventRouter::StartDiscoverySession(
device::BluetoothAdapter* adapter, device::BluetoothAdapter* adapter,
const std::string& extension_id, const std::string& extension_id,
...@@ -151,16 +118,6 @@ void BluetoothEventRouter::StopDiscoverySession( ...@@ -151,16 +118,6 @@ void BluetoothEventRouter::StopDiscoverySession(
session->Stop(callback, error_callback); session->Stop(callback, error_callback);
} }
device::BluetoothProfile* BluetoothEventRouter::GetProfile(
const device::BluetoothUUID& uuid) const {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
BluetoothProfileMap::const_iterator iter = bluetooth_profile_map_.find(uuid);
if (iter != bluetooth_profile_map_.end())
return iter->second.profile;
return NULL;
}
BluetoothApiPairingDelegate* BluetoothEventRouter::GetPairingDelegate( BluetoothApiPairingDelegate* BluetoothEventRouter::GetPairingDelegate(
const std::string& extension_id) { const std::string& extension_id) {
return ContainsKey(pairing_delegate_map_, extension_id) return ContainsKey(pairing_delegate_map_, extension_id)
...@@ -355,18 +312,6 @@ void BluetoothEventRouter::CleanUpForExtension( ...@@ -355,18 +312,6 @@ void BluetoothEventRouter::CleanUpForExtension(
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
RemovePairingDelegate(extension_id); RemovePairingDelegate(extension_id);
// Remove all profiles added by the extension.
BluetoothProfileMap::iterator profile_iter = bluetooth_profile_map_.begin();
while (profile_iter != bluetooth_profile_map_.end()) {
ExtensionBluetoothProfileRecord record = profile_iter->second;
if (record.extension_id == extension_id) {
bluetooth_profile_map_.erase(profile_iter++);
record.profile->Unregister();
} else {
profile_iter++;
}
}
// Remove any discovery session initiated by the extension. // Remove any discovery session initiated by the extension.
DiscoverySessionMap::iterator session_iter = DiscoverySessionMap::iterator session_iter =
discovery_session_map_.find(extension_id); discovery_session_map_.find(extension_id);
...@@ -377,13 +322,6 @@ void BluetoothEventRouter::CleanUpForExtension( ...@@ -377,13 +322,6 @@ void BluetoothEventRouter::CleanUpForExtension(
} }
void BluetoothEventRouter::CleanUpAllExtensions() { void BluetoothEventRouter::CleanUpAllExtensions() {
for (BluetoothProfileMap::iterator it = bluetooth_profile_map_.begin();
it != bluetooth_profile_map_.end();
++it) {
it->second.profile->Unregister();
}
bluetooth_profile_map_.clear();
for (DiscoverySessionMap::iterator it = discovery_session_map_.begin(); for (DiscoverySessionMap::iterator it = discovery_session_map_.begin();
it != discovery_session_map_.end(); it != discovery_session_map_.end();
++it) { ++it) {
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_socket.h"
#include "device/bluetooth/bluetooth_uuid.h"
namespace content { namespace content {
class BrowserContext; class BrowserContext;
...@@ -28,7 +26,6 @@ namespace device { ...@@ -28,7 +26,6 @@ namespace device {
class BluetoothDevice; class BluetoothDevice;
class BluetoothDiscoverySession; class BluetoothDiscoverySession;
class BluetoothProfile;
} // namespace device } // namespace device
...@@ -49,22 +46,6 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer, ...@@ -49,22 +46,6 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer,
void GetAdapter( void GetAdapter(
const device::BluetoothAdapterFactory::AdapterCallback& callback); const device::BluetoothAdapterFactory::AdapterCallback& callback);
// Add the BluetoothProfile |bluetooth_profile| for use by the extension
// system. This class will hold onto the profile until RemoveProfile is
// called for the profile, or until the extension that added the profile
// is disabled/reloaded.
void AddProfile(const device::BluetoothUUID& uuid,
const std::string& extension_id,
device::BluetoothProfile* bluetooth_profile);
// Unregister the BluetoothProfile corersponding to |uuid| and release the
// object from this class.
void RemoveProfile(const device::BluetoothUUID& uuid);
// Returns true if the BluetoothProfile corresponding to |uuid| is already
// registered.
bool HasProfile(const device::BluetoothUUID& uuid) const;
// Requests that a new device discovery session be initiated for extension // Requests that a new device discovery session be initiated for extension
// with id |extension_id|. |callback| is called, if a session has been // with id |extension_id|. |callback| is called, if a session has been
// initiated. |error_callback| is called, if the adapter failed to initiate // initiated. |error_callback| is called, if the adapter failed to initiate
...@@ -84,10 +65,6 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer, ...@@ -84,10 +65,6 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer,
const base::Closure& callback, const base::Closure& callback,
const base::Closure& error_callback); const base::Closure& error_callback);
// Returns the BluetoothProfile that corresponds to |uuid|. It returns NULL
// if the BluetoothProfile with |uuid| does not exist.
device::BluetoothProfile* GetProfile(const device::BluetoothUUID& uuid) const;
// Called when a bluetooth event listener is added. // Called when a bluetooth event listener is added.
void OnListenerAdded(); void OnListenerAdded();
...@@ -135,10 +112,6 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer, ...@@ -135,10 +112,6 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer,
static const bool kServiceIsNULLWhileTesting = true; static const bool kServiceIsNULLWhileTesting = true;
private: private:
// Forward declarations of internal structs.
struct ExtensionBluetoothSocketRecord;
struct ExtensionBluetoothProfileRecord;
void OnAdapterInitialized(const base::Closure& callback, void OnAdapterInitialized(const base::Closure& callback,
scoped_refptr<device::BluetoothAdapter> adapter); scoped_refptr<device::BluetoothAdapter> adapter);
void MaybeReleaseAdapter(); void MaybeReleaseAdapter();
...@@ -157,12 +130,6 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer, ...@@ -157,12 +130,6 @@ class BluetoothEventRouter : public device::BluetoothAdapter::Observer,
int num_event_listeners_; int num_event_listeners_;
// Maps uuids to a struct containing a Bluetooth profile and its
// associated extension id.
typedef std::map<device::BluetoothUUID, ExtensionBluetoothProfileRecord>
BluetoothProfileMap;
BluetoothProfileMap bluetooth_profile_map_;
// A map that maps extension ids to BluetoothDiscoverySession pointers. // A map that maps extension ids to BluetoothDiscoverySession pointers.
typedef std::map<std::string, device::BluetoothDiscoverySession*> typedef std::map<std::string, device::BluetoothDiscoverySession*>
DiscoverySessionMap; DiscoverySessionMap;
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
#include "device/bluetooth/bluetooth_uuid.h" #include "device/bluetooth/bluetooth_uuid.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/bluetooth/test/mock_bluetooth_device.h" #include "device/bluetooth/test/mock_bluetooth_device.h"
#include "device/bluetooth/test/mock_bluetooth_profile.h"
#include "device/bluetooth/test/mock_bluetooth_socket.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
#include "extensions/common/extension_builder.h" #include "extensions/common/extension_builder.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -63,8 +61,6 @@ class BluetoothEventRouterTest : public testing::Test { ...@@ -63,8 +61,6 @@ class BluetoothEventRouterTest : public testing::Test {
// Note: |ui_thread_| must be declared before |router_|. // Note: |ui_thread_| must be declared before |router_|.
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_;
testing::NiceMock<device::MockBluetoothProfile> mock_audio_profile_;
testing::NiceMock<device::MockBluetoothProfile> mock_health_profile_;
scoped_ptr<TestingProfile> test_profile_; scoped_ptr<TestingProfile> test_profile_;
BluetoothEventRouter router_; BluetoothEventRouter router_;
}; };
...@@ -85,27 +81,6 @@ TEST_F(BluetoothEventRouterTest, MultipleBluetoothEventListeners) { ...@@ -85,27 +81,6 @@ TEST_F(BluetoothEventRouterTest, MultipleBluetoothEventListeners) {
router_.OnListenerRemoved(); router_.OnListenerRemoved();
} }
TEST_F(BluetoothEventRouterTest, Profiles) {
EXPECT_FALSE(router_.HasProfile(kAudioProfileUuid));
EXPECT_FALSE(router_.HasProfile(kHealthProfileUuid));
router_.AddProfile(
kAudioProfileUuid, kTestExtensionId, &mock_audio_profile_);
router_.AddProfile(
kHealthProfileUuid, kTestExtensionId, &mock_health_profile_);
EXPECT_TRUE(router_.HasProfile(kAudioProfileUuid));
EXPECT_TRUE(router_.HasProfile(kHealthProfileUuid));
EXPECT_CALL(mock_audio_profile_, Unregister()).Times(1);
router_.RemoveProfile(kAudioProfileUuid);
EXPECT_FALSE(router_.HasProfile(kAudioProfileUuid));
EXPECT_TRUE(router_.HasProfile(kHealthProfileUuid));
// Make sure remaining profiles are unregistered in destructor.
EXPECT_CALL(mock_health_profile_, Unregister()).Times(1);
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
}
TEST_F(BluetoothEventRouterTest, UnloadExtension) { TEST_F(BluetoothEventRouterTest, UnloadExtension) {
scoped_refptr<const extensions::Extension> extension = scoped_refptr<const extensions::Extension> extension =
extensions::ExtensionBuilder() extensions::ExtensionBuilder()
...@@ -116,17 +91,6 @@ TEST_F(BluetoothEventRouterTest, UnloadExtension) { ...@@ -116,17 +91,6 @@ TEST_F(BluetoothEventRouterTest, UnloadExtension) {
.SetID(kTestExtensionId) .SetID(kTestExtensionId)
.Build(); .Build();
router_.AddProfile(
kAudioProfileUuid, kTestExtensionId, &mock_audio_profile_);
router_.AddProfile(
kHealthProfileUuid, kTestExtensionId, &mock_health_profile_);
EXPECT_TRUE(router_.HasProfile(kAudioProfileUuid));
EXPECT_TRUE(router_.HasProfile(kHealthProfileUuid));
// Unloading the extension should unregister all profiles added by it.
EXPECT_CALL(mock_audio_profile_, Unregister()).Times(1);
EXPECT_CALL(mock_health_profile_, Unregister()).Times(1);
content::NotificationService* notifier = content::NotificationService* notifier =
content::NotificationService::current(); content::NotificationService::current();
UnloadedExtensionInfo details( UnloadedExtensionInfo details(
...@@ -135,8 +99,6 @@ TEST_F(BluetoothEventRouterTest, UnloadExtension) { ...@@ -135,8 +99,6 @@ TEST_F(BluetoothEventRouterTest, UnloadExtension) {
content::Source<Profile>(test_profile_.get()), content::Source<Profile>(test_profile_.get()),
content::Details<UnloadedExtensionInfo>(&details)); content::Details<UnloadedExtensionInfo>(&details));
EXPECT_FALSE(router_.HasProfile(kAudioProfileUuid));
EXPECT_FALSE(router_.HasProfile(kHealthProfileUuid));
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.h" #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_api_socket.h"
#include "device/bluetooth/bluetooth_socket.h" #include "device/bluetooth/bluetooth_socket.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_SOCKET_H_ #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_SOCKET_BLUETOOTH_API_SOCKET_H_
#define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_SOCKET_H_ #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_SOCKET_BLUETOOTH_API_SOCKET_H_
#include <string> #include <string>
...@@ -158,4 +158,4 @@ class BluetoothApiSocket : public ApiResource { ...@@ -158,4 +158,4 @@ class BluetoothApiSocket : public ApiResource {
} // namespace extensions } // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_SOCKET_H_ #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_SOCKET_BLUETOOTH_API_SOCKET_H_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_api.h" #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_api.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.h" #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_api_socket.h"
#include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_event_dispatcher.h" #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_event_dispatcher.h"
#include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/containers/hash_tables.h" #include "base/containers/hash_tables.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.h" #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_api_socket.h"
#include "chrome/common/extensions/api/bluetooth_socket.h" #include "chrome/common/extensions/api/bluetooth_socket.h"
#include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter.h"
#include "extensions/browser/api/api_resource_manager.h" #include "extensions/browser/api/api_resource_manager.h"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_event_dispatcher.h" #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_event_dispatcher.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.h" #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_api_socket.h"
#include "chrome/common/extensions/api/bluetooth_socket.h" #include "chrome/common/extensions/api/bluetooth_socket.h"
#include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/bluetooth_socket.h" #include "device/bluetooth/bluetooth_socket.h"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_EVENT_DISPATCHER_H_ #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_EVENT_DISPATCHER_H_
#define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_EVENT_DISPATCHER_H_ #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_SOCKET_BLUETOOTH_SOCKET_EVENT_DISPATCHER_H_
#include "chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.h" #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_api_socket.h"
#include "extensions/browser/api/api_resource_manager.h" #include "extensions/browser/api/api_resource_manager.h"
#include "extensions/browser/browser_context_keyed_api_factory.h" #include "extensions/browser/browser_context_keyed_api_factory.h"
......
...@@ -155,8 +155,6 @@ ...@@ -155,8 +155,6 @@
'browser/extensions/api/bluetooth/bluetooth_api.h', 'browser/extensions/api/bluetooth/bluetooth_api.h',
'browser/extensions/api/bluetooth/bluetooth_api_pairing_delegate.cc', 'browser/extensions/api/bluetooth/bluetooth_api_pairing_delegate.cc',
'browser/extensions/api/bluetooth/bluetooth_api_pairing_delegate.h', 'browser/extensions/api/bluetooth/bluetooth_api_pairing_delegate.h',
'browser/extensions/api/bluetooth/bluetooth_api_socket.h',
'browser/extensions/api/bluetooth/bluetooth_api_socket.cc',
'browser/extensions/api/bluetooth/bluetooth_api_utils.cc', 'browser/extensions/api/bluetooth/bluetooth_api_utils.cc',
'browser/extensions/api/bluetooth/bluetooth_api_utils.h', 'browser/extensions/api/bluetooth/bluetooth_api_utils.h',
'browser/extensions/api/bluetooth/bluetooth_event_router.cc', 'browser/extensions/api/bluetooth/bluetooth_event_router.cc',
...@@ -171,6 +169,8 @@ ...@@ -171,6 +169,8 @@
'browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h', 'browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h',
'browser/extensions/api/bluetooth_low_energy/utils.cc', 'browser/extensions/api/bluetooth_low_energy/utils.cc',
'browser/extensions/api/bluetooth_low_energy/utils.h', 'browser/extensions/api/bluetooth_low_energy/utils.h',
'browser/extensions/api/bluetooth_socket/bluetooth_api_socket.h',
'browser/extensions/api/bluetooth_socket/bluetooth_api_socket.cc',
'browser/extensions/api/bluetooth_socket/bluetooth_socket_api.cc', 'browser/extensions/api/bluetooth_socket/bluetooth_socket_api.cc',
'browser/extensions/api/bluetooth_socket/bluetooth_socket_api.h', 'browser/extensions/api/bluetooth_socket/bluetooth_socket_api.h',
'browser/extensions/api/bluetooth_socket/bluetooth_socket_event_dispatcher.cc', 'browser/extensions/api/bluetooth_socket/bluetooth_socket_event_dispatcher.cc',
......
...@@ -857,7 +857,6 @@ ...@@ -857,7 +857,6 @@
'browser/extensions/api/activity_log_private/activity_log_private_api_unittest.cc', 'browser/extensions/api/activity_log_private/activity_log_private_api_unittest.cc',
'browser/extensions/api/alarms/alarms_api_unittest.cc', 'browser/extensions/api/alarms/alarms_api_unittest.cc',
'browser/extensions/api/api_resource_manager_unittest.cc', 'browser/extensions/api/api_resource_manager_unittest.cc',
'browser/extensions/api/bluetooth/bluetooth_api_unittest.cc',
'browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc', 'browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc',
'browser/extensions/api/bookmarks/bookmark_api_helpers_unittest.cc', 'browser/extensions/api/bookmarks/bookmark_api_helpers_unittest.cc',
'browser/extensions/api/cast_channel/cast_channel_api_unittest.cc', 'browser/extensions/api/cast_channel/cast_channel_api_unittest.cc',
......
This diff is collapsed.
{
"manifest_version": 2,
"name": "Test Bluetooth OnConnection Event",
"version": "1.0",
"description": "Tests Bluetooth OnConnection Event",
"app": {
"background": {
"scripts": ["runtest.js"]
}
},
"bluetooth": { "uuids": ["1234"] }
}
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var deviceName;
var deviceAddress;
var profileUuid;
function testOnConnectionEvent() {
chrome.test.assertEq('d1', deviceName);
chrome.test.assertEq('11:12:13:14:15:16', deviceAddress);
chrome.test.assertEq('00001234-0000-1000-8000-00805f9b34fb', profileUuid);
chrome.test.succeed();
}
chrome.bluetooth.onConnection.addListener(
function(socket) {
deviceName = socket.device.name;
deviceAddress = socket.device.address;
profileUuid = socket.uuid;
chrome.bluetooth.disconnect({'socketId': socket.id});
});
chrome.test.sendMessage('ready',
function(message) {
chrome.test.runTests([testOnConnectionEvent]);
});
{
"manifest_version": 2,
"name": "Test Bluetooth AddProfile Function",
"version": "1.0",
"description": "Tests Bluetooth AddProfile Function",
"app": {
"background": {
"scripts": ["runtest.js"]
}
},
"bluetooth": {
"uuids": [
"1234",
"5678"
]
}
}
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment