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

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

Issue 885723002: bluetooth: Provide more device attributes in requestDevice reply. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt-0
Patch Set: uuids initializer fixed. Created 5 years, 10 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
« no previous file with comments | « content/child/bluetooth/bluetooth_dispatcher.h ('k') | content/common/bluetooth/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/child/worker_thread_task_runner.h" 12 #include "content/child/worker_thread_task_runner.h"
13 #include "content/common/bluetooth/bluetooth_messages.h" 13 #include "content/common/bluetooth/bluetooth_messages.h"
14 #include "third_party/WebKit/public/platform/WebBluetoothDevice.h" 14 #include "third_party/WebKit/public/platform/WebBluetoothDevice.h"
15 #include "third_party/WebKit/public/platform/WebBluetoothError.h" 15 #include "third_party/WebKit/public/platform/WebBluetoothError.h"
16 16
17 using blink::WebBluetoothDevice; 17 using blink::WebBluetoothDevice;
18 using blink::WebBluetoothError; 18 using blink::WebBluetoothError;
19 using blink::WebBluetoothRequestDeviceCallbacks; 19 using blink::WebBluetoothRequestDeviceCallbacks;
20 using blink::WebString; 20 using blink::WebString;
21 using blink::WebVector;
21 22
22 namespace content { 23 namespace content {
23 24
24 namespace { 25 namespace {
25 26
26 base::LazyInstance<base::ThreadLocalPointer<BluetoothDispatcher>>::Leaky 27 base::LazyInstance<base::ThreadLocalPointer<BluetoothDispatcher>>::Leaky
27 g_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; 28 g_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
28 29
29 BluetoothDispatcher* const kHasBeenDeleted = 30 BluetoothDispatcher* const kHasBeenDeleted =
30 reinterpret_cast<BluetoothDispatcher*>(0x1); 31 reinterpret_cast<BluetoothDispatcher*>(0x1);
31 32
32 int CurrentWorkerId() { 33 int CurrentWorkerId() {
33 return WorkerTaskRunner::Instance()->CurrentWorkerId(); 34 return WorkerTaskRunner::Instance()->CurrentWorkerId();
34 } 35 }
35 36
36 WebBluetoothError::ErrorType WebBluetoothErrorFromBluetoothError( 37 WebBluetoothError::ErrorType WebBluetoothErrorFromBluetoothError(
37 BluetoothError error_type) { 38 BluetoothError error_type) {
38 switch (error_type) { 39 switch (error_type) {
39 case BluetoothError::NOT_FOUND: 40 case BluetoothError::NOT_FOUND:
40 return WebBluetoothError::NotFoundError; 41 return WebBluetoothError::NotFoundError;
41 case BluetoothError::SECURITY: 42 case BluetoothError::SECURITY:
42 return WebBluetoothError::SecurityError; 43 return WebBluetoothError::SecurityError;
43 } 44 }
44 NOTIMPLEMENTED(); 45 NOTIMPLEMENTED();
45 return WebBluetoothError::NotFoundError; 46 return WebBluetoothError::NotFoundError;
46 } 47 }
47 48
49 WebBluetoothDevice::VendorIDSource GetWebVendorIdSource(
50 device::BluetoothDevice::VendorIDSource vendor_id_source) {
51 switch (vendor_id_source) {
52 case device::BluetoothDevice::VENDOR_ID_UNKNOWN:
53 return WebBluetoothDevice::VendorIDSource::Unknown;
54 case device::BluetoothDevice::VENDOR_ID_BLUETOOTH:
55 return WebBluetoothDevice::VendorIDSource::Bluetooth;
56 case device::BluetoothDevice::VENDOR_ID_USB:
57 return WebBluetoothDevice::VendorIDSource::USB;
58 }
59 NOTREACHED();
60 return WebBluetoothDevice::VendorIDSource::Unknown;
61 }
62
48 } // namespace 63 } // namespace
49 64
50 BluetoothDispatcher::BluetoothDispatcher(ThreadSafeSender* sender) 65 BluetoothDispatcher::BluetoothDispatcher(ThreadSafeSender* sender)
51 : thread_safe_sender_(sender) { 66 : thread_safe_sender_(sender) {
52 g_dispatcher_tls.Pointer()->Set(this); 67 g_dispatcher_tls.Pointer()->Set(this);
53 } 68 }
54 69
55 BluetoothDispatcher::~BluetoothDispatcher() { 70 BluetoothDispatcher::~BluetoothDispatcher() {
56 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); 71 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
57 } 72 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 Send(new BluetoothHostMsg_SetBluetoothMockDataSetForTesting(name)); 112 Send(new BluetoothHostMsg_SetBluetoothMockDataSetForTesting(name));
98 } 113 }
99 114
100 void BluetoothDispatcher::OnWorkerRunLoopStopped() { 115 void BluetoothDispatcher::OnWorkerRunLoopStopped() {
101 delete this; 116 delete this;
102 } 117 }
103 118
104 void BluetoothDispatcher::OnRequestDeviceSuccess( 119 void BluetoothDispatcher::OnRequestDeviceSuccess(
105 int thread_id, 120 int thread_id,
106 int request_id, 121 int request_id,
107 const std::string& device_instance_id) { 122 const BluetoothDevice& device) {
108 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 123 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
124
125 WebVector<WebString> uuids(device.uuids.size());
126 for (size_t i = 0; i < device.uuids.size(); ++i)
127 uuids[i] = WebString::fromUTF8(device.uuids[i].c_str());
128
109 pending_requests_.Lookup(request_id) 129 pending_requests_.Lookup(request_id)
110 ->onSuccess( 130 ->onSuccess(new WebBluetoothDevice(
111 new WebBluetoothDevice(WebString::fromUTF8(device_instance_id))); 131 WebString::fromUTF8(device.instance_id), WebString(device.name),
132 device.device_class, GetWebVendorIdSource(device.vendor_id_source),
133 device.vendor_id, device.product_id, device.product_version,
134 device.paired, device.connected, uuids));
112 pending_requests_.Remove(request_id); 135 pending_requests_.Remove(request_id);
113 } 136 }
114 137
115 void BluetoothDispatcher::OnRequestDeviceError(int thread_id, 138 void BluetoothDispatcher::OnRequestDeviceError(int thread_id,
116 int request_id, 139 int request_id,
117 BluetoothError error_type) { 140 BluetoothError error_type) {
118 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 141 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
119 pending_requests_.Lookup(request_id) 142 pending_requests_.Lookup(request_id)
120 ->onError(new WebBluetoothError( 143 ->onError(new WebBluetoothError(
121 WebBluetoothErrorFromBluetoothError(error_type), "")); 144 WebBluetoothErrorFromBluetoothError(error_type), ""));
122 pending_requests_.Remove(request_id); 145 pending_requests_.Remove(request_id);
123 } 146 }
124 147
125 } // namespace content 148 } // namespace content
OLDNEW
« no previous file with comments | « content/child/bluetooth/bluetooth_dispatcher.h ('k') | content/common/bluetooth/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698