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/bluetooth_event_router.h" | 5 #include "chrome/browser/extensions/bluetooth_event_router.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" | 13 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" |
14 #include "chrome/browser/extensions/event_names.h" | 14 #include "chrome/browser/extensions/event_names.h" |
15 #include "chrome/browser/extensions/event_router.h" | 15 #include "chrome/browser/extensions/event_router.h" |
| 16 #include "chrome/browser/extensions/extension_system.h" |
16 #include "chrome/common/extensions/api/bluetooth.h" | 17 #include "chrome/common/extensions/api/bluetooth.h" |
17 #include "device/bluetooth/bluetooth_adapter.h" | 18 #include "device/bluetooth/bluetooth_adapter.h" |
18 #include "device/bluetooth/bluetooth_adapter_factory.h" | 19 #include "device/bluetooth/bluetooth_adapter_factory.h" |
19 #include "device/bluetooth/bluetooth_device.h" | 20 #include "device/bluetooth/bluetooth_device.h" |
20 #include "device/bluetooth/bluetooth_socket.h" | 21 #include "device/bluetooth/bluetooth_socket.h" |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
24 ExtensionBluetoothEventRouter::ExtensionBluetoothEventRouter(Profile* profile) | 25 ExtensionBluetoothEventRouter::ExtensionBluetoothEventRouter(Profile* profile) |
25 : send_discovery_events_(false), | 26 : send_discovery_events_(false), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
92 send_discovery_events_ = should_send; | 93 send_discovery_events_ = should_send; |
93 } | 94 } |
94 | 95 |
95 void ExtensionBluetoothEventRouter::DispatchDeviceEvent( | 96 void ExtensionBluetoothEventRouter::DispatchDeviceEvent( |
96 const char* event_name, const extensions::api::bluetooth::Device& device) { | 97 const char* event_name, const extensions::api::bluetooth::Device& device) { |
97 scoped_ptr<ListValue> args(new ListValue()); | 98 scoped_ptr<ListValue> args(new ListValue()); |
98 args->Append(device.ToValue().release()); | 99 args->Append(device.ToValue().release()); |
99 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 100 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
100 event_name, | 101 DispatchEventToRenderers(event_name, args.Pass(), NULL, GURL()); |
101 args.Pass(), | |
102 NULL, | |
103 GURL()); | |
104 } | 102 } |
105 | 103 |
106 void ExtensionBluetoothEventRouter::AdapterPresentChanged( | 104 void ExtensionBluetoothEventRouter::AdapterPresentChanged( |
107 device::BluetoothAdapter* adapter, bool present) { | 105 device::BluetoothAdapter* adapter, bool present) { |
108 if (adapter != adapter_.get()) { | 106 if (adapter != adapter_.get()) { |
109 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); | 107 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); |
110 return; | 108 return; |
111 } | 109 } |
112 | 110 |
113 DispatchBooleanValueEvent( | 111 DispatchBooleanValueEvent( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 return; | 161 return; |
164 | 162 |
165 DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceDiscovered, | 163 DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceDiscovered, |
166 *extension_device); | 164 *extension_device); |
167 } | 165 } |
168 | 166 |
169 void ExtensionBluetoothEventRouter::DispatchBooleanValueEvent( | 167 void ExtensionBluetoothEventRouter::DispatchBooleanValueEvent( |
170 const char* event_name, bool value) { | 168 const char* event_name, bool value) { |
171 scoped_ptr<ListValue> args(new ListValue()); | 169 scoped_ptr<ListValue> args(new ListValue()); |
172 args->Append(Value::CreateBooleanValue(value)); | 170 args->Append(Value::CreateBooleanValue(value)); |
173 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 171 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
174 event_name, args.Pass(), NULL, GURL()); | 172 DispatchEventToRenderers(event_name, args.Pass(), NULL, GURL()); |
175 } | 173 } |
176 | 174 |
177 } // namespace extensions | 175 } // namespace extensions |
OLD | NEW |