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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/bluetooth/web_bluetooth_impl.h" 5 #include "content/renderer/bluetooth/web_bluetooth_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "content/child/mojo/type_converters.h" 12 #include "content/child/mojo/type_converters.h"
13 #include "content/child/thread_safe_sender.h" 13 #include "content/child/thread_safe_sender.h"
14 #include "content/public/common/service_registry.h" 14 #include "content/public/common/service_registry.h"
15 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" 15 #include "content/renderer/bluetooth/bluetooth_dispatcher.h"
16 #include "ipc/ipc_message.h" 16 #include "ipc/ipc_message.h"
17 #include "mojo/public/cpp/bindings/array.h" 17 #include "mojo/public/cpp/bindings/array.h"
18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h"
18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h" 19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h"
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h" 20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h"
20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTService.h" 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTService.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry, 25 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry,
25 ThreadSafeSender* thread_safe_sender, 26 ThreadSafeSender* thread_safe_sender,
26 int frame_routing_id) 27 int frame_routing_id)
27 : service_registry_(service_registry), 28 : service_registry_(service_registry),
28 binding_(this), 29 binding_(this),
29 thread_safe_sender_(thread_safe_sender), 30 thread_safe_sender_(thread_safe_sender),
30 frame_routing_id_(frame_routing_id) {} 31 frame_routing_id_(frame_routing_id) {}
31 32
32 WebBluetoothImpl::~WebBluetoothImpl() { 33 WebBluetoothImpl::~WebBluetoothImpl() {
33 } 34 }
34 35
35 void WebBluetoothImpl::requestDevice( 36 void WebBluetoothImpl::requestDevice(
36 const blink::WebRequestDeviceOptions& options, 37 const blink::WebRequestDeviceOptions& options,
37 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { 38 blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
38 GetDispatcher()->requestDevice(frame_routing_id_, options, callbacks); 39 GetDispatcher()->requestDevice(frame_routing_id_, options, callbacks);
39 } 40 }
40 41
41 void WebBluetoothImpl::connect( 42 void WebBluetoothImpl::connect(
42 const blink::WebString& device_id, 43 const blink::WebString& device_id,
44 blink::WebBluetoothDevice* device,
43 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) { 45 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) {
46 // TODO(crbug.com/495270): After the Bluetooth Tree is implemented, there will
47 // only be one object per device. But for now we replace the previous object.
48 connected_devices_[device_id.utf8()] = device;
49
44 GetWebBluetoothService().RemoteServerConnect( 50 GetWebBluetoothService().RemoteServerConnect(
45 mojo::String::From(device_id), 51 mojo::String::From(device_id),
46 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this), 52 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this),
47 base::Passed(base::WrapUnique(callbacks)))); 53 base::Passed(base::WrapUnique(callbacks))));
48 } 54 }
49 55
50 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) { 56 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) {
57 connected_devices_.erase(device_id.utf8());
58
51 GetWebBluetoothService().RemoteServerDisconnect( 59 GetWebBluetoothService().RemoteServerDisconnect(
52 mojo::String::From(device_id)); 60 mojo::String::From(device_id));
53 } 61 }
54 62
55 void WebBluetoothImpl::getPrimaryService( 63 void WebBluetoothImpl::getPrimaryService(
56 const blink::WebString& device_id, 64 const blink::WebString& device_id,
57 const blink::WebString& service_uuid, 65 const blink::WebString& service_uuid,
58 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { 66 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) {
59 GetWebBluetoothService().RemoteServerGetPrimaryService( 67 GetWebBluetoothService().RemoteServerGetPrimaryService(
60 mojo::String::From(device_id), mojo::String::From(service_uuid), 68 mojo::String::From(device_id), mojo::String::From(service_uuid),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 mojo::Array<uint8_t> value) { 147 mojo::Array<uint8_t> value) {
140 // We post a task so that the event is fired after any pending promises have 148 // We post a task so that the event is fired after any pending promises have
141 // resolved. 149 // resolved.
142 base::ThreadTaskRunnerHandle::Get()->PostTask( 150 base::ThreadTaskRunnerHandle::Get()->PostTask(
143 FROM_HERE, 151 FROM_HERE,
144 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, 152 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged,
145 base::Unretained(this), characteristic_instance_id, 153 base::Unretained(this), characteristic_instance_id,
146 value.PassStorage())); 154 value.PassStorage()));
147 } 155 }
148 156
157 void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) {
158 auto device_iter = connected_devices_.find(device_id);
159 if (device_iter != connected_devices_.end()) {
160 device_iter->second->dispatchGattServerDisconnected();
161 connected_devices_.erase(device_iter);
162 }
163 }
164
149 void WebBluetoothImpl::OnConnectComplete( 165 void WebBluetoothImpl::OnConnectComplete(
150 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> 166 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks>
151 callbacks, 167 callbacks,
152 blink::mojom::WebBluetoothError error) { 168 blink::mojom::WebBluetoothError error) {
153 if (error == blink::mojom::WebBluetoothError::SUCCESS) { 169 if (error == blink::mojom::WebBluetoothError::SUCCESS) {
154 callbacks->onSuccess(); 170 callbacks->onSuccess();
155 } else { 171 } else {
156 callbacks->onError(error); 172 callbacks->onError(error);
157 } 173 }
158 } 174 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // Create an associated interface ptr and pass it to the WebBluetoothService 272 // Create an associated interface ptr and pass it to the WebBluetoothService
257 // so that it can send us events without us prompting. 273 // so that it can send us events without us prompting.
258 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; 274 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info;
259 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); 275 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group());
260 web_bluetooth_service_->SetClient(std::move(ptr_info)); 276 web_bluetooth_service_->SetClient(std::move(ptr_info));
261 } 277 }
262 return *web_bluetooth_service_; 278 return *web_bluetooth_service_;
263 } 279 }
264 280
265 } // namespace content 281 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698