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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc

Issue 400843002: Clean up Bluetooth API implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove a trailing return Created 6 years, 5 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/extensions/api/bluetooth/bluetooth_api.h" 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) { 94 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) {
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
96 if (event_router()->IsBluetoothSupported()) 96 if (event_router()->IsBluetoothSupported())
97 event_router()->OnListenerRemoved(); 97 event_router()->OnListenerRemoved();
98 } 98 }
99 99
100 namespace api { 100 namespace api {
101 101
102 BluetoothGetAdapterStateFunction::~BluetoothGetAdapterStateFunction() {} 102 BluetoothGetAdapterStateFunction::~BluetoothGetAdapterStateFunction() {}
103 103
104 bool BluetoothGetAdapterStateFunction::DoWork( 104 void BluetoothGetAdapterStateFunction::DoWork(
105 scoped_refptr<BluetoothAdapter> adapter) { 105 scoped_refptr<BluetoothAdapter> adapter) {
106 bluetooth::AdapterState state; 106 bluetooth::AdapterState state;
107 PopulateAdapterState(*adapter.get(), &state); 107 PopulateAdapterState(*adapter.get(), &state);
108 results_ = bluetooth::GetAdapterState::Results::Create(state); 108 results_ = bluetooth::GetAdapterState::Results::Create(state);
109 SendResponse(true); 109 SendResponse(true);
110 return true;
111 } 110 }
112 111
113 BluetoothGetDevicesFunction::~BluetoothGetDevicesFunction() {} 112 BluetoothGetDevicesFunction::~BluetoothGetDevicesFunction() {}
114 113
115 bool BluetoothGetDevicesFunction::DoWork( 114 void BluetoothGetDevicesFunction::DoWork(
116 scoped_refptr<BluetoothAdapter> adapter) { 115 scoped_refptr<BluetoothAdapter> adapter) {
117 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 116 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
118 117
119 base::ListValue* device_list = new base::ListValue; 118 base::ListValue* device_list = new base::ListValue;
120 SetResult(device_list); 119 SetResult(device_list);
121 120
122 BluetoothAdapter::DeviceList devices = adapter->GetDevices(); 121 BluetoothAdapter::DeviceList devices = adapter->GetDevices();
123 for (BluetoothAdapter::DeviceList::const_iterator iter = devices.begin(); 122 for (BluetoothAdapter::DeviceList::const_iterator iter = devices.begin();
124 iter != devices.end(); 123 iter != devices.end();
125 ++iter) { 124 ++iter) {
126 const BluetoothDevice* device = *iter; 125 const BluetoothDevice* device = *iter;
127 DCHECK(device); 126 DCHECK(device);
128 127
129 bluetooth::Device extension_device; 128 bluetooth::Device extension_device;
130 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); 129 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device);
131 130
132 device_list->Append(extension_device.ToValue().release()); 131 device_list->Append(extension_device.ToValue().release());
133 } 132 }
134 133
135 SendResponse(true); 134 SendResponse(true);
136
137 return true;
138 } 135 }
139 136
140 BluetoothGetDeviceFunction::~BluetoothGetDeviceFunction() {} 137 BluetoothGetDeviceFunction::~BluetoothGetDeviceFunction() {}
141 138
142 bool BluetoothGetDeviceFunction::DoWork( 139 void BluetoothGetDeviceFunction::DoWork(
143 scoped_refptr<BluetoothAdapter> adapter) { 140 scoped_refptr<BluetoothAdapter> adapter) {
144 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 141 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
145 142
146 scoped_ptr<GetDevice::Params> params(GetDevice::Params::Create(*args_)); 143 scoped_ptr<GetDevice::Params> params(GetDevice::Params::Create(*args_));
147 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 144 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
148 145
149 BluetoothDevice* device = adapter->GetDevice(params->device_address); 146 BluetoothDevice* device = adapter->GetDevice(params->device_address);
150 if (device) { 147 if (device) {
151 bluetooth::Device extension_device; 148 bluetooth::Device extension_device;
152 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); 149 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device);
153 SetResult(extension_device.ToValue().release()); 150 SetResult(extension_device.ToValue().release());
154 SendResponse(true); 151 SendResponse(true);
155 } else { 152 } else {
156 SetError(kInvalidDevice); 153 SetError(kInvalidDevice);
157 SendResponse(false); 154 SendResponse(false);
158 } 155 }
159
160 return false;
161 } 156 }
162 157
163 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { 158 void BluetoothStartDiscoveryFunction::OnSuccessCallback() {
164 SendResponse(true); 159 SendResponse(true);
165 } 160 }
166 161
167 void BluetoothStartDiscoveryFunction::OnErrorCallback() { 162 void BluetoothStartDiscoveryFunction::OnErrorCallback() {
168 SetError(kStartDiscoveryFailed); 163 SetError(kStartDiscoveryFailed);
169 SendResponse(false); 164 SendResponse(false);
170 } 165 }
171 166
172 bool BluetoothStartDiscoveryFunction::DoWork( 167 void BluetoothStartDiscoveryFunction::DoWork(
173 scoped_refptr<BluetoothAdapter> adapter) { 168 scoped_refptr<BluetoothAdapter> adapter) {
174 GetEventRouter(browser_context())->StartDiscoverySession( 169 GetEventRouter(browser_context())->StartDiscoverySession(
175 adapter, 170 adapter,
176 extension_id(), 171 extension_id(),
177 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), 172 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this),
178 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); 173 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this));
179
180 return true;
181 } 174 }
182 175
183 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { 176 void BluetoothStopDiscoveryFunction::OnSuccessCallback() {
184 SendResponse(true); 177 SendResponse(true);
185 } 178 }
186 179
187 void BluetoothStopDiscoveryFunction::OnErrorCallback() { 180 void BluetoothStopDiscoveryFunction::OnErrorCallback() {
188 SetError(kStopDiscoveryFailed); 181 SetError(kStopDiscoveryFailed);
189 SendResponse(false); 182 SendResponse(false);
190 } 183 }
191 184
192 bool BluetoothStopDiscoveryFunction::DoWork( 185 void BluetoothStopDiscoveryFunction::DoWork(
193 scoped_refptr<BluetoothAdapter> adapter) { 186 scoped_refptr<BluetoothAdapter> adapter) {
194 GetEventRouter(browser_context())->StopDiscoverySession( 187 GetEventRouter(browser_context())->StopDiscoverySession(
195 adapter, 188 adapter,
196 extension_id(), 189 extension_id(),
197 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), 190 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this),
198 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); 191 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this));
199
200 return true;
201 } 192 }
202 193
203 } // namespace api 194 } // namespace api
204 } // namespace extensions 195 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698