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

Side by Side Diff: content/renderer/bluetooth/web_bluetooth_impl.h

Issue 2565913002: [Onion Soup] Move WebBluetoothImpl from //content/renderer/bluetooth to Blink's bluetooth module (Closed)
Patch Set: renamed BluetoothUUID.typemap to Bluetooth.typemap Created 3 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_
6 #define CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12 #include <unordered_map>
13 #include <vector>
14
15 #include "base/compiler_specific.h"
16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/threading/thread_task_runner_handle.h"
19 #include "content/common/bluetooth/web_bluetooth_device_id.h"
20 #include "content/common/content_export.h"
21 #include "mojo/public/cpp/bindings/associated_binding.h"
22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetooth.h"
23 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h"
24
25 namespace blink {
26 class WebBluetoothRemoteGATTCharacteristic;
27 }
28
29 namespace service_manager {
30 class InterfaceProvider;
31 }
32
33 namespace content {
34
35 class BluetoothDispatcher;
36
37 // Implementation of blink::WebBluetooth. Passes calls through to the thread
38 // specific BluetoothDispatcher.
39 class CONTENT_EXPORT WebBluetoothImpl
40 : NON_EXPORTED_BASE(public blink::mojom::WebBluetoothServiceClient),
41 NON_EXPORTED_BASE(public blink::WebBluetooth) {
42 public:
43 WebBluetoothImpl(service_manager::InterfaceProvider* remote_interfaces);
44 ~WebBluetoothImpl() override;
45
46 // blink::WebBluetooth interface:
47 void requestDevice(
48 const blink::WebRequestDeviceOptions& options,
49 blink::WebBluetoothRequestDeviceCallbacks* callbacks) override;
50 void connect(
51 const blink::WebString& device_id,
52 blink::WebBluetoothDevice* device,
53 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) override;
54 void disconnect(const blink::WebString& device_id) override;
55 void getPrimaryServices(
56 const blink::WebString& device_id,
57 int32_t quantity /* Corresponds to WebBluetoothGATTQueryQuantity in
58 web_bluetooth.mojom */,
59 const blink::WebString& services_uuid,
60 blink::WebBluetoothGetPrimaryServicesCallbacks* callbacks) override;
61 void getCharacteristics(
62 const blink::WebString& service_instance_id,
63 int32_t quantity /* Corresponds to WebBluetoothGATTQueryQuantity in
64 web_bluetooth.mojom */,
65 const blink::WebString& characteristics_uuid,
66 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) override;
67 void readValue(const blink::WebString& characteristic_instance_id,
68 blink::WebBluetoothReadValueCallbacks* callbacks) override;
69 void writeValue(const blink::WebString& characteristic_instance_id,
70 const blink::WebVector<uint8_t>& value,
71 blink::WebBluetoothWriteValueCallbacks*) override;
72 void startNotifications(
73 const blink::WebString& characteristic_instance_id,
74 blink::WebBluetoothNotificationsCallbacks*) override;
75 void stopNotifications(
76 const blink::WebString& characteristic_instance_id,
77 blink::WebBluetoothNotificationsCallbacks*) override;
78 void characteristicObjectRemoved(
79 const blink::WebString& characteristic_instance_id,
80 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override;
81 void registerCharacteristicObject(
82 const blink::WebString& characteristic_instance_id,
83 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) override;
84
85 private:
86 struct GetCharacteristicsCallback;
87 // WebBluetoothServiceClient methods:
88 void RemoteCharacteristicValueChanged(
89 const std::string& characteristic_instance_id,
90 const std::vector<uint8_t>& value) override;
91 void GattServerDisconnected(const WebBluetoothDeviceId& device_id) override;
92
93 // Callbacks for WebBluetoothService calls:
94 void OnRequestDeviceComplete(
95 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks,
96 const blink::mojom::WebBluetoothResult result,
97 blink::mojom::WebBluetoothDevicePtr device);
98 void OnConnectComplete(
99 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks>
100 callbacks,
101 blink::mojom::WebBluetoothResult result);
102 void OnGetPrimaryServicesComplete(
103 const blink::WebString& device_id,
104 std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks,
105 blink::mojom::WebBluetoothResult result,
106 base::Optional<
107 std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr>>
108 services);
109 void OnGetCharacteristicsComplete(
110 const blink::WebString& service_instance_id,
111 std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks,
112 blink::mojom::WebBluetoothResult result,
113 base::Optional<
114 std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>>
115 characteristics);
116 void OnReadValueComplete(
117 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks,
118 blink::mojom::WebBluetoothResult result,
119 const base::Optional<std::vector<uint8_t>>& value);
120 void OnWriteValueComplete(
121 const blink::WebVector<uint8_t>& value,
122 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks,
123 blink::mojom::WebBluetoothResult result);
124 void OnStartNotificationsComplete(
125 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks,
126 blink::mojom::WebBluetoothResult result);
127 void OnStopNotificationsComplete(
128 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks);
129
130 void DispatchCharacteristicValueChanged(
131 const std::string& characteristic_instance_id,
132 const std::vector<uint8_t>& value);
133
134 blink::mojom::WebBluetoothService& GetWebBluetoothService();
135 service_manager::InterfaceProvider* const remote_interfaces_;
136 blink::mojom::WebBluetoothServicePtr web_bluetooth_service_;
137
138 // Map of characteristic_instance_ids to
139 // WebBluetoothRemoteGATTCharacteristics. When characteristicObjectRemoved is
140 // called the characteristic should be removed from the map.
141 // Keeps track of what characteristics have listeners.
142 std::unordered_map<std::string, blink::WebBluetoothRemoteGATTCharacteristic*>
143 active_characteristics_;
144
145 // Map of device_ids to WebBluetoothDevices. Added in connect() and removed in
146 // disconnect(). This means a device may not actually be connected while in
147 // this map, but that it will definitely be removed when the page navigates.
148 std::unordered_map<WebBluetoothDeviceId,
149 blink::WebBluetoothDevice*,
150 WebBluetoothDeviceIdHash>
151 connected_devices_;
152
153 // Binding associated with |web_bluetooth_service_|.
154 mojo::AssociatedBinding<blink::mojom::WebBluetoothServiceClient> binding_;
155
156 DISALLOW_COPY_AND_ASSIGN(WebBluetoothImpl);
157 };
158
159 } // namespace content
160
161 #endif // CONTENT_RENDERER_BLUETOOTH_WEB_BLUETOOTH_IMPL_H_
OLDNEW
« no previous file with comments | « content/renderer/bluetooth/bluetooth_type_converters.cc ('k') | content/renderer/bluetooth/web_bluetooth_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698