OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h" | 5 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 error_ = kPermissionDeniedError; | 133 error_ = kPermissionDeniedError; |
134 return false; | 134 return false; |
135 } | 135 } |
136 | 136 |
137 manager_ = ApiResourceManager<BluetoothApiSocket>::Get(browser_context()); | 137 manager_ = ApiResourceManager<BluetoothApiSocket>::Get(browser_context()); |
138 DCHECK(manager_) | 138 DCHECK(manager_) |
139 << "There is no socket manager. " | 139 << "There is no socket manager. " |
140 "If this assertion is failing during a test, then it is likely that " | 140 "If this assertion is failing during a test, then it is likely that " |
141 "TestExtensionSystem is failing to provide an instance of " | 141 "TestExtensionSystem is failing to provide an instance of " |
142 "ApiResourceManager<BluetoothApiSocket>."; | 142 "ApiResourceManager<BluetoothApiSocket>."; |
143 return manager_ != NULL; | 143 return manager_ != nullptr; |
144 } | 144 } |
145 | 145 |
146 bool BluetoothSocketAsyncApiFunction::Respond() { return error_.empty(); } | 146 bool BluetoothSocketAsyncApiFunction::Respond() { return error_.empty(); } |
147 | 147 |
148 void BluetoothSocketAsyncApiFunction::AsyncWorkCompleted() { | 148 void BluetoothSocketAsyncApiFunction::AsyncWorkCompleted() { |
149 SendResponse(Respond()); | 149 SendResponse(Respond()); |
150 } | 150 } |
151 | 151 |
152 void BluetoothSocketAsyncApiFunction::Work() {} | 152 void BluetoothSocketAsyncApiFunction::Work() {} |
153 | 153 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 if (!socket) { | 222 if (!socket) { |
223 error_ = kSocketNotFoundError; | 223 error_ = kSocketNotFoundError; |
224 return; | 224 return; |
225 } | 225 } |
226 | 226 |
227 SetSocketProperties(socket, ¶ms_.get()->properties); | 227 SetSocketProperties(socket, ¶ms_.get()->properties); |
228 results_ = bluetooth_socket::Update::Results::Create(); | 228 results_ = bluetooth_socket::Update::Results::Create(); |
229 } | 229 } |
230 | 230 |
231 BluetoothSocketSetPausedFunction::BluetoothSocketSetPausedFunction() | 231 BluetoothSocketSetPausedFunction::BluetoothSocketSetPausedFunction() |
232 : socket_event_dispatcher_(NULL) {} | 232 : socket_event_dispatcher_(nullptr) { |
| 233 } |
233 | 234 |
234 BluetoothSocketSetPausedFunction::~BluetoothSocketSetPausedFunction() {} | 235 BluetoothSocketSetPausedFunction::~BluetoothSocketSetPausedFunction() {} |
235 | 236 |
236 bool BluetoothSocketSetPausedFunction::Prepare() { | 237 bool BluetoothSocketSetPausedFunction::Prepare() { |
237 params_ = bluetooth_socket::SetPaused::Params::Create(*args_); | 238 params_ = bluetooth_socket::SetPaused::Params::Create(*args_); |
238 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 239 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
239 | 240 |
240 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); | 241 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); |
241 return socket_event_dispatcher_ != NULL; | 242 return socket_event_dispatcher_ != nullptr; |
242 } | 243 } |
243 | 244 |
244 void BluetoothSocketSetPausedFunction::Work() { | 245 void BluetoothSocketSetPausedFunction::Work() { |
245 BluetoothApiSocket* socket = GetSocket(params_->socket_id); | 246 BluetoothApiSocket* socket = GetSocket(params_->socket_id); |
246 if (!socket) { | 247 if (!socket) { |
247 error_ = kSocketNotFoundError; | 248 error_ = kSocketNotFoundError; |
248 return; | 249 return; |
249 } | 250 } |
250 | 251 |
251 if (socket->paused() != params_->paused) { | 252 if (socket->paused() != params_->paused) { |
252 socket->set_paused(params_->paused); | 253 socket->set_paused(params_->paused); |
253 if (!params_->paused) { | 254 if (!params_->paused) { |
254 socket_event_dispatcher_->OnSocketResume(extension_id(), | 255 socket_event_dispatcher_->OnSocketResume(extension_id(), |
255 params_->socket_id); | 256 params_->socket_id); |
256 } | 257 } |
257 } | 258 } |
258 | 259 |
259 results_ = bluetooth_socket::SetPaused::Results::Create(); | 260 results_ = bluetooth_socket::SetPaused::Results::Create(); |
260 } | 261 } |
261 | 262 |
262 BluetoothSocketListenFunction::BluetoothSocketListenFunction() {} | 263 BluetoothSocketListenFunction::BluetoothSocketListenFunction() {} |
263 | 264 |
264 BluetoothSocketListenFunction::~BluetoothSocketListenFunction() {} | 265 BluetoothSocketListenFunction::~BluetoothSocketListenFunction() {} |
265 | 266 |
266 bool BluetoothSocketListenFunction::Prepare() { | 267 bool BluetoothSocketListenFunction::Prepare() { |
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
268 if (!CreateParams()) | 269 if (!CreateParams()) |
269 return false; | 270 return false; |
270 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); | 271 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); |
271 return socket_event_dispatcher_ != NULL; | 272 return socket_event_dispatcher_ != nullptr; |
272 } | 273 } |
273 | 274 |
274 void BluetoothSocketListenFunction::AsyncWorkStart() { | 275 void BluetoothSocketListenFunction::AsyncWorkStart() { |
275 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); | 276 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); |
276 device::BluetoothAdapterFactory::GetAdapter( | 277 device::BluetoothAdapterFactory::GetAdapter( |
277 base::Bind(&BluetoothSocketListenFunction::OnGetAdapter, this)); | 278 base::Bind(&BluetoothSocketListenFunction::OnGetAdapter, this)); |
278 } | 279 } |
279 | 280 |
280 void BluetoothSocketListenFunction::OnGetAdapter( | 281 void BluetoothSocketListenFunction::OnGetAdapter( |
281 scoped_refptr<device::BluetoothAdapter> adapter) { | 282 scoped_refptr<device::BluetoothAdapter> adapter) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 | 442 |
442 BluetoothSocketAbstractConnectFunction:: | 443 BluetoothSocketAbstractConnectFunction:: |
443 ~BluetoothSocketAbstractConnectFunction() {} | 444 ~BluetoothSocketAbstractConnectFunction() {} |
444 | 445 |
445 bool BluetoothSocketAbstractConnectFunction::Prepare() { | 446 bool BluetoothSocketAbstractConnectFunction::Prepare() { |
446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
447 params_ = bluetooth_socket::Connect::Params::Create(*args_); | 448 params_ = bluetooth_socket::Connect::Params::Create(*args_); |
448 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 449 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
449 | 450 |
450 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); | 451 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); |
451 return socket_event_dispatcher_ != NULL; | 452 return socket_event_dispatcher_ != nullptr; |
452 } | 453 } |
453 | 454 |
454 void BluetoothSocketAbstractConnectFunction::AsyncWorkStart() { | 455 void BluetoothSocketAbstractConnectFunction::AsyncWorkStart() { |
455 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); | 456 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); |
456 device::BluetoothAdapterFactory::GetAdapter( | 457 device::BluetoothAdapterFactory::GetAdapter( |
457 base::Bind(&BluetoothSocketAbstractConnectFunction::OnGetAdapter, this)); | 458 base::Bind(&BluetoothSocketAbstractConnectFunction::OnGetAdapter, this)); |
458 } | 459 } |
459 | 460 |
460 void BluetoothSocketAbstractConnectFunction::OnGetAdapter( | 461 void BluetoothSocketAbstractConnectFunction::OnGetAdapter( |
461 scoped_refptr<device::BluetoothAdapter> adapter) { | 462 scoped_refptr<device::BluetoothAdapter> adapter) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 | 654 |
654 BluetoothSocketGetSocketsFunction::BluetoothSocketGetSocketsFunction() {} | 655 BluetoothSocketGetSocketsFunction::BluetoothSocketGetSocketsFunction() {} |
655 | 656 |
656 BluetoothSocketGetSocketsFunction::~BluetoothSocketGetSocketsFunction() {} | 657 BluetoothSocketGetSocketsFunction::~BluetoothSocketGetSocketsFunction() {} |
657 | 658 |
658 bool BluetoothSocketGetSocketsFunction::Prepare() { return true; } | 659 bool BluetoothSocketGetSocketsFunction::Prepare() { return true; } |
659 | 660 |
660 void BluetoothSocketGetSocketsFunction::Work() { | 661 void BluetoothSocketGetSocketsFunction::Work() { |
661 std::vector<linked_ptr<bluetooth_socket::SocketInfo> > socket_infos; | 662 std::vector<linked_ptr<bluetooth_socket::SocketInfo> > socket_infos; |
662 base::hash_set<int>* resource_ids = GetSocketIds(); | 663 base::hash_set<int>* resource_ids = GetSocketIds(); |
663 if (resource_ids != NULL) { | 664 if (resource_ids != nullptr) { |
664 for (base::hash_set<int>::iterator it = resource_ids->begin(); | 665 for (base::hash_set<int>::iterator it = resource_ids->begin(); |
665 it != resource_ids->end(); | 666 it != resource_ids->end(); |
666 ++it) { | 667 ++it) { |
667 int socket_id = *it; | 668 int socket_id = *it; |
668 BluetoothApiSocket* socket = GetSocket(socket_id); | 669 BluetoothApiSocket* socket = GetSocket(socket_id); |
669 if (socket) { | 670 if (socket) { |
670 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 671 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
671 } | 672 } |
672 } | 673 } |
673 } | 674 } |
674 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos); | 675 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos); |
675 } | 676 } |
676 | 677 |
677 } // namespace core_api | 678 } // namespace core_api |
678 } // namespace extensions | 679 } // namespace extensions |
OLD | NEW |