| 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/chromeos/extensions/bluetooth_event_router.h" | 5 #include "chrome/browser/chromeos/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" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 bool ExtensionBluetoothEventRouter::IsResponsibleForDiscovery() const { | 74 bool ExtensionBluetoothEventRouter::IsResponsibleForDiscovery() const { |
| 75 return responsible_for_discovery_; | 75 return responsible_for_discovery_; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ExtensionBluetoothEventRouter::SetSendDiscoveryEvents(bool should_send) { | 78 void ExtensionBluetoothEventRouter::SetSendDiscoveryEvents(bool should_send) { |
| 79 // At the transition into sending devices, also send past devices that | 79 // At the transition into sending devices, also send past devices that |
| 80 // were discovered as they will not be discovered again. | 80 // were discovered as they will not be discovered again. |
| 81 if (should_send && !send_discovery_events_) { | 81 if (should_send && !send_discovery_events_) { |
| 82 for (DeviceList::const_iterator i = discovered_devices_.begin(); | 82 for (DeviceList::const_iterator i = discovered_devices_.begin(); |
| 83 i != discovered_devices_.end(); ++i) { | 83 i != discovered_devices_.end(); ++i) { |
| 84 DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceDiscovered, | 84 DispatchDeviceEvent(**i); |
| 85 **i); | |
| 86 } | 85 } |
| 87 } | 86 } |
| 88 | 87 |
| 89 send_discovery_events_ = should_send; | 88 send_discovery_events_ = should_send; |
| 90 } | 89 } |
| 91 | 90 |
| 92 void ExtensionBluetoothEventRouter::DispatchDeviceEvent( | |
| 93 const char* event_name, const experimental_bluetooth::Device& device) { | |
| 94 scoped_ptr<ListValue> args(new ListValue()); | |
| 95 args->Append(device.ToValue().release()); | |
| 96 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | |
| 97 event_name, | |
| 98 args.Pass(), | |
| 99 NULL, | |
| 100 GURL()); | |
| 101 } | |
| 102 | |
| 103 void ExtensionBluetoothEventRouter::AdapterPresentChanged( | 91 void ExtensionBluetoothEventRouter::AdapterPresentChanged( |
| 104 chromeos::BluetoothAdapter* adapter, bool present) { | 92 chromeos::BluetoothAdapter* adapter, bool present) { |
| 105 if (adapter != adapter_.get()) { | 93 if (adapter != adapter_.get()) { |
| 106 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); | 94 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); |
| 107 return; | 95 return; |
| 108 } | 96 } |
| 109 | 97 |
| 110 DispatchBooleanValueEvent( | 98 DispatchBooleanValueEvent( |
| 111 extensions::event_names::kBluetoothOnAvailabilityChanged, | 99 extensions::event_names::kBluetoothOnAvailabilityChanged, |
| 112 present); | 100 present); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 143 } | 131 } |
| 144 | 132 |
| 145 void ExtensionBluetoothEventRouter::DeviceAdded( | 133 void ExtensionBluetoothEventRouter::DeviceAdded( |
| 146 chromeos::BluetoothAdapter* adapter, chromeos::BluetoothDevice* device) { | 134 chromeos::BluetoothAdapter* adapter, chromeos::BluetoothDevice* device) { |
| 147 if (adapter != adapter_.get()) { | 135 if (adapter != adapter_.get()) { |
| 148 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); | 136 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); |
| 149 return; | 137 return; |
| 150 } | 138 } |
| 151 | 139 |
| 152 experimental_bluetooth::Device* extension_device = | 140 experimental_bluetooth::Device* extension_device = |
| 153 new experimental_bluetooth::Device(); | 141 new experimental_bluetooth::Device(); |
| 154 experimental_bluetooth::BluetoothDeviceToApiDevice(*device, extension_device); | 142 experimental_bluetooth::BluetoothDeviceToApiDevice(*device, extension_device); |
| 155 discovered_devices_.push_back(extension_device); | 143 discovered_devices_.push_back(extension_device); |
| 156 | 144 |
| 157 if (!send_discovery_events_) | 145 if (!send_discovery_events_) |
| 158 return; | 146 return; |
| 159 | 147 |
| 160 DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceDiscovered, | 148 DispatchDeviceEvent(*extension_device); |
| 161 *extension_device); | |
| 162 } | 149 } |
| 163 | 150 |
| 164 void ExtensionBluetoothEventRouter::DispatchBooleanValueEvent( | 151 void ExtensionBluetoothEventRouter::DispatchBooleanValueEvent( |
| 165 const char* event_name, bool value) { | 152 const char* event_name, bool value) { |
| 166 scoped_ptr<ListValue> args(new ListValue()); | 153 scoped_ptr<ListValue> args(new ListValue()); |
| 167 args->Append(Value::CreateBooleanValue(value)); | 154 args->Append(Value::CreateBooleanValue(value)); |
| 168 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 155 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 169 event_name, args.Pass(), NULL, GURL()); | 156 event_name, args.Pass(), NULL, GURL()); |
| 170 } | 157 } |
| 171 | 158 |
| 159 void ExtensionBluetoothEventRouter::DispatchDeviceEvent( |
| 160 const experimental_bluetooth::Device& device) { |
| 161 scoped_ptr<ListValue> args(new ListValue()); |
| 162 args->Append(device.ToValue().release()); |
| 163 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 164 extensions::event_names::kBluetoothOnDeviceDiscovered, |
| 165 args.Pass(), |
| 166 NULL, |
| 167 GURL()); |
| 168 } |
| 169 |
| 172 } // namespace chromeos | 170 } // namespace chromeos |
| OLD | NEW |