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

Unified Diff: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc

Issue 10536159: Bluetooth Extension API: Add a discovery API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove chromeos/bluetooth code Created 8 years, 6 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/bluetooth_api.cc
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
index 7b80b96d7a4aa25bd28e63df964dc610e60d156d..731b9502cc939a724b22c51530ef43501b5688f1 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
@@ -46,6 +46,9 @@ namespace {
const char kFailedToConnect[] = "Connection failed";
const char kInvalidDevice[] = "Invalid device";
const char kSocketNotFoundError[] = "Socket not found: invalid socket id";
+const char kStartDiscoveryFailed[] =
+ "Starting discovery failed, or already discovering";
+const char kStopDiscoveryFailed[] = "Failed to stop discovery";
} // namespace
@@ -302,6 +305,54 @@ bool BluetoothWriteFunction::Respond() {
return success_;
}
+void BluetoothStartDiscoveryFunction::OnSuccessCallback() {
+ SendResponse(true);
+ Release(); // Added in RunImpl
+}
+
+void BluetoothStartDiscoveryFunction::OnErrorCallback() {
+ SetError(kStartDiscoveryFailed);
+ SendResponse(false);
+ Release(); // Added in RunImpl
+}
+
+bool BluetoothStartDiscoveryFunction::RunImpl() {
+ GetEventRouter(profile())->SetSendDiscoveryEvents(true);
+
+ // BluetoothAdapter will throw an error if we SetDiscovering(true) when
+ // discovery is already in progress
+ if (GetMutableAdapter(profile())->IsDiscovering()) {
+ SendResponse(true);
+ return true;
+ }
+
+ GetMutableAdapter(profile())->SetDiscovering(true,
+ base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this),
+ base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this));
+ AddRef(); // Removed in whichever callback is called.
+ return true;
+}
+
+void BluetoothStopDiscoveryFunction::OnSuccessCallback() {
+ SendResponse(true);
+ Release(); // Added in RunImpl
+}
+
+void BluetoothStopDiscoveryFunction::OnErrorCallback() {
+ SetError(kStopDiscoveryFailed);
+ SendResponse(false);
+ Release(); // Added in RunImpl
+}
+
+bool BluetoothStopDiscoveryFunction::RunImpl() {
+ GetEventRouter(profile())->SetSendDiscoveryEvents(false);
+ GetMutableAdapter(profile())->SetDiscovering(false,
+ base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this),
+ base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this));
+ AddRef(); // Removed in whichever callback is called.
+ return true;
+}
+
#else
// -----------------------------------------------------------------------------
@@ -366,6 +417,16 @@ bool BluetoothWriteFunction::Respond() {
return false;
}
+bool BluetoothStartDiscoveryFunction::RunImpl() {
+ NOTREACHED() << "Not implemented yet";
+ return false;
+}
+
+bool BluetoothStopDiscoveryFunction::RunImpl() {
+ NOTREACHED() << "Not implemented yet";
+ return false;
+}
+
#endif
BluetoothReadFunction::BluetoothReadFunction() {}

Powered by Google App Engine
This is Rietveld 408576698