| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 if (socket->IsConnected()) | 55 if (socket->IsConnected()) |
| 56 socket_info.address.reset(new std::string(socket->device_address())); | 56 socket_info.address.reset(new std::string(socket->device_address())); |
| 57 socket_info.uuid.reset(new std::string(socket->uuid().canonical_value())); | 57 socket_info.uuid.reset(new std::string(socket->uuid().canonical_value())); |
| 58 | 58 |
| 59 return socket_info; | 59 return socket_info; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void SetSocketProperties(BluetoothApiSocket* socket, | 62 void SetSocketProperties(BluetoothApiSocket* socket, |
| 63 SocketProperties* properties) { | 63 SocketProperties* properties) { |
| 64 if (properties->name.get()) { | 64 if (properties->name.get()) { |
| 65 socket->set_name(*properties->name.get()); | 65 socket->set_name(*properties->name); |
| 66 } | 66 } |
| 67 if (properties->persistent.get()) { | 67 if (properties->persistent.get()) { |
| 68 socket->set_persistent(*properties->persistent.get()); | 68 socket->set_persistent(*properties->persistent); |
| 69 } | 69 } |
| 70 if (properties->buffer_size.get()) { | 70 if (properties->buffer_size.get()) { |
| 71 // buffer size is validated when issuing the actual Recv operation | 71 // buffer size is validated when issuing the actual Recv operation |
| 72 // on the socket. | 72 // on the socket. |
| 73 socket->set_buffer_size(*properties->buffer_size.get()); | 73 socket->set_buffer_size(*properties->buffer_size); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 BluetoothSocketEventDispatcher* GetSocketEventDispatcher( | 77 BluetoothSocketEventDispatcher* GetSocketEventDispatcher( |
| 78 content::BrowserContext* browser_context) { | 78 content::BrowserContext* browser_context) { |
| 79 BluetoothSocketEventDispatcher* socket_event_dispatcher = | 79 BluetoothSocketEventDispatcher* socket_event_dispatcher = |
| 80 BluetoothSocketEventDispatcher::Get(browser_context); | 80 BluetoothSocketEventDispatcher::Get(browser_context); |
| 81 DCHECK(socket_event_dispatcher) | 81 DCHECK(socket_event_dispatcher) |
| 82 << "There is no socket event dispatcher. " | 82 << "There is no socket event dispatcher. " |
| 83 "If this assertion is failing during a test, then it is likely that " | 83 "If this assertion is failing during a test, then it is likely that " |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_CURRENTLY_ON(work_thread_id()); | 194 DCHECK_CURRENTLY_ON(work_thread_id()); |
| 195 | 195 |
| 196 BluetoothApiSocket* socket = new BluetoothApiSocket(extension_id()); | 196 BluetoothApiSocket* socket = new BluetoothApiSocket(extension_id()); |
| 197 | 197 |
| 198 bluetooth_socket::SocketProperties* properties = | 198 bluetooth_socket::SocketProperties* properties = params_->properties.get(); |
| 199 params_.get()->properties.get(); | |
| 200 if (properties) { | 199 if (properties) { |
| 201 SetSocketProperties(socket, properties); | 200 SetSocketProperties(socket, properties); |
| 202 } | 201 } |
| 203 | 202 |
| 204 bluetooth_socket::CreateInfo create_info; | 203 bluetooth_socket::CreateInfo create_info; |
| 205 create_info.socket_id = AddSocket(socket); | 204 create_info.socket_id = AddSocket(socket); |
| 206 results_ = bluetooth_socket::Create::Results::Create(create_info); | 205 results_ = bluetooth_socket::Create::Results::Create(create_info); |
| 207 // AsyncWorkCompleted is called by AsyncWorkStart(). | 206 // AsyncWorkCompleted is called by AsyncWorkStart(). |
| 208 } | 207 } |
| 209 | 208 |
| 210 BluetoothSocketUpdateFunction::BluetoothSocketUpdateFunction() {} | 209 BluetoothSocketUpdateFunction::BluetoothSocketUpdateFunction() {} |
| 211 | 210 |
| 212 BluetoothSocketUpdateFunction::~BluetoothSocketUpdateFunction() {} | 211 BluetoothSocketUpdateFunction::~BluetoothSocketUpdateFunction() {} |
| 213 | 212 |
| 214 bool BluetoothSocketUpdateFunction::Prepare() { | 213 bool BluetoothSocketUpdateFunction::Prepare() { |
| 215 params_ = bluetooth_socket::Update::Params::Create(*args_); | 214 params_ = bluetooth_socket::Update::Params::Create(*args_); |
| 216 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 215 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 217 return true; | 216 return true; |
| 218 } | 217 } |
| 219 | 218 |
| 220 void BluetoothSocketUpdateFunction::Work() { | 219 void BluetoothSocketUpdateFunction::Work() { |
| 221 BluetoothApiSocket* socket = GetSocket(params_->socket_id); | 220 BluetoothApiSocket* socket = GetSocket(params_->socket_id); |
| 222 if (!socket) { | 221 if (!socket) { |
| 223 error_ = kSocketNotFoundError; | 222 error_ = kSocketNotFoundError; |
| 224 return; | 223 return; |
| 225 } | 224 } |
| 226 | 225 |
| 227 SetSocketProperties(socket, ¶ms_.get()->properties); | 226 SetSocketProperties(socket, ¶ms_->properties); |
| 228 results_ = bluetooth_socket::Update::Results::Create(); | 227 results_ = bluetooth_socket::Update::Results::Create(); |
| 229 } | 228 } |
| 230 | 229 |
| 231 BluetoothSocketSetPausedFunction::BluetoothSocketSetPausedFunction() | 230 BluetoothSocketSetPausedFunction::BluetoothSocketSetPausedFunction() |
| 232 : socket_event_dispatcher_(NULL) {} | 231 : socket_event_dispatcher_(NULL) {} |
| 233 | 232 |
| 234 BluetoothSocketSetPausedFunction::~BluetoothSocketSetPausedFunction() {} | 233 BluetoothSocketSetPausedFunction::~BluetoothSocketSetPausedFunction() {} |
| 235 | 234 |
| 236 bool BluetoothSocketSetPausedFunction::Prepare() { | 235 bool BluetoothSocketSetPausedFunction::Prepare() { |
| 237 params_ = bluetooth_socket::SetPaused::Params::Create(*args_); | 236 params_ = bluetooth_socket::SetPaused::Params::Create(*args_); |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 if (socket) { | 662 if (socket) { |
| 664 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 663 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
| 665 } | 664 } |
| 666 } | 665 } |
| 667 } | 666 } |
| 668 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos); | 667 results_ = bluetooth_socket::GetSockets::Results::Create(socket_infos); |
| 669 } | 668 } |
| 670 | 669 |
| 671 } // namespace api | 670 } // namespace api |
| 672 } // namespace extensions | 671 } // namespace extensions |
| OLD | NEW |