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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 void SocketSetNoDelayFunction::Work() { | 440 void SocketSetNoDelayFunction::Work() { |
441 bool result = false; | 441 bool result = false; |
442 Socket* socket = manager_->Get(params_->socket_id); | 442 Socket* socket = manager_->Get(params_->socket_id); |
443 if (socket) | 443 if (socket) |
444 result = socket->SetNoDelay(params_->no_delay); | 444 result = socket->SetNoDelay(params_->no_delay); |
445 else | 445 else |
446 error_ = kSocketNotFoundError; | 446 error_ = kSocketNotFoundError; |
447 SetResult(Value::CreateBooleanValue(result)); | 447 SetResult(Value::CreateBooleanValue(result)); |
448 } | 448 } |
449 | 449 |
| 450 SocketGetInfoFunction::SocketGetInfoFunction() |
| 451 : params_(NULL) { |
| 452 } |
| 453 |
| 454 SocketGetInfoFunction::~SocketGetInfoFunction() {} |
| 455 |
| 456 bool SocketGetInfoFunction::Prepare() { |
| 457 params_ = api::experimental_socket::GetInfo::Params::Create(*args_); |
| 458 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 459 return true; |
| 460 } |
| 461 |
| 462 void SocketGetInfoFunction::Work() { |
| 463 api::experimental_socket::SocketInfo info; |
| 464 Socket* socket = manager_->Get(params_->socket_id); |
| 465 if (socket) { |
| 466 info.socket_type = (socket->IsTCPSocket() ? kTCPOption : kUDPOption); |
| 467 info.connected = socket->IsConnected(); |
| 468 |
| 469 net::IPEndPoint peerAddress; |
| 470 if (socket->GetPeerAddress(&peerAddress)) { |
| 471 info.peer_address.reset( |
| 472 new std::string(peerAddress.ToStringWithoutPort())); |
| 473 info.peer_port.reset(new int(peerAddress.port())); |
| 474 } |
| 475 |
| 476 net::IPEndPoint localAddress; |
| 477 if (socket->GetLocalAddress(&localAddress)) { |
| 478 info.local_address.reset( |
| 479 new std::string(localAddress.ToStringWithoutPort())); |
| 480 info.local_port.reset(new int(localAddress.port())); |
| 481 } |
| 482 } else { |
| 483 error_ = kSocketNotFoundError; |
| 484 } |
| 485 SetResult(info.ToValue().release()); |
| 486 } |
| 487 |
450 } // namespace extensions | 488 } // namespace extensions |
OLD | NEW |