| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sockets_tcp/sockets_tcp_api.h" | 5 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/socket/tcp_socket.h" | |
| 8 #include "chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.
h" | |
| 9 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" | 7 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" |
| 10 #include "content/public/common/socket_permission_request.h" | 8 #include "content/public/common/socket_permission_request.h" |
| 9 #include "extensions/browser/api/socket/tcp_socket.h" |
| 10 #include "extensions/browser/api/sockets_tcp/tcp_socket_event_dispatcher.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 | 12 |
| 13 using extensions::ResumableTCPSocket; | 13 using extensions::ResumableTCPSocket; |
| 14 using extensions::api::sockets_tcp::SocketInfo; | 14 using extensions::core_api::sockets_tcp::SocketInfo; |
| 15 using extensions::api::sockets_tcp::SocketProperties; | 15 using extensions::core_api::sockets_tcp::SocketProperties; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kSocketNotFoundError[] = "Socket not found"; | 19 const char kSocketNotFoundError[] = "Socket not found"; |
| 20 const char kPermissionError[] = "Does not have permission"; | 20 const char kPermissionError[] = "Does not have permission"; |
| 21 | 21 |
| 22 linked_ptr<SocketInfo> CreateSocketInfo(int socket_id, | 22 linked_ptr<SocketInfo> CreateSocketInfo(int socket_id, |
| 23 ResumableTCPSocket* socket) { | 23 ResumableTCPSocket* socket) { |
| 24 linked_ptr<SocketInfo> socket_info(new SocketInfo()); | 24 linked_ptr<SocketInfo> socket_info(new SocketInfo()); |
| 25 // This represents what we know about the socket, and does not call through | 25 // This represents what we know about the socket, and does not call through |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (properties->buffer_size.get()) { | 68 if (properties->buffer_size.get()) { |
| 69 // buffer size is validated when issuing the actual Recv operation | 69 // buffer size is validated when issuing the actual Recv operation |
| 70 // on the socket. | 70 // on the socket. |
| 71 socket->set_buffer_size(*properties->buffer_size.get()); | 71 socket->set_buffer_size(*properties->buffer_size.get()); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 namespace extensions { | 77 namespace extensions { |
| 78 namespace api { | 78 namespace core_api { |
| 79 | 79 |
| 80 using content::SocketPermissionRequest; | 80 using content::SocketPermissionRequest; |
| 81 | 81 |
| 82 TCPSocketAsyncApiFunction::~TCPSocketAsyncApiFunction() {} | 82 TCPSocketAsyncApiFunction::~TCPSocketAsyncApiFunction() {} |
| 83 | 83 |
| 84 scoped_ptr<SocketResourceManagerInterface> | 84 scoped_ptr<SocketResourceManagerInterface> |
| 85 TCPSocketAsyncApiFunction::CreateSocketResourceManager() { | 85 TCPSocketAsyncApiFunction::CreateSocketResourceManager() { |
| 86 return scoped_ptr<SocketResourceManagerInterface>( | 86 return scoped_ptr<SocketResourceManagerInterface>( |
| 87 new SocketResourceManager<ResumableTCPSocket>()).Pass(); | 87 new SocketResourceManager<ResumableTCPSocket>()).Pass(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 ResumableTCPSocket* TCPSocketAsyncApiFunction::GetTcpSocket(int socket_id) { | 90 ResumableTCPSocket* TCPSocketAsyncApiFunction::GetTcpSocket(int socket_id) { |
| 91 return static_cast<ResumableTCPSocket*>(GetSocket(socket_id)); | 91 return static_cast<ResumableTCPSocket*>(GetSocket(socket_id)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TCPSocketExtensionWithDnsLookupFunction:: | 94 TCPSocketExtensionWithDnsLookupFunction:: |
| 95 ~TCPSocketExtensionWithDnsLookupFunction() {} | 95 ~TCPSocketExtensionWithDnsLookupFunction() {} |
| 96 | 96 |
| 97 scoped_ptr<SocketResourceManagerInterface> | 97 scoped_ptr<SocketResourceManagerInterface> |
| 98 TCPSocketExtensionWithDnsLookupFunction::CreateSocketResourceManager() { | 98 TCPSocketExtensionWithDnsLookupFunction::CreateSocketResourceManager() { |
| 99 return scoped_ptr<SocketResourceManagerInterface>( | 99 return scoped_ptr<SocketResourceManagerInterface>( |
| 100 new SocketResourceManager<ResumableTCPSocket>()).Pass(); | 100 new SocketResourceManager<ResumableTCPSocket>()).Pass(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 ResumableTCPSocket* TCPSocketExtensionWithDnsLookupFunction::GetTcpSocket( | 103 ResumableTCPSocket* TCPSocketExtensionWithDnsLookupFunction::GetTcpSocket( |
| 104 int socket_id) { | 104 int socket_id) { |
| 105 return static_cast<ResumableTCPSocket*>(GetSocket(socket_id)); | 105 return static_cast<ResumableTCPSocket*>(GetSocket(socket_id)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 SocketsTcpCreateFunction::SocketsTcpCreateFunction() {} | 108 SocketsTcpCreateFunction::SocketsTcpCreateFunction() {} |
| 109 | 109 |
| 110 SocketsTcpCreateFunction::~SocketsTcpCreateFunction() {} | 110 SocketsTcpCreateFunction::~SocketsTcpCreateFunction() {} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 SetSocketProperties(socket, ¶ms_.get()->properties); | 148 SetSocketProperties(socket, ¶ms_.get()->properties); |
| 149 results_ = sockets_tcp::Update::Results::Create(); | 149 results_ = sockets_tcp::Update::Results::Create(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() | 152 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() |
| 153 : socket_event_dispatcher_(NULL) {} | 153 : socket_event_dispatcher_(NULL) {} |
| 154 | 154 |
| 155 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} | 155 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} |
| 156 | 156 |
| 157 bool SocketsTcpSetPausedFunction::Prepare() { | 157 bool SocketsTcpSetPausedFunction::Prepare() { |
| 158 params_ = api::sockets_tcp::SetPaused::Params::Create(*args_); | 158 params_ = core_api::sockets_tcp::SetPaused::Params::Create(*args_); |
| 159 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 159 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 160 | 160 |
| 161 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); | 161 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); |
| 162 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " | 162 DCHECK(socket_event_dispatcher_) |
| 163 "If this assertion is failing during a test, then it is likely that " | 163 << "There is no socket event dispatcher. " |
| 164 "TestExtensionSystem is failing to provide an instance of " | 164 "If this assertion is failing during a test, then it is likely that " |
| 165 "TCPSocketEventDispatcher."; | 165 "TestExtensionSystem is failing to provide an instance of " |
| 166 "TCPSocketEventDispatcher."; |
| 166 return socket_event_dispatcher_ != NULL; | 167 return socket_event_dispatcher_ != NULL; |
| 167 } | 168 } |
| 168 | 169 |
| 169 void SocketsTcpSetPausedFunction::Work() { | 170 void SocketsTcpSetPausedFunction::Work() { |
| 170 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 171 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 171 if (!socket) { | 172 if (!socket) { |
| 172 error_ = kSocketNotFoundError; | 173 error_ = kSocketNotFoundError; |
| 173 return; | 174 return; |
| 174 } | 175 } |
| 175 | 176 |
| 176 if (socket->paused() != params_->paused) { | 177 if (socket->paused() != params_->paused) { |
| 177 socket->set_paused(params_->paused); | 178 socket->set_paused(params_->paused); |
| 178 if (socket->IsConnected() && !params_->paused) { | 179 if (socket->IsConnected() && !params_->paused) { |
| 179 socket_event_dispatcher_->OnSocketResume(extension_->id(), | 180 socket_event_dispatcher_->OnSocketResume(extension_->id(), |
| 180 params_->socket_id); | 181 params_->socket_id); |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 | 184 |
| 184 results_ = sockets_tcp::SetPaused::Results::Create(); | 185 results_ = sockets_tcp::SetPaused::Results::Create(); |
| 185 } | 186 } |
| 186 | 187 |
| 187 SocketsTcpSetKeepAliveFunction::SocketsTcpSetKeepAliveFunction() {} | 188 SocketsTcpSetKeepAliveFunction::SocketsTcpSetKeepAliveFunction() {} |
| 188 | 189 |
| 189 SocketsTcpSetKeepAliveFunction::~SocketsTcpSetKeepAliveFunction() {} | 190 SocketsTcpSetKeepAliveFunction::~SocketsTcpSetKeepAliveFunction() {} |
| 190 | 191 |
| 191 bool SocketsTcpSetKeepAliveFunction::Prepare() { | 192 bool SocketsTcpSetKeepAliveFunction::Prepare() { |
| 192 params_ = api::sockets_tcp::SetKeepAlive::Params::Create(*args_); | 193 params_ = core_api::sockets_tcp::SetKeepAlive::Params::Create(*args_); |
| 193 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 194 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 194 return true; | 195 return true; |
| 195 } | 196 } |
| 196 | 197 |
| 197 void SocketsTcpSetKeepAliveFunction::Work() { | 198 void SocketsTcpSetKeepAliveFunction::Work() { |
| 198 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 199 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 199 if (!socket) { | 200 if (!socket) { |
| 200 error_ = kSocketNotFoundError; | 201 error_ = kSocketNotFoundError; |
| 201 return; | 202 return; |
| 202 } | 203 } |
| 203 | 204 |
| 204 int delay = params_->delay ? *params_->delay.get() : 0; | 205 int delay = params_->delay ? *params_->delay.get() : 0; |
| 205 | 206 |
| 206 bool success = socket->SetKeepAlive(params_->enable, delay); | 207 bool success = socket->SetKeepAlive(params_->enable, delay); |
| 207 int net_result = (success ? net::OK : net::ERR_FAILED); | 208 int net_result = (success ? net::OK : net::ERR_FAILED); |
| 208 if (net_result != net::OK) | 209 if (net_result != net::OK) |
| 209 error_ = net::ErrorToString(net_result); | 210 error_ = net::ErrorToString(net_result); |
| 210 results_ = sockets_tcp::SetKeepAlive::Results::Create(net_result); | 211 results_ = sockets_tcp::SetKeepAlive::Results::Create(net_result); |
| 211 } | 212 } |
| 212 | 213 |
| 213 SocketsTcpSetNoDelayFunction::SocketsTcpSetNoDelayFunction() {} | 214 SocketsTcpSetNoDelayFunction::SocketsTcpSetNoDelayFunction() {} |
| 214 | 215 |
| 215 SocketsTcpSetNoDelayFunction::~SocketsTcpSetNoDelayFunction() {} | 216 SocketsTcpSetNoDelayFunction::~SocketsTcpSetNoDelayFunction() {} |
| 216 | 217 |
| 217 bool SocketsTcpSetNoDelayFunction::Prepare() { | 218 bool SocketsTcpSetNoDelayFunction::Prepare() { |
| 218 params_ = api::sockets_tcp::SetNoDelay::Params::Create(*args_); | 219 params_ = core_api::sockets_tcp::SetNoDelay::Params::Create(*args_); |
| 219 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 220 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 220 return true; | 221 return true; |
| 221 } | 222 } |
| 222 | 223 |
| 223 void SocketsTcpSetNoDelayFunction::Work() { | 224 void SocketsTcpSetNoDelayFunction::Work() { |
| 224 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 225 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 225 if (!socket) { | 226 if (!socket) { |
| 226 error_ = kSocketNotFoundError; | 227 error_ = kSocketNotFoundError; |
| 227 return; | 228 return; |
| 228 } | 229 } |
| 229 | 230 |
| 230 bool success = socket->SetNoDelay(params_->no_delay); | 231 bool success = socket->SetNoDelay(params_->no_delay); |
| 231 int net_result = (success ? net::OK : net::ERR_FAILED); | 232 int net_result = (success ? net::OK : net::ERR_FAILED); |
| 232 if (net_result != net::OK) | 233 if (net_result != net::OK) |
| 233 error_ = net::ErrorToString(net_result); | 234 error_ = net::ErrorToString(net_result); |
| 234 results_ = sockets_tcp::SetNoDelay::Results::Create(net_result); | 235 results_ = sockets_tcp::SetNoDelay::Results::Create(net_result); |
| 235 } | 236 } |
| 236 | 237 |
| 237 SocketsTcpConnectFunction::SocketsTcpConnectFunction() | 238 SocketsTcpConnectFunction::SocketsTcpConnectFunction() |
| 238 : socket_event_dispatcher_(NULL) {} | 239 : socket_event_dispatcher_(NULL) {} |
| 239 | 240 |
| 240 SocketsTcpConnectFunction::~SocketsTcpConnectFunction() {} | 241 SocketsTcpConnectFunction::~SocketsTcpConnectFunction() {} |
| 241 | 242 |
| 242 bool SocketsTcpConnectFunction::Prepare() { | 243 bool SocketsTcpConnectFunction::Prepare() { |
| 243 params_ = sockets_tcp::Connect::Params::Create(*args_); | 244 params_ = sockets_tcp::Connect::Params::Create(*args_); |
| 244 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 245 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 245 | 246 |
| 246 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); | 247 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); |
| 247 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " | 248 DCHECK(socket_event_dispatcher_) |
| 248 "If this assertion is failing during a test, then it is likely that " | 249 << "There is no socket event dispatcher. " |
| 249 "TestExtensionSystem is failing to provide an instance of " | 250 "If this assertion is failing during a test, then it is likely that " |
| 250 "TCPSocketEventDispatcher."; | 251 "TestExtensionSystem is failing to provide an instance of " |
| 252 "TCPSocketEventDispatcher."; |
| 251 return socket_event_dispatcher_ != NULL; | 253 return socket_event_dispatcher_ != NULL; |
| 252 } | 254 } |
| 253 | 255 |
| 254 void SocketsTcpConnectFunction::AsyncWorkStart() { | 256 void SocketsTcpConnectFunction::AsyncWorkStart() { |
| 255 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 257 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 256 if (!socket) { | 258 if (!socket) { |
| 257 error_ = kSocketNotFoundError; | 259 error_ = kSocketNotFoundError; |
| 258 AsyncWorkCompleted(); | 260 AsyncWorkCompleted(); |
| 259 return; | 261 return; |
| 260 } | 262 } |
| 261 | 263 |
| 262 content::SocketPermissionRequest param( | 264 content::SocketPermissionRequest param(SocketPermissionRequest::TCP_CONNECT, |
| 263 SocketPermissionRequest::TCP_CONNECT, | 265 params_->peer_address, |
| 264 params_->peer_address, | 266 params_->peer_port); |
| 265 params_->peer_port); | |
| 266 if (!SocketsManifestData::CheckRequest(GetExtension(), param)) { | 267 if (!SocketsManifestData::CheckRequest(GetExtension(), param)) { |
| 267 error_ = kPermissionError; | 268 error_ = kPermissionError; |
| 268 AsyncWorkCompleted(); | 269 AsyncWorkCompleted(); |
| 269 return; | 270 return; |
| 270 } | 271 } |
| 271 | 272 |
| 272 StartDnsLookup(params_->peer_address); | 273 StartDnsLookup(params_->peer_address); |
| 273 } | 274 } |
| 274 | 275 |
| 275 void SocketsTcpConnectFunction::AfterDnsLookup(int lookup_result) { | 276 void SocketsTcpConnectFunction::AfterDnsLookup(int lookup_result) { |
| 276 if (lookup_result == net::OK) { | 277 if (lookup_result == net::OK) { |
| 277 StartConnect(); | 278 StartConnect(); |
| 278 } else { | 279 } else { |
| 279 OnCompleted(lookup_result); | 280 OnCompleted(lookup_result); |
| 280 } | 281 } |
| 281 } | 282 } |
| 282 | 283 |
| 283 void SocketsTcpConnectFunction::StartConnect() { | 284 void SocketsTcpConnectFunction::StartConnect() { |
| 284 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 285 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 285 if (!socket) { | 286 if (!socket) { |
| 286 error_ = kSocketNotFoundError; | 287 error_ = kSocketNotFoundError; |
| 287 AsyncWorkCompleted(); | 288 AsyncWorkCompleted(); |
| 288 return; | 289 return; |
| 289 } | 290 } |
| 290 | 291 |
| 291 socket->Connect(resolved_address_, params_->peer_port, | 292 socket->Connect(resolved_address_, |
| 293 params_->peer_port, |
| 292 base::Bind(&SocketsTcpConnectFunction::OnCompleted, this)); | 294 base::Bind(&SocketsTcpConnectFunction::OnCompleted, this)); |
| 293 } | 295 } |
| 294 | 296 |
| 295 void SocketsTcpConnectFunction::OnCompleted(int net_result) { | 297 void SocketsTcpConnectFunction::OnCompleted(int net_result) { |
| 296 if (net_result == net::OK) { | 298 if (net_result == net::OK) { |
| 297 socket_event_dispatcher_->OnSocketConnect(extension_->id(), | 299 socket_event_dispatcher_->OnSocketConnect(extension_->id(), |
| 298 params_->socket_id); | 300 params_->socket_id); |
| 299 } | 301 } |
| 300 | 302 |
| 301 if (net_result != net::OK) | 303 if (net_result != net::OK) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 318 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 320 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 319 if (!socket) { | 321 if (!socket) { |
| 320 error_ = kSocketNotFoundError; | 322 error_ = kSocketNotFoundError; |
| 321 return; | 323 return; |
| 322 } | 324 } |
| 323 | 325 |
| 324 socket->Disconnect(); | 326 socket->Disconnect(); |
| 325 results_ = sockets_tcp::Disconnect::Results::Create(); | 327 results_ = sockets_tcp::Disconnect::Results::Create(); |
| 326 } | 328 } |
| 327 | 329 |
| 328 SocketsTcpSendFunction::SocketsTcpSendFunction() | 330 SocketsTcpSendFunction::SocketsTcpSendFunction() : io_buffer_size_(0) {} |
| 329 : io_buffer_size_(0) {} | |
| 330 | 331 |
| 331 SocketsTcpSendFunction::~SocketsTcpSendFunction() {} | 332 SocketsTcpSendFunction::~SocketsTcpSendFunction() {} |
| 332 | 333 |
| 333 bool SocketsTcpSendFunction::Prepare() { | 334 bool SocketsTcpSendFunction::Prepare() { |
| 334 params_ = sockets_tcp::Send::Params::Create(*args_); | 335 params_ = sockets_tcp::Send::Params::Create(*args_); |
| 335 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 336 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 336 io_buffer_size_ = params_->data.size(); | 337 io_buffer_size_ = params_->data.size(); |
| 337 io_buffer_ = new net::WrappedIOBuffer(params_->data.data()); | 338 io_buffer_ = new net::WrappedIOBuffer(params_->data.data()); |
| 338 return true; | 339 return true; |
| 339 } | 340 } |
| 340 | 341 |
| 341 void SocketsTcpSendFunction::AsyncWorkStart() { | 342 void SocketsTcpSendFunction::AsyncWorkStart() { |
| 342 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 343 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 343 if (!socket) { | 344 if (!socket) { |
| 344 error_ = kSocketNotFoundError; | 345 error_ = kSocketNotFoundError; |
| 345 AsyncWorkCompleted(); | 346 AsyncWorkCompleted(); |
| 346 return; | 347 return; |
| 347 } | 348 } |
| 348 | 349 |
| 349 socket->Write(io_buffer_, io_buffer_size_, | 350 socket->Write(io_buffer_, |
| 351 io_buffer_size_, |
| 350 base::Bind(&SocketsTcpSendFunction::OnCompleted, this)); | 352 base::Bind(&SocketsTcpSendFunction::OnCompleted, this)); |
| 351 } | 353 } |
| 352 | 354 |
| 353 void SocketsTcpSendFunction::OnCompleted(int net_result) { | 355 void SocketsTcpSendFunction::OnCompleted(int net_result) { |
| 354 if (net_result >= net::OK) { | 356 if (net_result >= net::OK) { |
| 355 SetSendResult(net::OK, net_result); | 357 SetSendResult(net::OK, net_result); |
| 356 } else { | 358 } else { |
| 357 SetSendResult(net_result, -1); | 359 SetSendResult(net_result, -1); |
| 358 } | 360 } |
| 359 } | 361 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 415 |
| 414 linked_ptr<sockets_tcp::SocketInfo> socket_info = | 416 linked_ptr<sockets_tcp::SocketInfo> socket_info = |
| 415 CreateSocketInfo(params_->socket_id, socket); | 417 CreateSocketInfo(params_->socket_id, socket); |
| 416 results_ = sockets_tcp::GetInfo::Results::Create(*socket_info); | 418 results_ = sockets_tcp::GetInfo::Results::Create(*socket_info); |
| 417 } | 419 } |
| 418 | 420 |
| 419 SocketsTcpGetSocketsFunction::SocketsTcpGetSocketsFunction() {} | 421 SocketsTcpGetSocketsFunction::SocketsTcpGetSocketsFunction() {} |
| 420 | 422 |
| 421 SocketsTcpGetSocketsFunction::~SocketsTcpGetSocketsFunction() {} | 423 SocketsTcpGetSocketsFunction::~SocketsTcpGetSocketsFunction() {} |
| 422 | 424 |
| 423 bool SocketsTcpGetSocketsFunction::Prepare() { | 425 bool SocketsTcpGetSocketsFunction::Prepare() { return true; } |
| 424 return true; | |
| 425 } | |
| 426 | 426 |
| 427 void SocketsTcpGetSocketsFunction::Work() { | 427 void SocketsTcpGetSocketsFunction::Work() { |
| 428 std::vector<linked_ptr<sockets_tcp::SocketInfo> > socket_infos; | 428 std::vector<linked_ptr<sockets_tcp::SocketInfo> > socket_infos; |
| 429 base::hash_set<int>* resource_ids = GetSocketIds(); | 429 base::hash_set<int>* resource_ids = GetSocketIds(); |
| 430 if (resource_ids != NULL) { | 430 if (resource_ids != NULL) { |
| 431 for (base::hash_set<int>::iterator it = resource_ids->begin(); | 431 for (base::hash_set<int>::iterator it = resource_ids->begin(); |
| 432 it != resource_ids->end(); ++it) { | 432 it != resource_ids->end(); |
| 433 ++it) { |
| 433 int socket_id = *it; | 434 int socket_id = *it; |
| 434 ResumableTCPSocket* socket = GetTcpSocket(socket_id); | 435 ResumableTCPSocket* socket = GetTcpSocket(socket_id); |
| 435 if (socket) { | 436 if (socket) { |
| 436 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 437 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
| 437 } | 438 } |
| 438 } | 439 } |
| 439 } | 440 } |
| 440 results_ = sockets_tcp::GetSockets::Results::Create(socket_infos); | 441 results_ = sockets_tcp::GetSockets::Results::Create(socket_infos); |
| 441 } | 442 } |
| 442 | 443 |
| 443 } // namespace api | 444 } // namespace core_api |
| 444 } // namespace extensions | 445 } // namespace extensions |
| OLD | NEW |