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

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

Issue 1865613002: bluetooth: Move read value to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-notifications
Patch Set: Address jyasskin's comments Created 4 years, 8 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 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" 5 #include "content/browser/bluetooth/web_bluetooth_service_impl.h"
6 6
7 #include "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "content/browser/bluetooth/bluetooth_blacklist.h" 8 #include "content/browser/bluetooth/bluetooth_blacklist.h"
9 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" 9 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
10 #include "content/browser/renderer_host/render_process_host_impl.h" 10 #include "content/browser/renderer_host/render_process_host_impl.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 characteristic_instance_id, mojo::Array<uint8_t>(std::move(value))); 128 characteristic_instance_id, mojo::Array<uint8_t>(std::move(value)));
129 } 129 }
130 } 130 }
131 131
132 void WebBluetoothServiceImpl::SetClient( 132 void WebBluetoothServiceImpl::SetClient(
133 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) { 133 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) {
134 DCHECK(!client_.get()); 134 DCHECK(!client_.get());
135 client_.Bind(std::move(client)); 135 client_.Bind(std::move(client));
136 } 136 }
137 137
138 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
139 const mojo::String& characteristic_instance_id,
140 const RemoteCharacteristicReadValueCallback& callback) {
141 DCHECK_CURRENTLY_ON(BrowserThread::UI);
142 RecordWebBluetoothFunctionCall(
143 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE);
144
145 const CacheQueryResult query_result =
146 GetBluetoothDispatcherHost()->QueryCacheForCharacteristic(
147 GetOrigin(), characteristic_instance_id);
148
149 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
150 return;
151 }
152
153 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
154 RecordCharacteristicReadValueOutcome(query_result.outcome);
155 callback.Run(query_result.GetWebError(), nullptr /* value */);
156 return;
157 }
158
159 if (BluetoothBlacklist::Get().IsExcludedFromReads(
160 query_result.characteristic->GetUUID())) {
161 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED);
162 callback.Run(blink::mojom::WebBluetoothError::BLACKLISTED_READ,
163 nullptr /* value */);
164 return;
165 }
166
167 query_result.characteristic->ReadRemoteCharacteristic(
168 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess,
169 weak_ptr_factory_.GetWeakPtr(), callback),
170 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed,
171 weak_ptr_factory_.GetWeakPtr(), callback));
172 }
173
138 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( 174 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue(
139 const mojo::String& characteristic_instance_id, 175 const mojo::String& characteristic_instance_id,
140 mojo::Array<uint8_t> value, 176 mojo::Array<uint8_t> value,
141 const RemoteCharacteristicWriteValueCallback& callback) { 177 const RemoteCharacteristicWriteValueCallback& callback) {
142 DCHECK_CURRENTLY_ON(BrowserThread::UI); 178 DCHECK_CURRENTLY_ON(BrowserThread::UI);
143 RecordWebBluetoothFunctionCall( 179 RecordWebBluetoothFunctionCall(
144 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); 180 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE);
145 181
146 // We perform the length check on the renderer side. So if we 182 // We perform the length check on the renderer side. So if we
147 // get a value with length > 512, we can assume it's a hostile 183 // get a value with length > 512, we can assume it's a hostile
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // If the frame hasn't subscribed to notifications before we just 287 // If the frame hasn't subscribed to notifications before we just
252 // run the callback. 288 // run the callback.
253 callback.Run(); 289 callback.Run();
254 return; 290 return;
255 } 291 }
256 notify_session_iter->second->Stop(base::Bind( 292 notify_session_iter->second->Stop(base::Bind(
257 &WebBluetoothServiceImpl::OnStopNotifySessionComplete, 293 &WebBluetoothServiceImpl::OnStopNotifySessionComplete,
258 weak_ptr_factory_.GetWeakPtr(), characteristic_instance_id, callback)); 294 weak_ptr_factory_.GetWeakPtr(), characteristic_instance_id, callback));
259 } 295 }
260 296
297 void WebBluetoothServiceImpl::OnReadValueSuccess(
298 const RemoteCharacteristicReadValueCallback& callback,
299 const std::vector<uint8_t>& value) {
300 DCHECK_CURRENTLY_ON(BrowserThread::UI);
301 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS);
302 callback.Run(blink::mojom::WebBluetoothError::SUCCESS,
303 mojo::Array<uint8_t>::From(value));
304 }
305
306 void WebBluetoothServiceImpl::OnReadValueFailed(
307 const RemoteCharacteristicReadValueCallback& callback,
308 device::BluetoothGattService::GattErrorCode error_code) {
309 DCHECK_CURRENTLY_ON(BrowserThread::UI);
310 callback.Run(TranslateGATTErrorAndRecord(
311 error_code, UMAGATTOperation::CHARACTERISTIC_READ),
312 nullptr /* value */);
313 }
314
261 void WebBluetoothServiceImpl::OnWriteValueSuccess( 315 void WebBluetoothServiceImpl::OnWriteValueSuccess(
262 const RemoteCharacteristicWriteValueCallback& callback) { 316 const RemoteCharacteristicWriteValueCallback& callback) {
263 DCHECK_CURRENTLY_ON(BrowserThread::UI); 317 DCHECK_CURRENTLY_ON(BrowserThread::UI);
264 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); 318 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS);
265 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); 319 callback.Run(blink::mojom::WebBluetoothError::SUCCESS);
266 } 320 }
267 321
268 void WebBluetoothServiceImpl::OnWriteValueFailed( 322 void WebBluetoothServiceImpl::OnWriteValueFailed(
269 const RemoteCharacteristicWriteValueCallback& callback, 323 const RemoteCharacteristicWriteValueCallback& callback,
270 device::BluetoothGattService::GattErrorCode error_code) { 324 device::BluetoothGattService::GattErrorCode error_code) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 bad_message::BadMessageReason reason) { 370 bad_message::BadMessageReason reason) {
317 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); 371 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason);
318 binding_.Close(); 372 binding_.Close();
319 } 373 }
320 374
321 url::Origin WebBluetoothServiceImpl::GetOrigin() { 375 url::Origin WebBluetoothServiceImpl::GetOrigin() {
322 return render_frame_host_->GetLastCommittedOrigin(); 376 return render_frame_host_->GetLastCommittedOrigin();
323 } 377 }
324 378
325 } // namespace content 379 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/web_bluetooth_service_impl.h ('k') | content/common/bluetooth/bluetooth_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698