Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
index a34580f671f39955f109f5fffe9825a8e96ab18a..fc50f4ea8c17f0700bd7abd20d410f6043ff2e47 100644 |
--- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
+++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
@@ -87,6 +87,10 @@ const char kStatusAdvertisementAlreadyExists[] = |
"An advertisement is already advertising"; |
const char kStatusAdvertisementDoesNotExist[] = |
"This advertisement does not exist"; |
+#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
+const char kStatusInvalidAdvertisingInterval[] = |
+ "Invalid advertising interval specified."; |
+#endif |
// Returns the correct error string based on error status |status|. This is used |
// to set the value of |chrome.runtime.lastError.message| and should not be |
@@ -1298,6 +1302,45 @@ void BluetoothLowEnergyUnregisterAdvertisementFunction::ErrorCallback( |
SendResponse(false); |
} |
+// SetAdvertisingInterval: |
+ |
+template class BLEPeripheralExtensionFunction< |
+ apibtle::SetAdvertisingInterval::Params>; |
+ |
+void BluetoothLowEnergySetAdvertisingIntervalFunction::DoWork() { |
+#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
+ BluetoothLowEnergyEventRouter* event_router = |
+ GetEventRouter(browser_context()); |
+ event_router->adapter()->SetAdvertisingInterval( |
+ base::TimeDelta::FromMilliseconds(params_->min_interval), |
+ base::TimeDelta::FromMilliseconds(params_->max_interval), |
+ base::Bind( |
+ &BluetoothLowEnergySetAdvertisingIntervalFunction::SuccessCallback, |
+ this), |
+ base::Bind( |
+ &BluetoothLowEnergySetAdvertisingIntervalFunction::ErrorCallback, |
+ this)); |
+#endif |
+} |
+ |
+void BluetoothLowEnergySetAdvertisingIntervalFunction::SuccessCallback() { |
+ Respond(NoArguments()); |
+} |
+ |
+void BluetoothLowEnergySetAdvertisingIntervalFunction::ErrorCallback( |
+ device::BluetoothAdvertisement::ErrorCode status) { |
+#if defined(OS_CHROMEOS) || defined(OS_LINUX) |
+ switch (status) { |
+ case device::BluetoothAdvertisement::ErrorCode:: |
+ ERROR_INVALID_ADVERTISEMENT_INTERVAL: |
+ Respond(Error(kStatusInvalidAdvertisingInterval)); |
+ break; |
+ default: |
+ Respond(Error(kErrorOperationFailed)); |
+ } |
+#endif |
+} |
+ |
// createService: |
template class BLEPeripheralExtensionFunction<apibtle::CreateService::Params>; |