OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
6 | 6 |
7 #if defined(OS_CHROMEOS) | 7 #if defined(OS_CHROMEOS) |
8 #include <errno.h> | 8 #include <errno.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" | 13 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" |
14 #include "chrome/browser/extensions/event_names.h" | 14 #include "chrome/browser/extensions/event_names.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/extensions/api/experimental_bluetooth.h" | 17 #include "chrome/common/extensions/api/experimental_bluetooth.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 | 19 |
20 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
22 #include "base/safe_strerror_posix.h" | 22 #include "base/safe_strerror_posix.h" |
23 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 23 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
24 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" | 24 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" |
25 #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" | |
25 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" | 26 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" |
26 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" | 27 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" |
27 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" | 28 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" |
28 #include "chromeos/dbus/bluetooth_out_of_band_client.h" | 29 #include "chromeos/dbus/bluetooth_out_of_band_client.h" |
30 #include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" | |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 chromeos::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) { | 34 chromeos::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) { |
33 return profile->GetExtensionService()->bluetooth_event_router(); | 35 return profile->GetExtensionService()->bluetooth_event_router(); |
34 } | 36 } |
35 | 37 |
36 const chromeos::BluetoothAdapter& GetAdapter(Profile* profile) { | 38 const chromeos::BluetoothAdapter& GetAdapter(Profile* profile) { |
37 return GetEventRouter(profile)->adapter(); | 39 return GetEventRouter(profile)->adapter(); |
38 } | 40 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 void BluetoothGetDevicesFunction::DispatchDeviceSearchResult( | 105 void BluetoothGetDevicesFunction::DispatchDeviceSearchResult( |
104 const chromeos::BluetoothDevice& device) { | 106 const chromeos::BluetoothDevice& device) { |
105 experimental_bluetooth::Device extension_device; | 107 experimental_bluetooth::Device extension_device; |
106 experimental_bluetooth::BluetoothDeviceToApiDevice(device, &extension_device); | 108 experimental_bluetooth::BluetoothDeviceToApiDevice(device, &extension_device); |
107 GetEventRouter(profile())->DispatchDeviceEvent( | 109 GetEventRouter(profile())->DispatchDeviceEvent( |
108 extensions::event_names::kBluetoothOnDeviceSearchResult, | 110 extensions::event_names::kBluetoothOnDeviceSearchResult, |
109 extension_device); | 111 extension_device); |
110 } | 112 } |
111 | 113 |
112 void BluetoothGetDevicesFunction::ProvidesServiceCallback( | 114 void BluetoothGetDevicesFunction::ProvidesServiceCallback( |
113 const chromeos::BluetoothDevice* device, | 115 const chromeos::BluetoothDevice* device, bool providesService) { |
114 bool providesService) { | |
115 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 116 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
116 | 117 |
117 CHECK(device); | 118 CHECK(device); |
118 if (providesService) | 119 if (providesService) |
119 DispatchDeviceSearchResult(*device); | 120 DispatchDeviceSearchResult(*device); |
120 | 121 |
121 callbacks_pending_--; | 122 callbacks_pending_--; |
122 if (callbacks_pending_ == -1) | 123 if (callbacks_pending_ == -1) |
123 SendResponse(true); | 124 SendResponse(true); |
124 } | 125 } |
(...skipping 12 matching lines...) Expand all Loading... | |
137 SetError(kInvalidUuid); | 138 SetError(kInvalidUuid); |
138 return false; | 139 return false; |
139 } | 140 } |
140 } | 141 } |
141 | 142 |
142 CHECK_EQ(0, callbacks_pending_); | 143 CHECK_EQ(0, callbacks_pending_); |
143 | 144 |
144 chromeos::BluetoothAdapter::DeviceList devices = | 145 chromeos::BluetoothAdapter::DeviceList devices = |
145 GetMutableAdapter(profile())->GetDevices(); | 146 GetMutableAdapter(profile())->GetDevices(); |
146 for (chromeos::BluetoothAdapter::DeviceList::iterator i = devices.begin(); | 147 for (chromeos::BluetoothAdapter::DeviceList::iterator i = devices.begin(); |
147 i != devices.end(); ++i) { | 148 i != devices.end(); ++i) { |
keybuk
2012/09/13 23:57:30
what happened here? (x2)
youngki
2012/09/17 21:53:02
I aligned the second line to the one character nex
| |
148 chromeos::BluetoothDevice* device = *i; | 149 chromeos::BluetoothDevice* device = *i; |
149 CHECK(device); | 150 CHECK(device); |
150 | 151 |
151 if (!uuid.empty() && !(device->ProvidesServiceWithUUID(uuid))) | 152 if (!uuid.empty() && !(device->ProvidesServiceWithUUID(uuid))) |
152 continue; | 153 continue; |
153 | 154 |
154 if (options.name.get() == NULL) { | 155 if (options.name.get() == NULL) { |
155 DispatchDeviceSearchResult(*device); | 156 DispatchDeviceSearchResult(*device); |
156 continue; | 157 continue; |
157 } | 158 } |
(...skipping 13 matching lines...) Expand all Loading... | |
171 if (callbacks_pending_ == -1) | 172 if (callbacks_pending_ == -1) |
172 SendResponse(true); | 173 SendResponse(true); |
173 | 174 |
174 return true; | 175 return true; |
175 } | 176 } |
176 | 177 |
177 void BluetoothGetServicesFunction::GetServiceRecordsCallback( | 178 void BluetoothGetServicesFunction::GetServiceRecordsCallback( |
178 base::ListValue* services, | 179 base::ListValue* services, |
179 const chromeos::BluetoothDevice::ServiceRecordList& records) { | 180 const chromeos::BluetoothDevice::ServiceRecordList& records) { |
180 for (chromeos::BluetoothDevice::ServiceRecordList::const_iterator i = | 181 for (chromeos::BluetoothDevice::ServiceRecordList::const_iterator i = |
181 records.begin(); i != records.end(); ++i) { | 182 records.begin(); i != records.end(); ++i) { |
182 const chromeos::BluetoothServiceRecord& record = **i; | 183 const chromeos::BluetoothServiceRecord& record = **i; |
183 experimental_bluetooth::ServiceRecord api_record; | 184 experimental_bluetooth::ServiceRecord api_record; |
184 api_record.name = record.name(); | 185 api_record.name = record.name(); |
185 if (!record.uuid().empty()) | 186 if (!record.uuid().empty()) |
186 api_record.uuid.reset(new std::string(record.uuid())); | 187 api_record.uuid.reset(new std::string(record.uuid())); |
187 services->Append(api_record.ToValue().release()); | 188 services->Append(api_record.ToValue().release()); |
188 } | 189 } |
189 | 190 |
190 SendResponse(true); | 191 SendResponse(true); |
191 } | 192 } |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 #endif | 609 #endif |
609 | 610 |
610 BluetoothReadFunction::BluetoothReadFunction() {} | 611 BluetoothReadFunction::BluetoothReadFunction() {} |
611 BluetoothReadFunction::~BluetoothReadFunction() {} | 612 BluetoothReadFunction::~BluetoothReadFunction() {} |
612 | 613 |
613 BluetoothWriteFunction::BluetoothWriteFunction() {} | 614 BluetoothWriteFunction::BluetoothWriteFunction() {} |
614 BluetoothWriteFunction::~BluetoothWriteFunction() {} | 615 BluetoothWriteFunction::~BluetoothWriteFunction() {} |
615 | 616 |
616 } // namespace api | 617 } // namespace api |
617 } // namespace extensions | 618 } // namespace extensions |
OLD | NEW |