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

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

Issue 1922923002: bluetooth: Move requestDevice to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-request-device
Patch Set: Address moar comments! 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..f1c1b6486b2c2ff74820d1949bf41e493e44a0fb 100644
--- a/content/renderer/bluetooth/web_bluetooth_impl.cc
+++ b/content/renderer/bluetooth/web_bluetooth_impl.cc
@@ -12,22 +12,19 @@
#include "content/child/mojo/type_converters.h"
#include "content/child/thread_safe_sender.h"
#include "content/public/common/service_registry.h"
-#include "content/renderer/bluetooth/bluetooth_dispatcher.h"
+#include "content/renderer/bluetooth/bluetooth_type_converters.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"
+#include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceOptions.h"
namespace content {
-WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry,
- ThreadSafeSender* thread_safe_sender,
- int frame_routing_id)
- : service_registry_(service_registry),
- binding_(this),
- thread_safe_sender_(thread_safe_sender),
- frame_routing_id_(frame_routing_id) {}
+WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry)
+ : service_registry_(service_registry), binding_(this) {}
WebBluetoothImpl::~WebBluetoothImpl() {
}
@@ -35,7 +32,11 @@ WebBluetoothImpl::~WebBluetoothImpl() {
void WebBluetoothImpl::requestDevice(
const blink::WebRequestDeviceOptions& options,
blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
- GetDispatcher()->requestDevice(frame_routing_id_, options, callbacks);
+ GetWebBluetoothService().RequestDevice(
+ blink::mojom::WebBluetoothRequestDeviceOptions::From(options),
+ base::Bind(&WebBluetoothImpl::OnRequestDeviceComplete,
+ base::Unretained(this),
+ base::Passed(base::WrapUnique(callbacks))));
}
void WebBluetoothImpl::connect(
@@ -146,6 +147,23 @@ void WebBluetoothImpl::RemoteCharacteristicValueChanged(
value.PassStorage()));
}
+void WebBluetoothImpl::OnRequestDeviceComplete(
+ std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks,
+ const blink::mojom::WebBluetoothError error,
+ blink::mojom::WebBluetoothDevicePtr device) {
+ if (error == blink::mojom::WebBluetoothError::SUCCESS) {
+ blink::WebVector<blink::WebString> uuids(device->uuids.size());
+ for (size_t i = 0; i < device->uuids.size(); ++i)
+ uuids[i] = blink::WebString::fromUTF8(device->uuids[i]);
+
+ callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDevice(
+ blink::WebString::fromUTF8(device->id),
+ blink::WebString::fromUTF8(device->name), uuids)));
+ } else {
+ callbacks->onError(error);
+ }
+}
+
void WebBluetoothImpl::OnConnectComplete(
std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks>
callbacks,
@@ -244,11 +262,6 @@ void WebBluetoothImpl::DispatchCharacteristicValueChanged(
}
}
-BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() {
- return BluetoothDispatcher::GetOrCreateThreadSpecificInstance(
- thread_safe_sender_.get());
-}
-
blink::mojom::WebBluetoothService& WebBluetoothImpl::GetWebBluetoothService() {
if (!web_bluetooth_service_) {
service_registry_->ConnectToRemoteService(

Powered by Google App Engine
This is Rietveld 408576698