Chromium Code Reviews| 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 93ba29c1e7fa20a0746b0c6d77cb653e6bb08c3d..4d3fae5b96b7671964e94091948520e790a7d6b6 100644 |
| --- a/chrome/browser/extensions/api/socket/socket_api.cc |
| +++ b/chrome/browser/extensions/api/socket/socket_api.cc |
| @@ -447,4 +447,49 @@ void SocketSetNoDelayFunction::Work() { |
| SetResult(Value::CreateBooleanValue(result)); |
| } |
| +SocketGetInfoFunction::SocketGetInfoFunction() |
| + : params_(NULL) { |
|
benwells
2012/07/30 00:47:58
Nit: can use {} on the one line.
thorogood
2012/07/30 07:22:18
Done, I've left the ": params_(NULL) {}" on the ne
|
| +} |
| + |
| +SocketGetInfoFunction::~SocketGetInfoFunction() {} |
| + |
| +bool SocketGetInfoFunction::Prepare() { |
| + params_ = api::experimental_socket::GetInfo::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| + return true; |
| +} |
| + |
| +void SocketGetInfoFunction::Work() { |
| + api::experimental_socket::SocketInfo info; |
| + Socket* socket = manager_->Get(params_->socket_id); |
| + if (socket) { |
| + // This represents what we know about the socket, and does not call through |
| + // to the system. |
| + info.socket_type = (socket->IsTCPSocket() ? kTCPOption : kUDPOption); |
| + info.connected = socket->IsConnected(); |
| + |
| + // Grab the peer address as known by the OS. This is racey along with the |
| + // second call below; it is possible e.g. for a TCP socket to be connected |
| + // here, but disconnected by the OS before we grab our localAddress, which |
| + // will then be blank. |
| + net::IPEndPoint peerAddress; |
| + if (socket->GetPeerAddress(&peerAddress)) { |
| + info.peer_address.reset( |
| + new std::string(peerAddress.ToStringWithoutPort())); |
| + info.peer_port.reset(new int(peerAddress.port())); |
| + } |
| + |
| + // Grab the local address as known by the OS. |
| + net::IPEndPoint localAddress; |
| + if (socket->GetLocalAddress(&localAddress)) { |
| + info.local_address.reset( |
| + new std::string(localAddress.ToStringWithoutPort())); |
| + info.local_port.reset(new int(localAddress.port())); |
| + } |
| + } else { |
| + error_ = kSocketNotFoundError; |
| + } |
| + SetResult(info.ToValue().release()); |
| +} |
| + |
| } // namespace extensions |