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..64dd6665b27a2d8e43a754ff2cad75d98ed46f58 100644 |
--- a/chrome/browser/extensions/api/socket/socket_api.cc |
+++ b/chrome/browser/extensions/api/socket/socket_api.cc |
@@ -447,4 +447,42 @@ void SocketSetNoDelayFunction::Work() { |
SetResult(Value::CreateBooleanValue(result)); |
} |
+SocketGetInfoFunction::SocketGetInfoFunction() |
+ : params_(NULL) { |
+} |
+ |
+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) { |
+ info.socket_type = (socket->IsTCPSocket() ? kTCPOption : kUDPOption); |
+ info.connected = socket->IsConnected(); |
+ |
+ net::IPEndPoint peerAddress; |
+ if (socket->GetPeerAddress(&peerAddress)) { |
+ info.peer_address.reset( |
+ new std::string(peerAddress.ToStringWithoutPort())); |
+ info.peer_port.reset(new int(peerAddress.port())); |
+ } |
+ |
+ 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 |