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

Unified 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 side-by-side diff with in-line comments
Download patch
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>;

Powered by Google App Engine
This is Rietveld 408576698