| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bluetooth_event_router.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 const char* event_name, const extensions::api::bluetooth::Device& device) { | 127 const char* event_name, const extensions::api::bluetooth::Device& device) { |
| 128 scoped_ptr<ListValue> args(new ListValue()); | 128 scoped_ptr<ListValue> args(new ListValue()); |
| 129 args->Append(device.ToValue().release()); | 129 args->Append(device.ToValue().release()); |
| 130 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 130 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
| 131 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 131 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void ExtensionBluetoothEventRouter::AdapterPresentChanged( | 134 void ExtensionBluetoothEventRouter::AdapterPresentChanged( |
| 135 device::BluetoothAdapter* adapter, bool present) { | 135 device::BluetoothAdapter* adapter, bool present) { |
| 136 if (adapter != adapter_) { | 136 if (adapter != adapter_) { |
| 137 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); | 137 DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress(); |
| 138 return; | 138 return; |
| 139 } | 139 } |
| 140 DispatchAdapterStateEvent(); | 140 DispatchAdapterStateEvent(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ExtensionBluetoothEventRouter::AdapterPoweredChanged( | 143 void ExtensionBluetoothEventRouter::AdapterPoweredChanged( |
| 144 device::BluetoothAdapter* adapter, bool has_power) { | 144 device::BluetoothAdapter* adapter, bool has_power) { |
| 145 if (adapter != adapter_) { | 145 if (adapter != adapter_) { |
| 146 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); | 146 DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress(); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 DispatchAdapterStateEvent(); | 149 DispatchAdapterStateEvent(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void ExtensionBluetoothEventRouter::AdapterDiscoveringChanged( | 152 void ExtensionBluetoothEventRouter::AdapterDiscoveringChanged( |
| 153 device::BluetoothAdapter* adapter, bool discovering) { | 153 device::BluetoothAdapter* adapter, bool discovering) { |
| 154 if (adapter != adapter_) { | 154 if (adapter != adapter_) { |
| 155 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); | 155 DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress(); |
| 156 return; | 156 return; |
| 157 } | 157 } |
| 158 | 158 |
| 159 if (!discovering) { | 159 if (!discovering) { |
| 160 send_discovery_events_ = false; | 160 send_discovery_events_ = false; |
| 161 responsible_for_discovery_ = false; | 161 responsible_for_discovery_ = false; |
| 162 discovered_devices_.clear(); | 162 discovered_devices_.clear(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 DispatchAdapterStateEvent(); | 165 DispatchAdapterStateEvent(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void ExtensionBluetoothEventRouter::DeviceAdded( | 168 void ExtensionBluetoothEventRouter::DeviceAdded( |
| 169 device::BluetoothAdapter* adapter, | 169 device::BluetoothAdapter* adapter, |
| 170 device::BluetoothDevice* device) { | 170 device::BluetoothDevice* device) { |
| 171 if (adapter != adapter_) { | 171 if (adapter != adapter_) { |
| 172 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); | 172 DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress(); |
| 173 return; | 173 return; |
| 174 } | 174 } |
| 175 | 175 |
| 176 extensions::api::bluetooth::Device* extension_device = | 176 extensions::api::bluetooth::Device* extension_device = |
| 177 new extensions::api::bluetooth::Device(); | 177 new extensions::api::bluetooth::Device(); |
| 178 extensions::api::bluetooth::BluetoothDeviceToApiDevice( | 178 extensions::api::bluetooth::BluetoothDeviceToApiDevice( |
| 179 *device, extension_device); | 179 *device, extension_device); |
| 180 discovered_devices_.push_back(extension_device); | 180 discovered_devices_.push_back(extension_device); |
| 181 | 181 |
| 182 if (!send_discovery_events_) | 182 if (!send_discovery_events_) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 214 |
| 215 scoped_ptr<ListValue> args(new ListValue()); | 215 scoped_ptr<ListValue> args(new ListValue()); |
| 216 args->Append(state.ToValue().release()); | 216 args->Append(state.ToValue().release()); |
| 217 scoped_ptr<Event> event(new Event( | 217 scoped_ptr<Event> event(new Event( |
| 218 extensions::event_names::kBluetoothOnAdapterStateChanged, | 218 extensions::event_names::kBluetoothOnAdapterStateChanged, |
| 219 args.Pass())); | 219 args.Pass())); |
| 220 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 220 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace extensions | 223 } // namespace extensions |
| OLD | NEW |