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

Side by Side 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: Better comments, nit fix Created 8 years, 4 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 unified diff | Download patch
OLDNEW
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
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 SocketGetInfoFunction::~SocketGetInfoFunction() {}
454
455 bool SocketGetInfoFunction::Prepare() {
456 params_ = api::experimental_socket::GetInfo::Params::Create(*args_);
457 EXTENSION_FUNCTION_VALIDATE(params_.get());
458 return true;
459 }
460
461 void SocketGetInfoFunction::Work() {
462 api::experimental_socket::SocketInfo info;
463 Socket* socket = manager_->Get(params_->socket_id);
464 if (socket) {
465 // This represents what we know about the socket, and does not call through
466 // to the system.
467 info.socket_type = (socket->IsTCPSocket() ? kTCPOption : kUDPOption);
468 info.connected = socket->IsConnected();
469
470 // Grab the peer address as known by the OS. This and the call below will
471 // always succeed while the socket is connected, even if the socket has
472 // been remotely closed by the peer; only reading the socket will reveal
473 // that it should be closed locally.
474 net::IPEndPoint peerAddress;
475 if (socket->GetPeerAddress(&peerAddress)) {
476 info.peer_address.reset(
477 new std::string(peerAddress.ToStringWithoutPort()));
478 info.peer_port.reset(new int(peerAddress.port()));
479 }
480
481 // Grab the local address as known by the OS.
482 net::IPEndPoint localAddress;
483 if (socket->GetLocalAddress(&localAddress)) {
484 info.local_address.reset(
485 new std::string(localAddress.ToStringWithoutPort()));
486 info.local_port.reset(new int(localAddress.port()));
487 }
488 } else {
489 error_ = kSocketNotFoundError;
490 }
491 SetResult(info.ToValue().release());
492 }
493
450 } // namespace extensions 494 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698