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

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

Issue 1228113004: Put the RenderFrame's ID into a per-frame WebBluetooth, and plumb that back to the browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@store-request-device-state-in-dispatcher
Patch Set: Remove mention of frames from content/child. Created 5 years, 5 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 // NETWORK_ERROR Note: 5 // NETWORK_ERROR Note:
6 // When a device can't be found in the BluetoothAdapter, that generally 6 // When a device can't be found in the BluetoothAdapter, that generally
7 // indicates that it's gone out of range. We reject with a NetworkError in that 7 // indicates that it's gone out of range. We reject with a NetworkError in that
8 // case. 8 // case.
9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt 9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt
10 10
11 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" 11 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
12 12
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "content/browser/bad_message.h" 15 #include "content/browser/bad_message.h"
16 #include "content/browser/frame_host/render_frame_host_impl.h"
16 #include "content/common/bluetooth/bluetooth_messages.h" 17 #include "content/common/bluetooth/bluetooth_messages.h"
17 #include "device/bluetooth/bluetooth_adapter.h" 18 #include "device/bluetooth/bluetooth_adapter.h"
18 #include "device/bluetooth/bluetooth_adapter_factory.h" 19 #include "device/bluetooth/bluetooth_adapter_factory.h"
19 #include "device/bluetooth/bluetooth_device.h" 20 #include "device/bluetooth/bluetooth_device.h"
20 #include "device/bluetooth/bluetooth_discovery_session.h" 21 #include "device/bluetooth/bluetooth_discovery_session.h"
21 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 22 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
22 #include "device/bluetooth/bluetooth_gatt_service.h" 23 #include "device/bluetooth/bluetooth_gatt_service.h"
23 24
24 using blink::WebBluetoothError; 25 using blink::WebBluetoothError;
25 using device::BluetoothAdapter; 26 using device::BluetoothAdapter;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return blink::WebBluetoothError::GATTNotSupported; 129 return blink::WebBluetoothError::GATTNotSupported;
129 } 130 }
130 NOTREACHED(); 131 NOTREACHED();
131 return blink::WebBluetoothError::GATTUntranslatedErrorCode; 132 return blink::WebBluetoothError::GATTUntranslatedErrorCode;
132 } 133 }
133 134
134 } // namespace 135 } // namespace
135 136
136 namespace content { 137 namespace content {
137 138
138 BluetoothDispatcherHost::BluetoothDispatcherHost() 139 BluetoothDispatcherHost::BluetoothDispatcherHost(int render_process_id)
139 : BrowserMessageFilter(BluetoothMsgStart), 140 : BrowserMessageFilter(BluetoothMsgStart),
141 render_process_id_(render_process_id),
140 weak_ptr_factory_(this) { 142 weak_ptr_factory_(this) {
141 DCHECK_CURRENTLY_ON(BrowserThread::UI); 143 DCHECK_CURRENTLY_ON(BrowserThread::UI);
142 current_delay_time_ = kDelayTime; 144 current_delay_time_ = kDelayTime;
143 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) 145 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable())
144 BluetoothAdapterFactory::GetAdapter( 146 BluetoothAdapterFactory::GetAdapter(
145 base::Bind(&BluetoothDispatcherHost::set_adapter, 147 base::Bind(&BluetoothDispatcherHost::set_adapter,
146 weak_ptr_factory_.GetWeakPtr())); 148 weak_ptr_factory_.GetWeakPtr()));
147 } 149 }
148 150
149 void BluetoothDispatcherHost::OnDestruct() const { 151 void BluetoothDispatcherHost::OnDestruct() const {
(...skipping 30 matching lines...) Expand all
180 set_adapter(mock_adapter.Pass()); 182 set_adapter(mock_adapter.Pass());
181 } 183 }
182 184
183 BluetoothDispatcherHost::~BluetoothDispatcherHost() { 185 BluetoothDispatcherHost::~BluetoothDispatcherHost() {
184 DCHECK_CURRENTLY_ON(BrowserThread::UI); 186 DCHECK_CURRENTLY_ON(BrowserThread::UI);
185 // Clear adapter, releasing observer references. 187 // Clear adapter, releasing observer references.
186 set_adapter(scoped_refptr<device::BluetoothAdapter>()); 188 set_adapter(scoped_refptr<device::BluetoothAdapter>());
187 } 189 }
188 190
189 struct BluetoothDispatcherHost::RequestDeviceSession { 191 struct BluetoothDispatcherHost::RequestDeviceSession {
190 RequestDeviceSession(const std::vector<BluetoothScanFilter>& filters, 192 RequestDeviceSession(int frame_routing_id,
ortuno 2015/07/15 23:00:46 This is called frame_routing_id but you call it ro
Jeffrey Yasskin 2015/07/17 01:32:44 Yep, this is undone now that it's no longer coming
193 const std::vector<BluetoothScanFilter>& filters,
191 const std::vector<BluetoothUUID>& optional_services) 194 const std::vector<BluetoothUUID>& optional_services)
192 : filters(filters), optional_services(optional_services) {} 195 : frame_routing_id(frame_routing_id),
196 filters(filters),
197 optional_services(optional_services) {}
193 198
199 int frame_routing_id;
scheib 2015/07/16 01:11:46 Perhaps add it when we need it? Or if you have a f
Jeffrey Yasskin 2015/07/17 01:32:44 I've undone this storage. We'll see how it needs t
194 std::vector<BluetoothScanFilter> filters; 200 std::vector<BluetoothScanFilter> filters;
195 std::vector<BluetoothUUID> optional_services; 201 std::vector<BluetoothUUID> optional_services;
196 }; 202 };
197 203
198 void BluetoothDispatcherHost::set_adapter( 204 void BluetoothDispatcherHost::set_adapter(
199 scoped_refptr<device::BluetoothAdapter> adapter) { 205 scoped_refptr<device::BluetoothAdapter> adapter) {
200 DCHECK_CURRENTLY_ON(BrowserThread::UI); 206 DCHECK_CURRENTLY_ON(BrowserThread::UI);
201 if (adapter_.get()) 207 if (adapter_.get())
202 adapter_->RemoveObserver(this); 208 adapter_->RemoveObserver(this);
203 adapter_ = adapter; 209 adapter_ = adapter;
(...skipping 12 matching lines...) Expand all
216 device::BluetoothDiscoveryFilter::TRANSPORT_DUAL)); 222 device::BluetoothDiscoveryFilter::TRANSPORT_DUAL));
217 for (const BluetoothUUID& service : services) { 223 for (const BluetoothUUID& service : services) {
218 discovery_filter->AddUUID(service); 224 discovery_filter->AddUUID(service);
219 } 225 }
220 return discovery_filter.Pass(); 226 return discovery_filter.Pass();
221 } 227 }
222 228
223 void BluetoothDispatcherHost::OnRequestDevice( 229 void BluetoothDispatcherHost::OnRequestDevice(
224 int thread_id, 230 int thread_id,
225 int request_id, 231 int request_id,
232 int routing_id,
226 const std::vector<BluetoothScanFilter>& filters, 233 const std::vector<BluetoothScanFilter>& filters,
227 const std::vector<BluetoothUUID>& optional_services) { 234 const std::vector<BluetoothUUID>& optional_services) {
228 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 235 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
236
237 RenderFrameHostImpl* render_frame_host =
238 RenderFrameHostImpl::FromID(render_process_id_, routing_id);
239
240 if (!render_frame_host) {
241 DLOG(WARNING)
ortuno 2015/07/15 23:00:46 Should we add a histogram for this?
Jeffrey Yasskin 2015/07/17 01:32:44 Will do, but not today. I'll ping Monday when it's
Jeffrey Yasskin 2015/07/21 00:47:05 Done in https://codereview.chromium.org/1248573002
242 << "Got a requestDevice IPC without a matching RenderFrameHost: "
243 << render_process_id_ << ", " << routing_id;
244 Send(new BluetoothMsg_RequestDeviceError(
245 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame));
246 }
247
229 // TODO(scheib): Device selection UI: crbug.com/436280 248 // TODO(scheib): Device selection UI: crbug.com/436280
230 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed. 249 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed.
231 if (adapter_.get()) { 250 if (adapter_.get()) {
232 if (!request_device_sessions_ 251 if (!request_device_sessions_
233 .insert(std::make_pair( 252 .insert(std::make_pair(
234 std::make_pair(thread_id, request_id), 253 std::make_pair(thread_id, request_id),
235 RequestDeviceSession(filters, optional_services))) 254 RequestDeviceSession(routing_id, filters, optional_services)))
236 .second) { 255 .second) {
237 LOG(ERROR) << "2 requestDevice() calls with the same thread_id (" 256 LOG(ERROR) << "2 requestDevice() calls with the same thread_id ("
238 << thread_id << ") and request_id (" << request_id 257 << thread_id << ") and request_id (" << request_id
239 << ") shouldn't arrive at the same BluetoothDispatcherHost."; 258 << ") shouldn't arrive at the same BluetoothDispatcherHost.";
240 bad_message::ReceivedBadMessage( 259 bad_message::ReceivedBadMessage(
241 this, bad_message::BDH_DUPLICATE_REQUEST_DEVICE_ID); 260 this, bad_message::BDH_DUPLICATE_REQUEST_DEVICE_ID);
242 } 261 }
243 adapter_->StartDiscoverySessionWithFilter( 262 adapter_->StartDiscoverySessionWithFilter(
244 ComputeScanFilter(filters), 263 ComputeScanFilter(filters),
245 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, 264 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted,
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 651
633 void BluetoothDispatcherHost::OnWriteValueFailed( 652 void BluetoothDispatcherHost::OnWriteValueFailed(
634 int thread_id, 653 int thread_id,
635 int request_id, 654 int request_id,
636 device::BluetoothGattService::GattErrorCode error_code) { 655 device::BluetoothGattService::GattErrorCode error_code) {
637 Send(new BluetoothMsg_WriteCharacteristicValueError( 656 Send(new BluetoothMsg_WriteCharacteristicValueError(
638 thread_id, request_id, TranslateGATTError(error_code))); 657 thread_id, request_id, TranslateGATTError(error_code)));
639 } 658 }
640 659
641 } // namespace content 660 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698