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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc

Issue 2353133005: Add the chrome.bluetoothLowEnergy.setAdvertisingInterval API. (Closed)
Patch Set: Created 4 years, 3 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 "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <iterator> 9 #include <iterator>
10 #include <utility> 10 #include <utility>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 "The characteristic does not have the indicate property set."; 80 "The characteristic does not have the indicate property set.";
81 const char kErrorServiceNotRegistered[] = 81 const char kErrorServiceNotRegistered[] =
82 "The characteristic is not owned by a service that is registered."; 82 "The characteristic is not owned by a service that is registered.";
83 const char kErrorUnknownNotificationError[] = 83 const char kErrorUnknownNotificationError[] =
84 "An unknown notification error occured."; 84 "An unknown notification error occured.";
85 85
86 const char kStatusAdvertisementAlreadyExists[] = 86 const char kStatusAdvertisementAlreadyExists[] =
87 "An advertisement is already advertising"; 87 "An advertisement is already advertising";
88 const char kStatusAdvertisementDoesNotExist[] = 88 const char kStatusAdvertisementDoesNotExist[] =
89 "This advertisement does not exist"; 89 "This advertisement does not exist";
90 const char kStatusInvalidAdvertisingInterval[] =
91 "Invalid advertising interval specified.";
90 92
91 // Returns the correct error string based on error status |status|. This is used 93 // Returns the correct error string based on error status |status|. This is used
92 // to set the value of |chrome.runtime.lastError.message| and should not be 94 // to set the value of |chrome.runtime.lastError.message| and should not be
93 // passed |BluetoothLowEnergyEventRouter::kStatusSuccess|. 95 // passed |BluetoothLowEnergyEventRouter::kStatusSuccess|.
94 std::string StatusToString(BluetoothLowEnergyEventRouter::Status status) { 96 std::string StatusToString(BluetoothLowEnergyEventRouter::Status status) {
95 switch (status) { 97 switch (status) {
96 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyConnected: 98 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyConnected:
97 return kErrorAlreadyConnected; 99 return kErrorAlreadyConnected;
98 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyNotifying: 100 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyNotifying:
99 return kErrorAlreadyNotifying; 101 return kErrorAlreadyNotifying;
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 case device::BluetoothAdvertisement::ErrorCode:: 1293 case device::BluetoothAdvertisement::ErrorCode::
1292 ERROR_ADVERTISEMENT_DOES_NOT_EXIST: 1294 ERROR_ADVERTISEMENT_DOES_NOT_EXIST:
1293 SetError(kStatusAdvertisementDoesNotExist); 1295 SetError(kStatusAdvertisementDoesNotExist);
1294 break; 1296 break;
1295 default: 1297 default:
1296 SetError(kErrorOperationFailed); 1298 SetError(kErrorOperationFailed);
1297 } 1299 }
1298 SendResponse(false); 1300 SendResponse(false);
1299 } 1301 }
1300 1302
1303 // SetAdvertisingInterval:
1304
1305 template class BLEPeripheralExtensionFunction<
1306 apibtle::SetAdvertisingInterval::Params>;
1307
1308 void BluetoothLowEnergySetAdvertisingIntervalFunction::DoWork() {
1309 BluetoothLowEnergyEventRouter* event_router =
1310 GetEventRouter(browser_context());
1311
1312 event_router->adapter()->SetAdvertisingInterval(
1313 base::TimeDelta::FromMilliseconds(params_->min_interval),
1314 base::TimeDelta::FromMilliseconds(params_->max_interval),
1315 base::Bind(
1316 &BluetoothLowEnergySetAdvertisingIntervalFunction::SuccessCallback,
1317 this),
1318 base::Bind(
1319 &BluetoothLowEnergySetAdvertisingIntervalFunction::ErrorCallback,
1320 this));
1321 }
1322
1323 void BluetoothLowEnergySetAdvertisingIntervalFunction::SuccessCallback() {
1324 Respond(NoArguments());
1325 }
1326
1327 void BluetoothLowEnergySetAdvertisingIntervalFunction::ErrorCallback(
1328 device::BluetoothAdvertisement::ErrorCode status) {
1329 switch (status) {
1330 case device::BluetoothAdvertisement::ErrorCode::
1331 ERROR_INVALID_ADVERTISEMENT_INTERVAL:
1332 Respond(Error(kStatusInvalidAdvertisingInterval));
1333 return;
xiyuan 2016/09/21 16:35:23 nit: remove since we have "break" ? Or keep this a
Rahul Chaturvedi 2016/09/21 18:54:12 Done.
1334 break;
1335 default:
1336 Respond(Error(kErrorOperationFailed));
1337 }
1338 }
1339
1301 // createService: 1340 // createService:
1302 1341
1303 template class BLEPeripheralExtensionFunction<apibtle::CreateService::Params>; 1342 template class BLEPeripheralExtensionFunction<apibtle::CreateService::Params>;
1304 1343
1305 void BluetoothLowEnergyCreateServiceFunction::DoWork() { 1344 void BluetoothLowEnergyCreateServiceFunction::DoWork() {
1306 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1345 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1307 // Causes link error on Windows. API will never be on Windows, so #ifdefing. 1346 // Causes link error on Windows. API will never be on Windows, so #ifdefing.
1308 // TODO: Ideally this should be handled by our feature system, so that this 1347 // TODO: Ideally this should be handled by our feature system, so that this
1309 // code doesn't even compile on OSes it isn't being used on, but currently this 1348 // code doesn't even compile on OSes it isn't being used on, but currently this
1310 // is not possible. 1349 // is not possible.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 params_->response.value->end()); 1527 params_->response.value->end());
1489 } 1528 }
1490 event_router_->HandleRequestResponse( 1529 event_router_->HandleRequestResponse(
1491 extension(), params_->response.request_id, params_->response.is_error, 1530 extension(), params_->response.request_id, params_->response.is_error,
1492 uint8_vector); 1531 uint8_vector);
1493 Respond(NoArguments()); 1532 Respond(NoArguments());
1494 } 1533 }
1495 1534
1496 } // namespace api 1535 } // namespace api
1497 } // namespace extensions 1536 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698