| OLD | NEW |
| 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/socket/socket_api.h" | 5 #include "chrome/browser/extensions/api/socket/socket_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h" | 9 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h" |
| 10 #include "chrome/browser/extensions/api/socket/socket.h" | 10 #include "chrome/browser/extensions/api/socket/socket.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 SocketCreateFunction::SocketCreateFunction() | 94 SocketCreateFunction::SocketCreateFunction() |
| 95 : socket_type_(kSocketTypeInvalid), | 95 : socket_type_(kSocketTypeInvalid), |
| 96 src_id_(-1), | 96 src_id_(-1), |
| 97 event_notifier_(NULL) { | 97 event_notifier_(NULL) { |
| 98 } | 98 } |
| 99 | 99 |
| 100 SocketCreateFunction::~SocketCreateFunction() {} | 100 SocketCreateFunction::~SocketCreateFunction() {} |
| 101 | 101 |
| 102 bool SocketCreateFunction::Prepare() { | 102 bool SocketCreateFunction::Prepare() { |
| 103 params_ = api::experimental_socket::Create::Params::Create(*args_); | 103 params_ = api::socket::Create::Params::Create(*args_); |
| 104 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 104 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 105 | 105 |
| 106 if (params_->type == kTCPOption) { | 106 if (params_->type == kTCPOption) { |
| 107 socket_type_ = kSocketTypeTCP; | 107 socket_type_ = kSocketTypeTCP; |
| 108 } else if (params_->type == kUDPOption) { | 108 } else if (params_->type == kUDPOption) { |
| 109 socket_type_ = kSocketTypeUDP; | 109 socket_type_ = kSocketTypeUDP; |
| 110 } else { | 110 } else { |
| 111 error_ = kSocketTypeInvalidError; | 111 error_ = kSocketTypeInvalidError; |
| 112 return false; | 112 return false; |
| 113 } | 113 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 SetResult(Value::CreateIntegerValue(result)); | 220 SetResult(Value::CreateIntegerValue(result)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 SocketReadFunction::SocketReadFunction() | 223 SocketReadFunction::SocketReadFunction() |
| 224 : params_(NULL) { | 224 : params_(NULL) { |
| 225 } | 225 } |
| 226 | 226 |
| 227 SocketReadFunction::~SocketReadFunction() {} | 227 SocketReadFunction::~SocketReadFunction() {} |
| 228 | 228 |
| 229 bool SocketReadFunction::Prepare() { | 229 bool SocketReadFunction::Prepare() { |
| 230 params_ = api::experimental_socket::Read::Params::Create(*args_); | 230 params_ = api::socket::Read::Params::Create(*args_); |
| 231 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 231 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 232 return true; | 232 return true; |
| 233 } | 233 } |
| 234 | 234 |
| 235 void SocketReadFunction::AsyncWorkStart() { | 235 void SocketReadFunction::AsyncWorkStart() { |
| 236 Socket* socket = manager_->Get(params_->socket_id); | 236 Socket* socket = manager_->Get(params_->socket_id); |
| 237 if (!socket) { | 237 if (!socket) { |
| 238 error_ = kSocketNotFoundError; | 238 error_ = kSocketNotFoundError; |
| 239 OnCompleted(-1, NULL); | 239 OnCompleted(-1, NULL); |
| 240 return; | 240 return; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 AsyncWorkCompleted(); | 301 AsyncWorkCompleted(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 SocketRecvFromFunction::SocketRecvFromFunction() | 304 SocketRecvFromFunction::SocketRecvFromFunction() |
| 305 : params_(NULL) { | 305 : params_(NULL) { |
| 306 } | 306 } |
| 307 | 307 |
| 308 SocketRecvFromFunction::~SocketRecvFromFunction() {} | 308 SocketRecvFromFunction::~SocketRecvFromFunction() {} |
| 309 | 309 |
| 310 bool SocketRecvFromFunction::Prepare() { | 310 bool SocketRecvFromFunction::Prepare() { |
| 311 params_ = api::experimental_socket::RecvFrom::Params::Create(*args_); | 311 params_ = api::socket::RecvFrom::Params::Create(*args_); |
| 312 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 312 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 313 return true; | 313 return true; |
| 314 } | 314 } |
| 315 | 315 |
| 316 void SocketRecvFromFunction::AsyncWorkStart() { | 316 void SocketRecvFromFunction::AsyncWorkStart() { |
| 317 Socket* socket = manager_->Get(params_->socket_id); | 317 Socket* socket = manager_->Get(params_->socket_id); |
| 318 if (!socket) { | 318 if (!socket) { |
| 319 error_ = kSocketNotFoundError; | 319 error_ = kSocketNotFoundError; |
| 320 OnCompleted(-1, NULL, std::string(), 0); | 320 OnCompleted(-1, NULL, std::string(), 0); |
| 321 return; | 321 return; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 AsyncWorkCompleted(); | 401 AsyncWorkCompleted(); |
| 402 } | 402 } |
| 403 | 403 |
| 404 SocketSetKeepAliveFunction::SocketSetKeepAliveFunction() | 404 SocketSetKeepAliveFunction::SocketSetKeepAliveFunction() |
| 405 : params_(NULL) { | 405 : params_(NULL) { |
| 406 } | 406 } |
| 407 | 407 |
| 408 SocketSetKeepAliveFunction::~SocketSetKeepAliveFunction() {} | 408 SocketSetKeepAliveFunction::~SocketSetKeepAliveFunction() {} |
| 409 | 409 |
| 410 bool SocketSetKeepAliveFunction::Prepare() { | 410 bool SocketSetKeepAliveFunction::Prepare() { |
| 411 params_ = api::experimental_socket::SetKeepAlive::Params::Create(*args_); | 411 params_ = api::socket::SetKeepAlive::Params::Create(*args_); |
| 412 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 412 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 413 return true; | 413 return true; |
| 414 } | 414 } |
| 415 | 415 |
| 416 void SocketSetKeepAliveFunction::Work() { | 416 void SocketSetKeepAliveFunction::Work() { |
| 417 bool result = false; | 417 bool result = false; |
| 418 Socket* socket = manager_->Get(params_->socket_id); | 418 Socket* socket = manager_->Get(params_->socket_id); |
| 419 if (socket) { | 419 if (socket) { |
| 420 int delay = 0; | 420 int delay = 0; |
| 421 if (params_->delay.get()) | 421 if (params_->delay.get()) |
| 422 delay = *params_->delay; | 422 delay = *params_->delay; |
| 423 result = socket->SetKeepAlive(params_->enable, delay); | 423 result = socket->SetKeepAlive(params_->enable, delay); |
| 424 } else { | 424 } else { |
| 425 error_ = kSocketNotFoundError; | 425 error_ = kSocketNotFoundError; |
| 426 } | 426 } |
| 427 SetResult(Value::CreateBooleanValue(result)); | 427 SetResult(Value::CreateBooleanValue(result)); |
| 428 } | 428 } |
| 429 | 429 |
| 430 SocketSetNoDelayFunction::SocketSetNoDelayFunction() | 430 SocketSetNoDelayFunction::SocketSetNoDelayFunction() |
| 431 : params_(NULL) { | 431 : params_(NULL) { |
| 432 } | 432 } |
| 433 | 433 |
| 434 SocketSetNoDelayFunction::~SocketSetNoDelayFunction() {} | 434 SocketSetNoDelayFunction::~SocketSetNoDelayFunction() {} |
| 435 | 435 |
| 436 bool SocketSetNoDelayFunction::Prepare() { | 436 bool SocketSetNoDelayFunction::Prepare() { |
| 437 params_ = api::experimental_socket::SetNoDelay::Params::Create(*args_); | 437 params_ = api::socket::SetNoDelay::Params::Create(*args_); |
| 438 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 438 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 439 return true; | 439 return true; |
| 440 } | 440 } |
| 441 | 441 |
| 442 void SocketSetNoDelayFunction::Work() { | 442 void SocketSetNoDelayFunction::Work() { |
| 443 bool result = false; | 443 bool result = false; |
| 444 Socket* socket = manager_->Get(params_->socket_id); | 444 Socket* socket = manager_->Get(params_->socket_id); |
| 445 if (socket) | 445 if (socket) |
| 446 result = socket->SetNoDelay(params_->no_delay); | 446 result = socket->SetNoDelay(params_->no_delay); |
| 447 else | 447 else |
| 448 error_ = kSocketNotFoundError; | 448 error_ = kSocketNotFoundError; |
| 449 SetResult(Value::CreateBooleanValue(result)); | 449 SetResult(Value::CreateBooleanValue(result)); |
| 450 } | 450 } |
| 451 | 451 |
| 452 } // namespace extensions | 452 } // namespace extensions |
| OLD | NEW |