OLD | NEW |
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 Loading... |
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 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 91 const char kStatusInvalidAdvertisingInterval[] = |
| 92 "Invalid advertising interval specified."; |
| 93 #endif |
90 | 94 |
91 // Returns the correct error string based on error status |status|. This is used | 95 // 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 | 96 // to set the value of |chrome.runtime.lastError.message| and should not be |
93 // passed |BluetoothLowEnergyEventRouter::kStatusSuccess|. | 97 // passed |BluetoothLowEnergyEventRouter::kStatusSuccess|. |
94 std::string StatusToString(BluetoothLowEnergyEventRouter::Status status) { | 98 std::string StatusToString(BluetoothLowEnergyEventRouter::Status status) { |
95 switch (status) { | 99 switch (status) { |
96 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyConnected: | 100 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyConnected: |
97 return kErrorAlreadyConnected; | 101 return kErrorAlreadyConnected; |
98 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyNotifying: | 102 case BluetoothLowEnergyEventRouter::kStatusErrorAlreadyNotifying: |
99 return kErrorAlreadyNotifying; | 103 return kErrorAlreadyNotifying; |
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 case device::BluetoothAdvertisement::ErrorCode:: | 1295 case device::BluetoothAdvertisement::ErrorCode:: |
1292 ERROR_ADVERTISEMENT_DOES_NOT_EXIST: | 1296 ERROR_ADVERTISEMENT_DOES_NOT_EXIST: |
1293 SetError(kStatusAdvertisementDoesNotExist); | 1297 SetError(kStatusAdvertisementDoesNotExist); |
1294 break; | 1298 break; |
1295 default: | 1299 default: |
1296 SetError(kErrorOperationFailed); | 1300 SetError(kErrorOperationFailed); |
1297 } | 1301 } |
1298 SendResponse(false); | 1302 SendResponse(false); |
1299 } | 1303 } |
1300 | 1304 |
| 1305 // SetAdvertisingInterval: |
| 1306 |
| 1307 template class BLEPeripheralExtensionFunction< |
| 1308 apibtle::SetAdvertisingInterval::Params>; |
| 1309 |
| 1310 void BluetoothLowEnergySetAdvertisingIntervalFunction::DoWork() { |
| 1311 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 1312 BluetoothLowEnergyEventRouter* event_router = |
| 1313 GetEventRouter(browser_context()); |
| 1314 event_router->adapter()->SetAdvertisingInterval( |
| 1315 base::TimeDelta::FromMilliseconds(params_->min_interval), |
| 1316 base::TimeDelta::FromMilliseconds(params_->max_interval), |
| 1317 base::Bind( |
| 1318 &BluetoothLowEnergySetAdvertisingIntervalFunction::SuccessCallback, |
| 1319 this), |
| 1320 base::Bind( |
| 1321 &BluetoothLowEnergySetAdvertisingIntervalFunction::ErrorCallback, |
| 1322 this)); |
| 1323 #endif |
| 1324 } |
| 1325 |
| 1326 void BluetoothLowEnergySetAdvertisingIntervalFunction::SuccessCallback() { |
| 1327 Respond(NoArguments()); |
| 1328 } |
| 1329 |
| 1330 void BluetoothLowEnergySetAdvertisingIntervalFunction::ErrorCallback( |
| 1331 device::BluetoothAdvertisement::ErrorCode status) { |
| 1332 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 1333 switch (status) { |
| 1334 case device::BluetoothAdvertisement::ErrorCode:: |
| 1335 ERROR_INVALID_ADVERTISEMENT_INTERVAL: |
| 1336 Respond(Error(kStatusInvalidAdvertisingInterval)); |
| 1337 break; |
| 1338 default: |
| 1339 Respond(Error(kErrorOperationFailed)); |
| 1340 } |
| 1341 #endif |
| 1342 } |
| 1343 |
1301 // createService: | 1344 // createService: |
1302 | 1345 |
1303 template class BLEPeripheralExtensionFunction<apibtle::CreateService::Params>; | 1346 template class BLEPeripheralExtensionFunction<apibtle::CreateService::Params>; |
1304 | 1347 |
1305 void BluetoothLowEnergyCreateServiceFunction::DoWork() { | 1348 void BluetoothLowEnergyCreateServiceFunction::DoWork() { |
1306 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1349 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1307 // Causes link error on Windows. API will never be on Windows, so #ifdefing. | 1350 // 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 | 1351 // 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 | 1352 // code doesn't even compile on OSes it isn't being used on, but currently this |
1310 // is not possible. | 1353 // is not possible. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 params_->response.value->end()); | 1531 params_->response.value->end()); |
1489 } | 1532 } |
1490 event_router_->HandleRequestResponse( | 1533 event_router_->HandleRequestResponse( |
1491 extension(), params_->response.request_id, params_->response.is_error, | 1534 extension(), params_->response.request_id, params_->response.is_error, |
1492 uint8_vector); | 1535 uint8_vector); |
1493 Respond(NoArguments()); | 1536 Respond(NoArguments()); |
1494 } | 1537 } |
1495 | 1538 |
1496 } // namespace api | 1539 } // namespace api |
1497 } // namespace extensions | 1540 } // namespace extensions |
OLD | NEW |