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

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

Issue 177113013: Bluetooth: add Device events, and cleanup JS API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arman-patch
Patch Set: Created 6 years, 10 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_event_router.cc
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
index 217d19e5081b05f67da1f1bed443c242282892a7..cf6c472557ecab8f4992b5bd5a44cf92288b5c9c 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router.cc
@@ -210,15 +210,6 @@ ExtensionBluetoothEventRouter::GetSocket(int id) {
return socket_entry->second.socket;
}
-void ExtensionBluetoothEventRouter::DispatchDeviceEvent(
- const std::string& event_name, const bluetooth::Device& device) {
- scoped_ptr<base::ListValue> args(new base::ListValue());
- args->Append(device.ToValue().release());
- scoped_ptr<Event> event(new Event(event_name, args.Pass()));
- ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent(
- event.Pass());
-}
-
void ExtensionBluetoothEventRouter::DispatchConnectionEvent(
const std::string& extension_id,
const std::string& uuid,
@@ -294,13 +285,32 @@ void ExtensionBluetoothEventRouter::DeviceAdded(
return;
}
- bluetooth::Device* extension_device =
- new bluetooth::Device();
- bluetooth::BluetoothDeviceToApiDevice(
- *device, extension_device);
+ DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceAdded,
+ device);
+}
- DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceDiscovered,
- *extension_device);
+void ExtensionBluetoothEventRouter::DeviceChanged(
+ device::BluetoothAdapter* adapter,
+ device::BluetoothDevice* device) {
+ if (adapter != adapter_.get()) {
+ DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress();
+ return;
+ }
+
+ DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceChanged,
+ device);
+}
+
+void ExtensionBluetoothEventRouter::DeviceRemoved(
+ device::BluetoothAdapter* adapter,
+ device::BluetoothDevice* device) {
+ if (adapter != adapter_.get()) {
+ DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress();
+ return;
+ }
+
+ DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceRemoved,
+ device);
}
void ExtensionBluetoothEventRouter::InitializeAdapterIfNeeded() {
@@ -338,6 +348,19 @@ void ExtensionBluetoothEventRouter::DispatchAdapterStateEvent() {
event.Pass());
}
+void ExtensionBluetoothEventRouter::DispatchDeviceEvent(
+ const std::string& event_name,
+ device::BluetoothDevice* device) {
+ bluetooth::Device extension_device;
+ bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device);
+
+ scoped_ptr<base::ListValue> args(new base::ListValue());
rpaquay 2014/03/06 00:11:19 You should be able to use auto-generated code, i.e
keybuk 2014/03/06 21:33:44 Done.
+ args->Append(extension_device.ToValue().release());
+ scoped_ptr<Event> event(new Event(event_name, args.Pass()));
+ ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent(
+ event.Pass());
+}
+
void ExtensionBluetoothEventRouter::CleanUpForExtension(
const std::string& extension_id) {
// Remove all profiles added by the extension.

Powered by Google App Engine
This is Rietveld 408576698