Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1089)

Unified Diff: chrome/browser/extensions/api/socket/socket_api.cc

Issue 10790137: Adds socket.getInfo to the socket API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Socket updates Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « chrome/browser/extensions/api/socket/socket_api.h ('k') | chrome/browser/extensions/api/socket/tcp_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698