summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorstevenjb <stevenjb@chromium.org>2015-11-12 15:14:57 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-12 23:16:24 +0000
commit5661293922b3e6b90e87bff3e4bc50aafe6ce033 (patch)
treed01b2e5a16de7159647395e4da45a1d59f111201 /extensions
parent86c81bb1cbb09a2df4b70e6912f5950c90e245d6 (diff)
downloadchromium_src-5661293922b3e6b90e87bff3e4bc50aafe6ce033.zip
chromium_src-5661293922b3e6b90e87bff3e4bc50aafe6ce033.tar.gz
chromium_src-5661293922b3e6b90e87bff3e4bc50aafe6ce033.tar.bz2
Implement bluetoothPrivate.forget
One last method we need in bluetoothPrivate for settings. BUG=543294 Review URL: https://codereview.chromium.org/1429283002 Cr-Commit-Position: refs/heads/master@{#359426}
Diffstat (limited to 'extensions')
-rw-r--r--extensions/browser/api/bluetooth/bluetooth_private_api.cc40
-rw-r--r--extensions/browser/api/bluetooth/bluetooth_private_api.h19
-rw-r--r--extensions/browser/api/bluetooth/bluetooth_private_apitest.cc25
-rw-r--r--extensions/browser/extension_function_histogram_value.h1
-rw-r--r--extensions/common/api/bluetooth_private.idl4
5 files changed, 82 insertions, 7 deletions
diff --git a/extensions/browser/api/bluetooth/bluetooth_private_api.cc b/extensions/browser/api/bluetooth/bluetooth_private_api.cc
index 794ad6a..3ce90e5 100644
--- a/extensions/browser/api/bluetooth/bluetooth_private_api.cc
+++ b/extensions/browser/api/bluetooth/bluetooth_private_api.cc
@@ -87,6 +87,7 @@ const char kInvalidPairingResponseOptions[] =
"Invalid pairing response options";
const char kAdapterNotPresent[] = "Failed to find a Bluetooth adapter";
const char kDisconnectError[] = "Failed to disconnect device";
+const char kForgetDeviceError[] = "Failed to forget device";
const char kSetDiscoveryFilterFailed[] = "Failed to set discovery filter";
const char kPairingFailed[] = "Pairing failed";
@@ -350,6 +351,45 @@ void BluetoothPrivateDisconnectAllFunction::OnErrorCallback(
////////////////////////////////////////////////////////////////////////////////
+BluetoothPrivateForgetDeviceFunction::BluetoothPrivateForgetDeviceFunction() {}
+
+BluetoothPrivateForgetDeviceFunction::~BluetoothPrivateForgetDeviceFunction() {}
+
+bool BluetoothPrivateForgetDeviceFunction::DoWork(
+ scoped_refptr<device::BluetoothAdapter> adapter) {
+ scoped_ptr<bt_private::ForgetDevice::Params> params(
+ bt_private::ForgetDevice::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ device::BluetoothDevice* device = adapter->GetDevice(params->device_address);
+ if (!device) {
+ SetError(kDeviceNotFoundError);
+ SendResponse(false);
+ return true;
+ }
+
+ device->Forget(
+ base::Bind(&BluetoothPrivateForgetDeviceFunction::OnSuccessCallback,
+ this),
+ base::Bind(&BluetoothPrivateForgetDeviceFunction::OnErrorCallback, this,
+ adapter, params->device_address));
+
+ return true;
+}
+
+void BluetoothPrivateForgetDeviceFunction::OnSuccessCallback() {
+ SendResponse(true);
+}
+
+void BluetoothPrivateForgetDeviceFunction::OnErrorCallback(
+ scoped_refptr<device::BluetoothAdapter> adapter,
+ const std::string& device_address) {
+ SetError(kForgetDeviceError);
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
bool BluetoothPrivateSetDiscoveryFilterFunction::DoWork(
scoped_refptr<device::BluetoothAdapter> adapter) {
scoped_ptr<SetDiscoveryFilter::Params> params(
diff --git a/extensions/browser/api/bluetooth/bluetooth_private_api.h b/extensions/browser/api/bluetooth/bluetooth_private_api.h
index 887d18a..a35dc2e 100644
--- a/extensions/browser/api/bluetooth/bluetooth_private_api.h
+++ b/extensions/browser/api/bluetooth/bluetooth_private_api.h
@@ -112,6 +112,25 @@ class BluetoothPrivateDisconnectAllFunction
DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateDisconnectAllFunction);
};
+class BluetoothPrivateForgetDeviceFunction : public BluetoothExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION("bluetoothPrivate.forgetDevice",
+ BLUETOOTHPRIVATE_FORGETDEVICE);
+ BluetoothPrivateForgetDeviceFunction();
+
+ // BluetoothExtensionFunction overrides:
+ bool DoWork(scoped_refptr<device::BluetoothAdapter> adapter) override;
+
+ private:
+ ~BluetoothPrivateForgetDeviceFunction() override;
+
+ void OnSuccessCallback();
+ void OnErrorCallback(scoped_refptr<device::BluetoothAdapter> adapter,
+ const std::string& device_address);
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothPrivateForgetDeviceFunction);
+};
+
class BluetoothPrivateSetDiscoveryFilterFunction
: public BluetoothExtensionFunction {
public:
diff --git a/extensions/browser/api/bluetooth/bluetooth_private_apitest.cc b/extensions/browser/api/bluetooth/bluetooth_private_apitest.cc
index 770154f..766157e 100644
--- a/extensions/browser/api/bluetooth/bluetooth_private_apitest.cc
+++ b/extensions/browser/api/bluetooth/bluetooth_private_apitest.cc
@@ -40,6 +40,7 @@ namespace {
const char kTestExtensionId[] = "jofgjdphhceggjecimellaapdjjadibj";
const char kAdapterName[] = "Helix";
const char kDeviceName[] = "Red";
+const char kDeviceAddress[] = "11:12:13:14:15:16";
MATCHER_P(IsFilterEqual, a, "") {
return arg->Equals(*a);
@@ -60,13 +61,9 @@ class BluetoothPrivateApiTest : public ExtensionApiTest {
switches::kWhitelistedExtensionID, kTestExtensionId);
mock_adapter_ = new NiceMock<MockBluetoothAdapter>();
event_router()->SetAdapterForTest(mock_adapter_.get());
- mock_device_.reset(new NiceMock<MockBluetoothDevice>(mock_adapter_.get(),
- 0,
- kDeviceName,
- "11:12:13:14:15:16",
- false,
- false));
- ON_CALL(*mock_adapter_.get(), GetDevice(mock_device_->GetAddress()))
+ mock_device_.reset(new NiceMock<MockBluetoothDevice>(
+ mock_adapter_.get(), 0, kDeviceName, kDeviceAddress, false, false));
+ ON_CALL(*mock_adapter_.get(), GetDevice(kDeviceAddress))
.WillByDefault(Return(mock_device_.get()));
ON_CALL(*mock_adapter_.get(), IsPresent()).WillByDefault(Return(true));
}
@@ -87,6 +84,12 @@ class BluetoothPrivateApiTest : public ExtensionApiTest {
callback.Run();
}
+ void ForgetDevice(const base::Closure& callback) {
+ mock_device_.reset();
+ event_router()->SetAdapterForTest(nullptr);
+ callback.Run();
+ }
+
void SetDiscoverable(bool discoverable, const base::Closure& callback) {
adapter_discoverable_ = discoverable;
callback.Run();
@@ -231,6 +234,14 @@ IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, DisconnectAll) {
<< message_;
}
+IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, ForgetDevice) {
+ EXPECT_CALL(*mock_device_.get(), Forget(_, _))
+ .WillOnce(
+ WithArgs<0>(Invoke(this, &BluetoothPrivateApiTest::ForgetDevice)));
+ ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/forget_device"))
+ << message_;
+}
+
IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, DiscoveryFilter) {
mock_discovery_session_ = new NiceMock<MockBluetoothDiscoverySession>();
diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h
index 7e9ab9e..1faed63 100644
--- a/extensions/browser/extension_function_histogram_value.h
+++ b/extensions/browser/extension_function_histogram_value.h
@@ -1155,6 +1155,7 @@ enum HistogramValue {
SETTINGSPRIVATE_GETDEFAULTZOOMPERCENTFUNCTION,
SETTINGSPRIVATE_SETDEFAULTZOOMPERCENTFUNCTION,
BLUETOOTHPRIVATE_CONNECT,
+ BLUETOOTHPRIVATE_FORGETDEVICE,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
diff --git a/extensions/common/api/bluetooth_private.idl b/extensions/common/api/bluetooth_private.idl
index 0ef9bc2..e3c60fd8 100644
--- a/extensions/common/api/bluetooth_private.idl
+++ b/extensions/common/api/bluetooth_private.idl
@@ -135,6 +135,10 @@ namespace bluetoothPrivate {
static void disconnectAll(DOMString deviceAddress,
optional VoidCallback callback);
+ // Forgets the given device.
+ static void forgetDevice(DOMString deviceAddress,
+ optional VoidCallback callback);
+
// Set or clear discovery filter.
static void setDiscoveryFilter(DiscoveryFilter discoveryFilter,
optional VoidCallback callback);