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/bind.h" | 10 #include "base/bind.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceDiscovered, | 155 DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceDiscovered, |
156 **i); | 156 **i); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 send_discovery_events_ = should_send; | 160 send_discovery_events_ = should_send; |
161 } | 161 } |
162 | 162 |
163 void ExtensionBluetoothEventRouter::DispatchDeviceEvent( | 163 void ExtensionBluetoothEventRouter::DispatchDeviceEvent( |
164 const char* event_name, const extensions::api::bluetooth::Device& device) { | 164 const char* event_name, const extensions::api::bluetooth::Device& device) { |
165 scoped_ptr<ListValue> args(new ListValue()); | 165 scoped_ptr<base::ListValue> args(new base::ListValue()); |
166 args->Append(device.ToValue().release()); | 166 args->Append(device.ToValue().release()); |
167 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 167 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
168 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 168 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); |
169 } | 169 } |
170 | 170 |
171 void ExtensionBluetoothEventRouter::DispatchConnectionEvent( | 171 void ExtensionBluetoothEventRouter::DispatchConnectionEvent( |
172 const std::string& extension_id, | 172 const std::string& extension_id, |
173 const std::string& uuid, | 173 const std::string& uuid, |
174 const device::BluetoothDevice* device, | 174 const device::BluetoothDevice* device, |
175 scoped_refptr<device::BluetoothSocket> socket) { | 175 scoped_refptr<device::BluetoothSocket> socket) { |
176 if (!HasProfile(uuid)) | 176 if (!HasProfile(uuid)) |
177 return; | 177 return; |
178 | 178 |
179 int socket_id = RegisterSocket(socket); | 179 int socket_id = RegisterSocket(socket); |
180 api::bluetooth::Socket result_socket; | 180 api::bluetooth::Socket result_socket; |
181 api::bluetooth::BluetoothDeviceToApiDevice(*device, &result_socket.device); | 181 api::bluetooth::BluetoothDeviceToApiDevice(*device, &result_socket.device); |
182 result_socket.profile.uuid = uuid; | 182 result_socket.profile.uuid = uuid; |
183 result_socket.id = socket_id; | 183 result_socket.id = socket_id; |
184 | 184 |
185 scoped_ptr<ListValue> args(new ListValue()); | 185 scoped_ptr<base::ListValue> args(new base::ListValue()); |
186 args->Append(result_socket.ToValue().release()); | 186 args->Append(result_socket.ToValue().release()); |
187 scoped_ptr<Event> event(new Event( | 187 scoped_ptr<Event> event(new Event( |
188 extensions::event_names::kBluetoothOnConnection, args.Pass())); | 188 extensions::event_names::kBluetoothOnConnection, args.Pass())); |
189 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( | 189 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( |
190 extension_id, event.Pass()); | 190 extension_id, event.Pass()); |
191 } | 191 } |
192 | 192 |
193 void ExtensionBluetoothEventRouter::AdapterPresentChanged( | 193 void ExtensionBluetoothEventRouter::AdapterPresentChanged( |
194 device::BluetoothAdapter* adapter, bool present) { | 194 device::BluetoothAdapter* adapter, bool present) { |
195 if (adapter != adapter_.get()) { | 195 if (adapter != adapter_.get()) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 if (adapter_.get() && num_event_listeners_ == 0) { | 264 if (adapter_.get() && num_event_listeners_ == 0) { |
265 adapter_->RemoveObserver(this); | 265 adapter_->RemoveObserver(this); |
266 adapter_ = NULL; | 266 adapter_ = NULL; |
267 } | 267 } |
268 } | 268 } |
269 | 269 |
270 void ExtensionBluetoothEventRouter::DispatchAdapterStateEvent() { | 270 void ExtensionBluetoothEventRouter::DispatchAdapterStateEvent() { |
271 api::bluetooth::AdapterState state; | 271 api::bluetooth::AdapterState state; |
272 PopulateAdapterState(*adapter_.get(), &state); | 272 PopulateAdapterState(*adapter_.get(), &state); |
273 | 273 |
274 scoped_ptr<ListValue> args(new ListValue()); | 274 scoped_ptr<base::ListValue> args(new base::ListValue()); |
275 args->Append(state.ToValue().release()); | 275 args->Append(state.ToValue().release()); |
276 scoped_ptr<Event> event(new Event( | 276 scoped_ptr<Event> event(new Event( |
277 extensions::event_names::kBluetoothOnAdapterStateChanged, | 277 extensions::event_names::kBluetoothOnAdapterStateChanged, |
278 args.Pass())); | 278 args.Pass())); |
279 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 279 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); |
280 } | 280 } |
281 | 281 |
282 } // namespace extensions | 282 } // namespace extensions |
OLD | NEW |