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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 176 |
177 base::hash_set<int>* BluetoothSocketAsyncApiFunction::GetSocketIds() { | 177 base::hash_set<int>* BluetoothSocketAsyncApiFunction::GetSocketIds() { |
178 return manager_->GetResourceIds(extension_id()); | 178 return manager_->GetResourceIds(extension_id()); |
179 } | 179 } |
180 | 180 |
181 BluetoothSocketCreateFunction::BluetoothSocketCreateFunction() {} | 181 BluetoothSocketCreateFunction::BluetoothSocketCreateFunction() {} |
182 | 182 |
183 BluetoothSocketCreateFunction::~BluetoothSocketCreateFunction() {} | 183 BluetoothSocketCreateFunction::~BluetoothSocketCreateFunction() {} |
184 | 184 |
185 bool BluetoothSocketCreateFunction::Prepare() { | 185 bool BluetoothSocketCreateFunction::Prepare() { |
186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 186 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
187 | 187 |
188 params_ = bluetooth_socket::Create::Params::Create(*args_); | 188 params_ = bluetooth_socket::Create::Params::Create(*args_); |
189 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 189 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
190 return true; | 190 return true; |
191 } | 191 } |
192 | 192 |
193 void BluetoothSocketCreateFunction::Work() { | 193 void BluetoothSocketCreateFunction::Work() { |
194 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); | 194 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); |
195 | 195 |
196 BluetoothApiSocket* socket = new BluetoothApiSocket(extension_id()); | 196 BluetoothApiSocket* socket = new BluetoothApiSocket(extension_id()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 257 } |
258 | 258 |
259 results_ = bluetooth_socket::SetPaused::Results::Create(); | 259 results_ = bluetooth_socket::SetPaused::Results::Create(); |
260 } | 260 } |
261 | 261 |
262 BluetoothSocketListenFunction::BluetoothSocketListenFunction() {} | 262 BluetoothSocketListenFunction::BluetoothSocketListenFunction() {} |
263 | 263 |
264 BluetoothSocketListenFunction::~BluetoothSocketListenFunction() {} | 264 BluetoothSocketListenFunction::~BluetoothSocketListenFunction() {} |
265 | 265 |
266 bool BluetoothSocketListenFunction::Prepare() { | 266 bool BluetoothSocketListenFunction::Prepare() { |
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 267 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
268 if (!CreateParams()) | 268 if (!CreateParams()) |
269 return false; | 269 return false; |
270 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); | 270 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); |
271 return socket_event_dispatcher_ != NULL; | 271 return socket_event_dispatcher_ != NULL; |
272 } | 272 } |
273 | 273 |
274 void BluetoothSocketListenFunction::AsyncWorkStart() { | 274 void BluetoothSocketListenFunction::AsyncWorkStart() { |
275 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); | 275 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); |
276 device::BluetoothAdapterFactory::GetAdapter( | 276 device::BluetoothAdapterFactory::GetAdapter( |
277 base::Bind(&BluetoothSocketListenFunction::OnGetAdapter, this)); | 277 base::Bind(&BluetoothSocketListenFunction::OnGetAdapter, this)); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 results_ = bluetooth_socket::ListenUsingL2cap::Results::Create(); | 436 results_ = bluetooth_socket::ListenUsingL2cap::Results::Create(); |
437 } | 437 } |
438 | 438 |
439 BluetoothSocketAbstractConnectFunction:: | 439 BluetoothSocketAbstractConnectFunction:: |
440 BluetoothSocketAbstractConnectFunction() {} | 440 BluetoothSocketAbstractConnectFunction() {} |
441 | 441 |
442 BluetoothSocketAbstractConnectFunction:: | 442 BluetoothSocketAbstractConnectFunction:: |
443 ~BluetoothSocketAbstractConnectFunction() {} | 443 ~BluetoothSocketAbstractConnectFunction() {} |
444 | 444 |
445 bool BluetoothSocketAbstractConnectFunction::Prepare() { | 445 bool BluetoothSocketAbstractConnectFunction::Prepare() { |
446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 446 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
447 params_ = bluetooth_socket::Connect::Params::Create(*args_); | 447 params_ = bluetooth_socket::Connect::Params::Create(*args_); |
448 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 448 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
449 | 449 |
450 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); | 450 socket_event_dispatcher_ = GetSocketEventDispatcher(browser_context()); |
451 return socket_event_dispatcher_ != NULL; | 451 return socket_event_dispatcher_ != NULL; |
452 } | 452 } |
453 | 453 |
454 void BluetoothSocketAbstractConnectFunction::AsyncWorkStart() { | 454 void BluetoothSocketAbstractConnectFunction::AsyncWorkStart() { |
455 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); | 455 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); |
456 device::BluetoothAdapterFactory::GetAdapter( | 456 device::BluetoothAdapterFactory::GetAdapter( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 uuid, | 533 uuid, |
534 base::Bind(&BluetoothSocketConnectFunction::OnConnect, this), | 534 base::Bind(&BluetoothSocketConnectFunction::OnConnect, this), |
535 base::Bind(&BluetoothSocketConnectFunction::OnConnectError, this)); | 535 base::Bind(&BluetoothSocketConnectFunction::OnConnectError, this)); |
536 } | 536 } |
537 | 537 |
538 BluetoothSocketDisconnectFunction::BluetoothSocketDisconnectFunction() {} | 538 BluetoothSocketDisconnectFunction::BluetoothSocketDisconnectFunction() {} |
539 | 539 |
540 BluetoothSocketDisconnectFunction::~BluetoothSocketDisconnectFunction() {} | 540 BluetoothSocketDisconnectFunction::~BluetoothSocketDisconnectFunction() {} |
541 | 541 |
542 bool BluetoothSocketDisconnectFunction::Prepare() { | 542 bool BluetoothSocketDisconnectFunction::Prepare() { |
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 543 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
544 params_ = bluetooth_socket::Disconnect::Params::Create(*args_); | 544 params_ = bluetooth_socket::Disconnect::Params::Create(*args_); |
545 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 545 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
546 return true; | 546 return true; |
547 } | 547 } |
548 | 548 |
549 void BluetoothSocketDisconnectFunction::AsyncWorkStart() { | 549 void BluetoothSocketDisconnectFunction::AsyncWorkStart() { |
550 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); | 550 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); |
551 BluetoothApiSocket* socket = GetSocket(params_->socket_id); | 551 BluetoothApiSocket* socket = GetSocket(params_->socket_id); |
552 if (!socket) { | 552 if (!socket) { |
553 error_ = kSocketNotFoundError; | 553 error_ = kSocketNotFoundError; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 RemoveSocket(params_->socket_id); | 585 RemoveSocket(params_->socket_id); |
586 results_ = bluetooth_socket::Close::Results::Create(); | 586 results_ = bluetooth_socket::Close::Results::Create(); |
587 } | 587 } |
588 | 588 |
589 BluetoothSocketSendFunction::BluetoothSocketSendFunction() | 589 BluetoothSocketSendFunction::BluetoothSocketSendFunction() |
590 : io_buffer_size_(0) {} | 590 : io_buffer_size_(0) {} |
591 | 591 |
592 BluetoothSocketSendFunction::~BluetoothSocketSendFunction() {} | 592 BluetoothSocketSendFunction::~BluetoothSocketSendFunction() {} |
593 | 593 |
594 bool BluetoothSocketSendFunction::Prepare() { | 594 bool BluetoothSocketSendFunction::Prepare() { |
595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 595 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
596 params_ = bluetooth_socket::Send::Params::Create(*args_); | 596 params_ = bluetooth_socket::Send::Params::Create(*args_); |
597 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 597 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
598 | 598 |
599 io_buffer_size_ = params_->data.size(); | 599 io_buffer_size_ = params_->data.size(); |
600 io_buffer_ = new net::WrappedIOBuffer(params_->data.data()); | 600 io_buffer_ = new net::WrappedIOBuffer(params_->data.data()); |
601 return true; | 601 return true; |
602 } | 602 } |
603 | 603 |
604 void BluetoothSocketSendFunction::AsyncWorkStart() { | 604 void BluetoothSocketSendFunction::AsyncWorkStart() { |
605 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); | 605 DCHECK(BrowserThread::CurrentlyOn(work_thread_id())); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 if (socket) { | 669 if (socket) { |
670 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 670 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
671 } | 671 } |
672 } | 672 } |
673 } | 673 } |
674 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos); | 674 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos); |
675 } | 675 } |
676 | 676 |
677 } // namespace core_api | 677 } // namespace core_api |
678 } // namespace extensions | 678 } // namespace extensions |
OLD | NEW |