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

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

Issue 1120373004: bluetooth: Browser-side implementation of connectGATT. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-request-device-implementation
Patch Set: Address jyasskin's comments Created 5 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 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"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return thread_safe_sender_->Send(msg); 94 return thread_safe_sender_->Send(msg);
95 } 95 }
96 96
97 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { 97 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
98 bool handled = true; 98 bool handled = true;
99 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg) 99 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg)
100 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess, 100 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess,
101 OnRequestDeviceSuccess); 101 OnRequestDeviceSuccess);
102 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError); 102 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError);
103 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess); 103 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess);
104 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError);
104 IPC_MESSAGE_UNHANDLED(handled = false) 105 IPC_MESSAGE_UNHANDLED(handled = false)
105 IPC_END_MESSAGE_MAP() 106 IPC_END_MESSAGE_MAP()
106 DCHECK(handled) << "Unhandled message:" << msg.type(); 107 DCHECK(handled) << "Unhandled message:" << msg.type();
107 } 108 }
108 109
109 void BluetoothDispatcher::requestDevice( 110 void BluetoothDispatcher::requestDevice(
110 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { 111 blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
111 int request_id = pending_requests_.Add(callbacks); 112 int request_id = pending_requests_.Add(callbacks);
112 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); 113 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id));
113 } 114 }
(...skipping 22 matching lines...) Expand all
136 137
137 pending_requests_.Lookup(request_id) 138 pending_requests_.Lookup(request_id)
138 ->onSuccess(new WebBluetoothDevice( 139 ->onSuccess(new WebBluetoothDevice(
139 WebString::fromUTF8(device.instance_id), WebString(device.name), 140 WebString::fromUTF8(device.instance_id), WebString(device.name),
140 device.device_class, GetWebVendorIdSource(device.vendor_id_source), 141 device.device_class, GetWebVendorIdSource(device.vendor_id_source),
141 device.vendor_id, device.product_id, device.product_version, 142 device.vendor_id, device.product_id, device.product_version,
142 device.paired, uuids)); 143 device.paired, uuids));
143 pending_requests_.Remove(request_id); 144 pending_requests_.Remove(request_id);
144 } 145 }
145 146
147 void BluetoothDispatcher::OnRequestDeviceError(int thread_id,
148 int request_id,
149 BluetoothError error_type) {
150 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
151 pending_requests_.Lookup(request_id)
152 ->onError(new WebBluetoothError(
153 // TODO(ortuno): Return more descriptive error messages.
154 // http://crbug.com/490419
155 WebBluetoothErrorFromBluetoothError(error_type), ""));
156 pending_requests_.Remove(request_id);
157 }
158
146 void BluetoothDispatcher::OnConnectGATTSuccess( 159 void BluetoothDispatcher::OnConnectGATTSuccess(
147 int thread_id, 160 int thread_id,
148 int request_id, 161 int request_id,
149 const std::string& device_instance_id) { 162 const std::string& device_instance_id) {
150 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; 163 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
151 pending_connect_requests_.Lookup(request_id) 164 pending_connect_requests_.Lookup(request_id)
152 ->onSuccess(new WebBluetoothGATTRemoteServer( 165 ->onSuccess(new WebBluetoothGATTRemoteServer(
153 WebString::fromUTF8(device_instance_id), true /* connected */)); 166 WebString::fromUTF8(device_instance_id), true /* connected */));
154 pending_connect_requests_.Remove(request_id); 167 pending_connect_requests_.Remove(request_id);
155 } 168 }
156 169
157 void BluetoothDispatcher::OnRequestDeviceError(int thread_id, 170 void BluetoothDispatcher::OnConnectGATTError(int thread_id,
158 int request_id, 171 int request_id,
159 BluetoothError error_type) { 172 BluetoothError error_type) {
160 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 173 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
161 pending_requests_.Lookup(request_id) 174 pending_connect_requests_.Lookup(request_id)
162 ->onError(new WebBluetoothError( 175 ->onError(new WebBluetoothError(
176 // TODO(ortuno): Return more descriptive error messages.
177 // http://crbug.com/490419
163 WebBluetoothErrorFromBluetoothError(error_type), "")); 178 WebBluetoothErrorFromBluetoothError(error_type), ""));
164 pending_requests_.Remove(request_id); 179 pending_connect_requests_.Remove(request_id);
165 } 180 }
166 181
167 } // namespace content 182 } // namespace content
OLDNEW
« no previous file with comments | « content/child/bluetooth/bluetooth_dispatcher.h ('k') | content/common/bluetooth/bluetooth_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698