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

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

Issue 1082273006: bluetooth: Impl uses new WebBluetoothGATTRemoteServer content/browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 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 16
16 using blink::WebBluetoothDevice; 17 using blink::WebBluetoothDevice;
17 using blink::WebBluetoothError; 18 using blink::WebBluetoothError;
18 using blink::WebBluetoothRequestDeviceCallbacks; 19 using blink::WebBluetoothRequestDeviceCallbacks;
20 using blink::WebBluetoothGATTRemoteServer;
scheib 2015/04/19 04:44:19 sort these lines. (surprised a script didn't menti
ortuno 2015/04/20 20:09:33 Done.
21 using blink::WebBluetoothConnectGATTCallbacks;
19 using blink::WebString; 22 using blink::WebString;
20 using blink::WebVector; 23 using blink::WebVector;
21 24
22 namespace content { 25 namespace content {
23 26
24 namespace { 27 namespace {
25 28
26 base::LazyInstance<base::ThreadLocalPointer<BluetoothDispatcher>>::Leaky 29 base::LazyInstance<base::ThreadLocalPointer<BluetoothDispatcher>>::Leaky
27 g_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; 30 g_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
28 31
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 bool BluetoothDispatcher::Send(IPC::Message* msg) { 91 bool BluetoothDispatcher::Send(IPC::Message* msg) {
89 return thread_safe_sender_->Send(msg); 92 return thread_safe_sender_->Send(msg);
90 } 93 }
91 94
92 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) { 95 void BluetoothDispatcher::OnMessageReceived(const IPC::Message& msg) {
93 bool handled = true; 96 bool handled = true;
94 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg) 97 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcher, msg)
95 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess, 98 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceSuccess,
96 OnRequestDeviceSuccess); 99 OnRequestDeviceSuccess);
97 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError); 100 IPC_MESSAGE_HANDLER(BluetoothMsg_RequestDeviceError, OnRequestDeviceError);
101 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess);
98 IPC_MESSAGE_UNHANDLED(handled = false) 102 IPC_MESSAGE_UNHANDLED(handled = false)
99 IPC_END_MESSAGE_MAP() 103 IPC_END_MESSAGE_MAP()
100 DCHECK(handled) << "Unhandled message:" << msg.type(); 104 DCHECK(handled) << "Unhandled message:" << msg.type();
101 } 105 }
102 106
103 void BluetoothDispatcher::requestDevice( 107 void BluetoothDispatcher::requestDevice(
104 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { 108 blink::WebBluetoothRequestDeviceCallbacks* callbacks) {
105 int request_id = pending_requests_.Add(callbacks); 109 int request_id = pending_requests_.Add(callbacks);
106 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); 110 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id));
107 } 111 }
108 112
113 void BluetoothDispatcher::connectGATT(std::string instance_id,
114 blink::WebBluetoothConnectGATTCallbacks* callbacks) {
115 int request_id = pending_connect_requests_.Add(callbacks);
116 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id,
117 instance_id));
118 }
119
109 void BluetoothDispatcher::SetBluetoothMockDataSetForTesting( 120 void BluetoothDispatcher::SetBluetoothMockDataSetForTesting(
110 const std::string& name) { 121 const std::string& name) {
111 Send(new BluetoothHostMsg_SetBluetoothMockDataSetForTesting(name)); 122 Send(new BluetoothHostMsg_SetBluetoothMockDataSetForTesting(name));
112 } 123 }
113 124
114 void BluetoothDispatcher::OnWorkerRunLoopStopped() { 125 void BluetoothDispatcher::OnWorkerRunLoopStopped() {
115 delete this; 126 delete this;
116 } 127 }
117 128
118 void BluetoothDispatcher::OnRequestDeviceSuccess( 129 void BluetoothDispatcher::OnRequestDeviceSuccess(
119 int thread_id, 130 int thread_id,
120 int request_id, 131 int request_id,
121 const BluetoothDevice& device) { 132 const BluetoothDevice& device) {
122 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 133 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
123 134
124 WebVector<WebString> uuids(device.uuids.size()); 135 WebVector<WebString> uuids(device.uuids.size());
125 for (size_t i = 0; i < device.uuids.size(); ++i) 136 for (size_t i = 0; i < device.uuids.size(); ++i)
126 uuids[i] = WebString::fromUTF8(device.uuids[i].c_str()); 137 uuids[i] = WebString::fromUTF8(device.uuids[i].c_str());
127 138
128 pending_requests_.Lookup(request_id) 139 pending_requests_.Lookup(request_id)
129 ->onSuccess(new WebBluetoothDevice( 140 ->onSuccess(new WebBluetoothDevice(
130 WebString::fromUTF8(device.instance_id), WebString(device.name), 141 WebString::fromUTF8(device.instance_id), WebString(device.name),
131 device.device_class, GetWebVendorIdSource(device.vendor_id_source), 142 device.device_class, GetWebVendorIdSource(device.vendor_id_source),
132 device.vendor_id, device.product_id, device.product_version, 143 device.vendor_id, device.product_id, device.product_version,
133 device.paired, device.connected, uuids)); 144 device.paired, device.connected, uuids));
134 pending_requests_.Remove(request_id); 145 pending_requests_.Remove(request_id);
135 } 146 }
136 147
148 void BluetoothDispatcher::OnConnectGATTSuccess(int thread_id,
149 int request_id,
150 const std::string& instance_id) {
151 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
Tom Sepez 2015/04/20 15:54:00 This is in the renderer, so it OK to assume that t
scheib 2015/04/20 16:50:12 Right. If the browser is functioning correctly it
152 pending_connect_requests_.Lookup(request_id)
153 ->onSuccess(new WebBluetoothGATTRemoteServer(
154 WebString::fromUTF8(instance_id), true /* connected */));
155 pending_connect_requests_.Remove(request_id);
156 }
157
137 void BluetoothDispatcher::OnRequestDeviceError(int thread_id, 158 void BluetoothDispatcher::OnRequestDeviceError(int thread_id,
138 int request_id, 159 int request_id,
139 BluetoothError error_type) { 160 BluetoothError error_type) {
140 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 161 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
141 pending_requests_.Lookup(request_id) 162 pending_requests_.Lookup(request_id)
142 ->onError(new WebBluetoothError( 163 ->onError(new WebBluetoothError(
143 WebBluetoothErrorFromBluetoothError(error_type), "")); 164 WebBluetoothErrorFromBluetoothError(error_type), ""));
144 pending_requests_.Remove(request_id); 165 pending_requests_.Remove(request_id);
145 } 166 }
146 167
147 } // namespace content 168 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698