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

Side by Side Diff: chrome/browser/chromeos/extensions/bluetooth_event_router.cc

Issue 10915148: Change getDevices to use a DeviceCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test breakage Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(**i); 84 DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceDiscovered,
85 **i);
85 } 86 }
86 } 87 }
87 88
88 send_discovery_events_ = should_send; 89 send_discovery_events_ = should_send;
89 } 90 }
90 91
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
91 void ExtensionBluetoothEventRouter::AdapterPresentChanged( 103 void ExtensionBluetoothEventRouter::AdapterPresentChanged(
92 chromeos::BluetoothAdapter* adapter, bool present) { 104 chromeos::BluetoothAdapter* adapter, bool present) {
93 if (adapter != adapter_.get()) { 105 if (adapter != adapter_.get()) {
94 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); 106 DVLOG(1) << "Ignoring event for adapter " << adapter->address();
95 return; 107 return;
96 } 108 }
97 109
98 DispatchBooleanValueEvent( 110 DispatchBooleanValueEvent(
99 extensions::event_names::kBluetoothOnAvailabilityChanged, 111 extensions::event_names::kBluetoothOnAvailabilityChanged,
100 present); 112 present);
(...skipping 30 matching lines...) Expand all
131 } 143 }
132 144
133 void ExtensionBluetoothEventRouter::DeviceAdded( 145 void ExtensionBluetoothEventRouter::DeviceAdded(
134 chromeos::BluetoothAdapter* adapter, chromeos::BluetoothDevice* device) { 146 chromeos::BluetoothAdapter* adapter, chromeos::BluetoothDevice* device) {
135 if (adapter != adapter_.get()) { 147 if (adapter != adapter_.get()) {
136 DVLOG(1) << "Ignoring event for adapter " << adapter->address(); 148 DVLOG(1) << "Ignoring event for adapter " << adapter->address();
137 return; 149 return;
138 } 150 }
139 151
140 experimental_bluetooth::Device* extension_device = 152 experimental_bluetooth::Device* extension_device =
141 new experimental_bluetooth::Device(); 153 new experimental_bluetooth::Device();
142 experimental_bluetooth::BluetoothDeviceToApiDevice(*device, extension_device); 154 experimental_bluetooth::BluetoothDeviceToApiDevice(*device, extension_device);
143 discovered_devices_.push_back(extension_device); 155 discovered_devices_.push_back(extension_device);
144 156
145 if (!send_discovery_events_) 157 if (!send_discovery_events_)
146 return; 158 return;
147 159
148 DispatchDeviceEvent(*extension_device); 160 DispatchDeviceEvent(extensions::event_names::kBluetoothOnDeviceDiscovered,
161 *extension_device);
149 } 162 }
150 163
151 void ExtensionBluetoothEventRouter::DispatchBooleanValueEvent( 164 void ExtensionBluetoothEventRouter::DispatchBooleanValueEvent(
152 const char* event_name, bool value) { 165 const char* event_name, bool value) {
153 scoped_ptr<ListValue> args(new ListValue()); 166 scoped_ptr<ListValue> args(new ListValue());
154 args->Append(Value::CreateBooleanValue(value)); 167 args->Append(Value::CreateBooleanValue(value));
155 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( 168 profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
156 event_name, args.Pass(), NULL, GURL()); 169 event_name, args.Pass(), NULL, GURL());
157 } 170 }
158 171
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
170 } // namespace chromeos 172 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/bluetooth_event_router.h ('k') | chrome/browser/extensions/api/bluetooth/bluetooth_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698