| Index: chrome/browser/extensions/api/socket/socket_api.cc
|
| diff --git a/chrome/browser/extensions/api/socket/socket_api.cc b/chrome/browser/extensions/api/socket/socket_api.cc
|
| index 2299491e54f8c97109e946be582dcd7992c2326f..468ed58c9fa37c1804a4cc716a5559ea66f4d47d 100644
|
| --- a/chrome/browser/extensions/api/socket/socket_api.cc
|
| +++ b/chrome/browser/extensions/api/socket/socket_api.cc
|
| @@ -265,6 +265,67 @@ void SocketBindFunction::Work() {
|
| SetResult(Value::CreateIntegerValue(result));
|
| }
|
|
|
| +SocketListenFunction::SocketListenFunction()
|
| + : params_(NULL) {
|
| +}
|
| +
|
| +SocketListenFunction::~SocketListenFunction() {}
|
| +
|
| +bool SocketListenFunction::Prepare() {
|
| + params_ = api::socket::Listen::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_.get());
|
| + return true;
|
| +}
|
| +
|
| +void SocketListenFunction::Work() {
|
| + int result = -1;
|
| + Socket* socket = manager_->Get(params_->socket_id);
|
| + if (socket) {
|
| + result = socket->Listen(params_->backlog, error_);
|
| + } else {
|
| + error_ = kSocketNotFoundError;
|
| + }
|
| +
|
| + SetResult(Value::CreateIntegerValue(result));
|
| +}
|
| +
|
| +SocketAcceptFunction::SocketAcceptFunction()
|
| + : params_(NULL) {
|
| +}
|
| +
|
| +SocketAcceptFunction::~SocketAcceptFunction() {}
|
| +
|
| +bool SocketAcceptFunction::Prepare() {
|
| + params_ = api::socket::Accept::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_.get());
|
| + return true;
|
| +}
|
| +
|
| +void SocketAcceptFunction::AsyncWorkStart() {
|
| + Socket* socket = manager_->Get(params_->socket_id);
|
| + if (socket) {
|
| + socket->Accept(base::Bind(&SocketAcceptFunction::OnAccept, this));
|
| + } else {
|
| + error_ = kSocketNotFoundError;
|
| + OnAccept(-1, NULL);
|
| + }
|
| +}
|
| +
|
| +void SocketAcceptFunction::OnAccept(int result_code,
|
| + net::TCPClientSocket *socket) {
|
| + DCHECK(socket);
|
| + // TODO(justinlin): This socket won't have an event notifier, but it's not
|
| + // used for anything right now.
|
| + Socket *client_socket = new TCPSocket(socket, NULL, true);
|
| +
|
| + DictionaryValue* result = new DictionaryValue();
|
| + result->SetInteger(kResultCodeKey, result_code);
|
| + result->SetInteger(kSocketIdKey, manager_->Add(client_socket));
|
| + SetResult(result);
|
| +
|
| + AsyncWorkCompleted();
|
| +}
|
| +
|
| SocketReadFunction::SocketReadFunction()
|
| : params_(NULL) {
|
| }
|
|
|