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

Side by Side Diff: content/child/bluetooth/bluetooth_dispatcher.cc

Issue 1159523002: bluetooth: Browser side partial implementation of getPrimaryService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address scheib's comments Created 5 years, 6 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/child/bluetooth/bluetooth_dispatcher.h" 5 #include "content/child/bluetooth/bluetooth_dispatcher.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "content/child/thread_safe_sender.h" 11 #include "content/child/thread_safe_sender.h"
12 #include "content/common/bluetooth/bluetooth_messages.h" 12 #include "content/common/bluetooth/bluetooth_messages.h"
13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h" 13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h"
14 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h" 14 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h"
15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h" 15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h"
16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h"
16 17
17 using blink::WebBluetoothConnectGATTCallbacks; 18 using blink::WebBluetoothConnectGATTCallbacks;
18 using blink::WebBluetoothDevice; 19 using blink::WebBluetoothDevice;
19 using blink::WebBluetoothError; 20 using blink::WebBluetoothError;
20 using blink::WebBluetoothGATTRemoteServer; 21 using blink::WebBluetoothGATTRemoteServer;
22 using blink::WebBluetoothGATTService;
21 using blink::WebBluetoothRequestDeviceCallbacks; 23 using blink::WebBluetoothRequestDeviceCallbacks;
22 using blink::WebString; 24 using blink::WebString;
23 using blink::WebVector; 25 using blink::WebVector;
24 26
27 namespace {
28
29 struct BluetoothPrimaryServiceRequest {
30 BluetoothPrimaryServiceRequest(
31 blink::WebString device_instance_id,
32 blink::WebString service_uuid,
33 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks)
34 : device_instance_id(device_instance_id),
35 service_uuid(service_uuid),
36 callbacks(callbacks) {}
37 ~BluetoothPrimaryServiceRequest() {}
38
39 blink::WebString device_instance_id;
40 blink::WebString service_uuid;
41 scoped_ptr<blink::WebBluetoothGetPrimaryServiceCallbacks> callbacks;
42 };
43 }
scheib 2015/06/01 19:35:56 Blank line. And "Terminate namespaces with comment
ortuno 2015/06/01 19:47:09 Done.
44
25 namespace content { 45 namespace content {
26 46
27 namespace { 47 namespace {
28 48
29 base::LazyInstance<base::ThreadLocalPointer<BluetoothDispatcher>>::Leaky 49 base::LazyInstance<base::ThreadLocalPointer<BluetoothDispatcher>>::Leaky
30 g_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; 50 g_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
31 51
32 BluetoothDispatcher* const kHasBeenDeleted = 52 BluetoothDispatcher* const kHasBeenDeleted =
33 reinterpret_cast<BluetoothDispatcher*>(0x1); 53 reinterpret_cast<BluetoothDispatcher*>(0x1);
34 54
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 115 }
96 116
97 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { 117 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
98 bool handled = true; 118 bool handled = true;
99 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg) 119 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg)
100 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess, 120 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess,
101 OnRequestDeviceSuccess); 121 OnRequestDeviceSuccess);
102 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError); 122 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError);
103 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess); 123 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess);
104 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError); 124 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError);
125 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess,
126 OnGetPrimaryServiceSuccess);
127 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError,
128 OnGetPrimaryServiceError);
105 IPC_MESSAGE_UNHANDLED(handled = false) 129 IPC_MESSAGE_UNHANDLED(handled = false)
106 IPC_END_MESSAGE_MAP() 130 IPC_END_MESSAGE_MAP()
107 DCHECK(handled) << "Unhandled message:" << msg.type(); 131 DCHECK(handled) << "Unhandled message:" << msg.type();
108 } 132 }
109 133
110 void BluetoothDispatcher::requestDevice( 134 void BluetoothDispatcher::requestDevice(
111 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { 135 blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
112 int request_id = pending_requests_.Add(callbacks); 136 int request_id = pending_requests_.Add(callbacks);
113 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); 137 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id));
114 } 138 }
115 139
116 void BluetoothDispatcher::connectGATT( 140 void BluetoothDispatcher::connectGATT(
117 const blink::WebString& device_instance_id, 141 const blink::WebString& device_instance_id,
118 blink::WebBluetoothConnectGATTCallbacks* callbacks) { 142 blink::WebBluetoothConnectGATTCallbacks* callbacks) {
119 int request_id = pending_connect_requests_.Add(callbacks); 143 int request_id = pending_connect_requests_.Add(callbacks);
120 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id, 144 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id,
121 device_instance_id.utf8())); 145 device_instance_id.utf8()));
122 } 146 }
123 147
148 void BluetoothDispatcher::getPrimaryService(
149 const blink::WebString& device_instance_id,
150 const blink::WebString& service_uuid,
151 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) {
152 int request_id =
153 pending_primary_service_requests_.Add(new BluetoothPrimaryServiceRequest(
154 device_instance_id, service_uuid, callbacks));
155 Send(new BluetoothHostMsg_GetPrimaryService(CurrentWorkerId(), request_id,
156 device_instance_id.utf8(),
157 service_uuid.utf8()));
158 }
159
124 void BluetoothDispatcher::OnWorkerRunLoopStopped() { 160 void BluetoothDispatcher::OnWorkerRunLoopStopped() {
125 delete this; 161 delete this;
126 } 162 }
127 163
128 void BluetoothDispatcher::OnRequestDeviceSuccess( 164 void BluetoothDispatcher::OnRequestDeviceSuccess(
129 int thread_id, 165 int thread_id,
130 int request_id, 166 int request_id,
131 const BluetoothDevice& device) { 167 const BluetoothDevice& device) {
132 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 168 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
133 169
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 BluetoothError error_type) { 208 BluetoothError error_type) {
173 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; 209 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
174 pending_connect_requests_.Lookup(request_id) 210 pending_connect_requests_.Lookup(request_id)
175 ->onError(new WebBluetoothError( 211 ->onError(new WebBluetoothError(
176 // TODO(ortuno): Return more descriptive error messages. 212 // TODO(ortuno): Return more descriptive error messages.
177 // http://crbug.com/490419 213 // http://crbug.com/490419
178 WebBluetoothErrorFromBluetoothError(error_type), "")); 214 WebBluetoothErrorFromBluetoothError(error_type), ""));
179 pending_connect_requests_.Remove(request_id); 215 pending_connect_requests_.Remove(request_id);
180 } 216 }
181 217
218 void BluetoothDispatcher::OnGetPrimaryServiceSuccess(
219 int thread_id,
220 int request_id,
221 const std::string& service_instance_id) {
222 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id;
223 BluetoothPrimaryServiceRequest* request =
224 pending_primary_service_requests_.Lookup(request_id);
225 request->callbacks->onSuccess(new WebBluetoothGATTService(
226 WebString::fromUTF8(service_instance_id), request->service_uuid,
227 true /* isPrimary */, request->device_instance_id));
228 pending_primary_service_requests_.Remove(request_id);
229 }
230
231 void BluetoothDispatcher::OnGetPrimaryServiceError(int thread_id,
232 int request_id,
233 BluetoothError error_type) {
234 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id;
235
236 // Since we couldn't find the service return null. See Step 3 of
237 // getPrimaryService algorithm:
238 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattremoteserv er-getprimaryservice
239 if (error_type == BluetoothError::NOT_FOUND) {
240 pending_primary_service_requests_.Lookup(request_id)
241 ->callbacks->onSuccess(nullptr);
242 pending_primary_service_requests_.Remove(request_id);
243 return;
244 }
245
246 pending_primary_service_requests_.Lookup(request_id)
247 ->callbacks->onError(new WebBluetoothError(
248 // TODO(ortuno): Return more descriptive error messages.
249 // http://crbug.com/490419
250 WebBluetoothErrorFromBluetoothError(error_type), ""));
251 pending_primary_service_requests_.Remove(request_id);
252 }
253
182 } // namespace content 254 } // namespace content
OLDNEW
« no previous file with comments | « content/child/bluetooth/bluetooth_dispatcher.h ('k') | content/child/bluetooth/web_bluetooth_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698