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

Unified Diff: content/renderer/bluetooth/web_bluetooth_impl.cc

Issue 1991063002: Implement the gattserverdisconnected event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rename-web-bluetooth-device
Patch Set: Skip the new tests on Mac, where getCharacteristic isn't implemented yet. Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/bluetooth/web_bluetooth_impl.cc
diff --git a/content/renderer/bluetooth/web_bluetooth_impl.cc b/content/renderer/bluetooth/web_bluetooth_impl.cc
index 7e7230d8b33f92846adbda413c0d505b8898518f..2f4da53dcdf5c738f596ba78add30dfb0011624b 100644
--- a/content/renderer/bluetooth/web_bluetooth_impl.cc
+++ b/content/renderer/bluetooth/web_bluetooth_impl.cc
@@ -15,6 +15,7 @@
#include "content/renderer/bluetooth/bluetooth_dispatcher.h"
#include "ipc/ipc_message.h"
#include "mojo/public/cpp/bindings/array.h"
+#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevice.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristicInit.h"
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTService.h"
@@ -40,7 +41,12 @@ void WebBluetoothImpl::requestDevice(
void WebBluetoothImpl::connect(
const blink::WebString& device_id,
+ blink::WebBluetoothDevice* device,
blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) {
+ // TODO(crbug.com/495270): After the Bluetooth Tree is implemented, there will
+ // only be one object per device. But for now we replace the previous object.
+ connected_devices_[device_id.utf8()] = device;
+
GetWebBluetoothService().RemoteServerConnect(
mojo::String::From(device_id),
base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this),
@@ -48,6 +54,8 @@ void WebBluetoothImpl::connect(
}
void WebBluetoothImpl::disconnect(const blink::WebString& device_id) {
+ connected_devices_.erase(device_id.utf8());
+
GetWebBluetoothService().RemoteServerDisconnect(
mojo::String::From(device_id));
}
@@ -146,6 +154,14 @@ void WebBluetoothImpl::RemoteCharacteristicValueChanged(
value.PassStorage()));
}
+void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) {
+ auto device_iter = connected_devices_.find(device_id);
+ if (device_iter != connected_devices_.end()) {
+ device_iter->second->dispatchGattServerDisconnected();
+ connected_devices_.erase(device_iter);
+ }
+}
+
void WebBluetoothImpl::OnConnectComplete(
std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks>
callbacks,

Powered by Google App Engine
This is Rietveld 408576698