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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_private_api.cc

Issue 400843002: Clean up Bluetooth API implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove a trailing return Created 6 years, 5 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 | Annotate | Revision Log
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 "chrome/browser/extensions/api/bluetooth/bluetooth_private_api.h" 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_private_api.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 114
115 } // namespace 115 } // namespace
116 116
117 BluetoothPrivateSetAdapterStateFunction:: 117 BluetoothPrivateSetAdapterStateFunction::
118 BluetoothPrivateSetAdapterStateFunction() {} 118 BluetoothPrivateSetAdapterStateFunction() {}
119 119
120 BluetoothPrivateSetAdapterStateFunction:: 120 BluetoothPrivateSetAdapterStateFunction::
121 ~BluetoothPrivateSetAdapterStateFunction() {} 121 ~BluetoothPrivateSetAdapterStateFunction() {}
122 122
123 bool BluetoothPrivateSetAdapterStateFunction::DoWork( 123 void BluetoothPrivateSetAdapterStateFunction::DoWork(
124 scoped_refptr<device::BluetoothAdapter> adapter) { 124 scoped_refptr<device::BluetoothAdapter> adapter) {
125 scoped_ptr<bt_private::SetAdapterState::Params> params( 125 scoped_ptr<bt_private::SetAdapterState::Params> params(
126 bt_private::SetAdapterState::Params::Create(*args_)); 126 bt_private::SetAdapterState::Params::Create(*args_));
127 EXTENSION_FUNCTION_VALIDATE(params.get()); 127 EXTENSION_FUNCTION_VALIDATE(params.get());
128 128
129 if (!adapter->IsPresent()) { 129 if (!adapter->IsPresent()) {
130 SetError(kAdapterNotPresent); 130 SetError(kAdapterNotPresent);
131 SendResponse(false); 131 SendResponse(false);
132 return true; 132 return;
133 } 133 }
134 134
135 const bt_private::NewAdapterState& new_state = params->adapter_state; 135 const bt_private::NewAdapterState& new_state = params->adapter_state;
136 136
137 // These properties are not owned. 137 // These properties are not owned.
138 std::string* name = new_state.name.get(); 138 std::string* name = new_state.name.get();
139 bool* powered = new_state.powered.get(); 139 bool* powered = new_state.powered.get();
140 bool* discoverable = new_state.discoverable.get(); 140 bool* discoverable = new_state.discoverable.get();
141 141
142 if (name && adapter->GetName() != *name) { 142 if (name && adapter->GetName() != *name) {
(...skipping 13 matching lines...) Expand all
156 if (discoverable && adapter->IsDiscoverable() != *discoverable) { 156 if (discoverable && adapter->IsDiscoverable() != *discoverable) {
157 pending_properties_.insert(kDiscoverableProperty); 157 pending_properties_.insert(kDiscoverableProperty);
158 adapter->SetDiscoverable( 158 adapter->SetDiscoverable(
159 *discoverable, 159 *discoverable,
160 CreatePropertySetCallback(kDiscoverableProperty), 160 CreatePropertySetCallback(kDiscoverableProperty),
161 CreatePropertyErrorCallback(kDiscoverableProperty)); 161 CreatePropertyErrorCallback(kDiscoverableProperty));
162 } 162 }
163 163
164 if (pending_properties_.empty()) 164 if (pending_properties_.empty())
165 SendResponse(true); 165 SendResponse(true);
166 return true;
167 } 166 }
168 167
169 base::Closure 168 base::Closure
170 BluetoothPrivateSetAdapterStateFunction::CreatePropertySetCallback( 169 BluetoothPrivateSetAdapterStateFunction::CreatePropertySetCallback(
171 const std::string& property_name) { 170 const std::string& property_name) {
172 return base::Bind( 171 return base::Bind(
173 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet, 172 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet,
174 this, 173 this,
175 property_name); 174 property_name);
176 } 175 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 SetError(error); 224 SetError(error);
226 SendResponse(false); 225 SendResponse(false);
227 } 226 }
228 227
229 BluetoothPrivateSetPairingResponseFunction:: 228 BluetoothPrivateSetPairingResponseFunction::
230 BluetoothPrivateSetPairingResponseFunction() {} 229 BluetoothPrivateSetPairingResponseFunction() {}
231 230
232 BluetoothPrivateSetPairingResponseFunction:: 231 BluetoothPrivateSetPairingResponseFunction::
233 ~BluetoothPrivateSetPairingResponseFunction() {} 232 ~BluetoothPrivateSetPairingResponseFunction() {}
234 233
235 bool BluetoothPrivateSetPairingResponseFunction::DoWork( 234 void BluetoothPrivateSetPairingResponseFunction::DoWork(
236 scoped_refptr<device::BluetoothAdapter> adapter) { 235 scoped_refptr<device::BluetoothAdapter> adapter) {
237 scoped_ptr<bt_private::SetPairingResponse::Params> params( 236 scoped_ptr<bt_private::SetPairingResponse::Params> params(
238 bt_private::SetPairingResponse::Params::Create(*args_)); 237 bt_private::SetPairingResponse::Params::Create(*args_));
239 EXTENSION_FUNCTION_VALIDATE(params.get()); 238 EXTENSION_FUNCTION_VALIDATE(params.get());
240 const bt_private::SetPairingResponseOptions& options = params->options; 239 const bt_private::SetPairingResponseOptions& options = params->options;
241 240
242 BluetoothEventRouter* router = 241 BluetoothEventRouter* router =
243 BluetoothAPI::Get(browser_context())->event_router(); 242 BluetoothAPI::Get(browser_context())->event_router();
244 if (!router->GetPairingDelegate(extension_id())) { 243 if (!router->GetPairingDelegate(extension_id())) {
245 SetError(kPairingNotEnabled); 244 SetError(kPairingNotEnabled);
246 SendResponse(false); 245 SendResponse(false);
247 return true; 246 return;
248 } 247 }
249 248
250 const std::string& device_address = options.device.address; 249 const std::string& device_address = options.device.address;
251 device::BluetoothDevice* device = adapter->GetDevice(device_address); 250 device::BluetoothDevice* device = adapter->GetDevice(device_address);
252 if (!device) { 251 if (!device) {
253 SetError(kDeviceNotFoundError); 252 SetError(kDeviceNotFoundError);
254 SendResponse(false); 253 SendResponse(false);
255 return true; 254 return;
256 } 255 }
257 256
258 if (!ValidatePairingResponseOptions(device, options)) { 257 if (!ValidatePairingResponseOptions(device, options)) {
259 SetError(kInvalidPairingResponseOptions); 258 SetError(kInvalidPairingResponseOptions);
260 SendResponse(false); 259 SendResponse(false);
261 return true; 260 return;
262 } 261 }
263 262
264 if (options.pincode.get()) { 263 if (options.pincode.get()) {
265 device->SetPinCode(*options.pincode.get()); 264 device->SetPinCode(*options.pincode.get());
266 } else if (options.passkey.get()) { 265 } else if (options.passkey.get()) {
267 device->SetPasskey(*options.passkey.get()); 266 device->SetPasskey(*options.passkey.get());
268 } else { 267 } else {
269 switch (options.response) { 268 switch (options.response) {
270 case bt_private::PAIRING_RESPONSE_CONFIRM: 269 case bt_private::PAIRING_RESPONSE_CONFIRM:
271 device->ConfirmPairing(); 270 device->ConfirmPairing();
272 break; 271 break;
273 case bt_private::PAIRING_RESPONSE_REJECT: 272 case bt_private::PAIRING_RESPONSE_REJECT:
274 device->RejectPairing(); 273 device->RejectPairing();
275 break; 274 break;
276 case bt_private::PAIRING_RESPONSE_CANCEL: 275 case bt_private::PAIRING_RESPONSE_CANCEL:
277 device->CancelPairing(); 276 device->CancelPairing();
278 break; 277 break;
279 default: 278 default:
280 NOTREACHED(); 279 NOTREACHED();
281 } 280 }
282 } 281 }
283 282
284 SendResponse(true); 283 SendResponse(true);
285 return true;
286 } 284 }
287 285
288 } // namespace api 286 } // namespace api
289 287
290 } // namespace extensions 288 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698