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

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: Change ref to pointer 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
« no previous file with comments | « content/renderer/bluetooth/web_bluetooth_impl.h ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2f4da53dcdf5c738f596ba78add30dfb0011624b..f2f474ef94ba60ac82c2a0ef6f22282c2d91f33e 100644
--- a/content/renderer/bluetooth/web_bluetooth_impl.cc
+++ b/content/renderer/bluetooth/web_bluetooth_impl.cc
@@ -12,23 +12,20 @@
#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/WebBluetoothDeviceInit.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() {
}
@@ -36,7 +33,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(
@@ -154,6 +155,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::WebBluetoothDeviceInit(
+ blink::WebString::fromUTF8(device->id),
+ blink::WebString::fromUTF8(device->name), uuids)));
+ } else {
+ callbacks->onError(error);
+ }
+}
+
void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) {
auto device_iter = connected_devices_.find(device_id);
if (device_iter != connected_devices_.end()) {
@@ -260,11 +278,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(
« no previous file with comments | « content/renderer/bluetooth/web_bluetooth_impl.h ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698