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

Side by Side Diff: content/browser/bluetooth/web_bluetooth_service_impl.h

Issue 1861013005: bluetooth: Move GetCharacteristic(s) over to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-read-value
Patch Set: Address jyasskin's 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ 5 #ifndef CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ 6 #define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "content/browser/bad_message.h" 13 #include "content/browser/bad_message.h"
14 #include "content/browser/bluetooth/cache_query_result.h"
14 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
15 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
16 #include "device/bluetooth/bluetooth_adapter.h" 17 #include "device/bluetooth/bluetooth_adapter.h"
17 #include "device/bluetooth/bluetooth_gatt_notify_session.h" 18 #include "device/bluetooth/bluetooth_gatt_notify_session.h"
18 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 19 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
19 #include "device/bluetooth/bluetooth_remote_gatt_service.h" 20 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
20 #include "mojo/public/cpp/bindings/binding.h" 21 #include "mojo/public/cpp/bindings/binding.h"
21 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h" 22 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h"
22 23
23 namespace url { 24 namespace url {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // Notifies the WebBluetoothServiceClient that characteristic 71 // Notifies the WebBluetoothServiceClient that characteristic
71 // |characteristic_instance_id| changed it's value. We only do this for 72 // |characteristic_instance_id| changed it's value. We only do this for
72 // characteristics that have been returned to the client in the past. 73 // characteristics that have been returned to the client in the past.
73 void NotifyCharacteristicValueChanged( 74 void NotifyCharacteristicValueChanged(
74 const std::string& characteristic_instance_id, 75 const std::string& characteristic_instance_id,
75 std::vector<uint8_t> value); 76 std::vector<uint8_t> value);
76 77
77 // WebBluetoothService methods: 78 // WebBluetoothService methods:
78 void SetClient( 79 void SetClient(
79 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) override; 80 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) override;
80 81 void RemoteServiceGetCharacteristics(
81 // WebBluetoothService methods: 82 const mojo::String& service_instance_id,
83 blink::mojom::WebBluetoothGATTQueryQuantity quantity,
84 const mojo::String& characteristics_uuid,
85 const RemoteServiceGetCharacteristicsCallback& callback) override;
82 void RemoteCharacteristicReadValue( 86 void RemoteCharacteristicReadValue(
83 const mojo::String& characteristic_instance_id, 87 const mojo::String& characteristic_instance_id,
84 const RemoteCharacteristicReadValueCallback& callback) override; 88 const RemoteCharacteristicReadValueCallback& callback) override;
85 void RemoteCharacteristicWriteValue( 89 void RemoteCharacteristicWriteValue(
86 const mojo::String& characteristic_instance_id, 90 const mojo::String& characteristic_instance_id,
87 mojo::Array<uint8_t> value, 91 mojo::Array<uint8_t> value,
88 const RemoteCharacteristicWriteValueCallback& callback) override; 92 const RemoteCharacteristicWriteValueCallback& callback) override;
89 void RemoteCharacteristicStartNotifications( 93 void RemoteCharacteristicStartNotifications(
90 const mojo::String& characteristic_instance_id, 94 const mojo::String& characteristic_instance_id,
91 const RemoteCharacteristicStartNotificationsCallback& callback) override; 95 const RemoteCharacteristicStartNotificationsCallback& callback) override;
(...skipping 21 matching lines...) Expand all
113 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); 117 std::unique_ptr<device::BluetoothGattNotifySession> notify_session);
114 void OnStartNotifySessionFailed( 118 void OnStartNotifySessionFailed(
115 const RemoteCharacteristicStartNotificationsCallback& callback, 119 const RemoteCharacteristicStartNotificationsCallback& callback,
116 device::BluetoothRemoteGattService::GattErrorCode error_code); 120 device::BluetoothRemoteGattService::GattErrorCode error_code);
117 121
118 // Callback for BluetoothGattNotifySession::Stop. 122 // Callback for BluetoothGattNotifySession::Stop.
119 void OnStopNotifySessionComplete( 123 void OnStopNotifySessionComplete(
120 const std::string& characteristic_instance_id, 124 const std::string& characteristic_instance_id,
121 const RemoteCharacteristicStopNotificationsCallback& callback); 125 const RemoteCharacteristicStopNotificationsCallback& callback);
122 126
127 // Functions to query the platform cache for the bluetooth object.
128 // result.outcome == CacheQueryOutcome::SUCCESS if the object was found in the
129 // cache. Otherwise result.outcome that can used to record the outcome and
130 // result.error will contain the error that should be send to the renderer.
palmer 2016/04/25 21:19:01 Typo: "...sent to..."
ortuno 2016/04/25 22:43:23 Done.
131 // One of the possible outcomes is BAD_RENDERER. In this case we crash the
132 // renderer, record the reason and close the pipe, so it's safe to drop
133 // any callbacks.
134
135 // Queries the platform cache for a characteristic with
136 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|,
137 // |service| and |characteristic| fields if successful.
138 CacheQueryResult QueryCacheForCharacteristic(
139 const std::string& characteristic_instance_id);
140
123 RenderProcessHost* GetRenderProcessHost(); 141 RenderProcessHost* GetRenderProcessHost();
124 BluetoothDispatcherHost* GetBluetoothDispatcherHost(); 142 BluetoothDispatcherHost* GetBluetoothDispatcherHost();
125 void CrashRendererAndClosePipe(bad_message::BadMessageReason reason); 143 void CrashRendererAndClosePipe(bad_message::BadMessageReason reason);
126 url::Origin GetOrigin(); 144 url::Origin GetOrigin();
127 145
128 // Clears all state (maps, sets, etc). 146 // Clears all state (maps, sets, etc).
129 void ClearState(); 147 void ClearState();
130 148
149 // Maps to get the object's parent based on it's instanceID.
palmer 2016/04/25 21:19:01 Typo: "its". Since this comment is introducing se
ortuno 2016/04/25 22:43:23 Done.
150 // Map of characteristic_instance_id to service_instance_id.
151 std::unordered_map<std::string, std::string> characteristic_to_service_;
palmer 2016/04/25 21:19:01 Not |characteristic_id_to_service_|, to match |cha
ortuno 2016/04/25 22:43:23 Changed to characteristic_id_to_service_id_.
152
131 // Map to keep track of the characteristics' notify sessions. 153 // Map to keep track of the characteristics' notify sessions.
132 std::unordered_map<std::string, 154 std::unordered_map<std::string,
133 std::unique_ptr<device::BluetoothGattNotifySession>> 155 std::unique_ptr<device::BluetoothGattNotifySession>>
134 characteristic_id_to_notify_session_; 156 characteristic_id_to_notify_session_;
135 157
136 // The RFH that owns this instance. 158 // The RFH that owns this instance.
137 RenderFrameHost* render_frame_host_; 159 RenderFrameHost* render_frame_host_;
138 160
139 // Proxy to the WebBluetoothServiceClient to send device events to. 161 // Proxy to the WebBluetoothServiceClient to send device events to.
140 blink::mojom::WebBluetoothServiceClientAssociatedPtr client_; 162 blink::mojom::WebBluetoothServiceClientAssociatedPtr client_;
141 163
142 // The lifetime of this instance is exclusively managed by the RFH that 164 // The lifetime of this instance is exclusively managed by the RFH that
143 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes 165 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes
144 // the service on pipe connection errors. 166 // the service on pipe connection errors.
145 mojo::Binding<blink::mojom::WebBluetoothService> binding_; 167 mojo::Binding<blink::mojom::WebBluetoothService> binding_;
146 168
147 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; 169 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_;
148 170
149 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); 171 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl);
150 }; 172 };
151 173
152 } // namespace content 174 } // namespace content
153 175
154 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ 176 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698