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

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: Check for NULL TCPSocket, updated test 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 void SocketSetNoDelayFunction::Work() { 446 void SocketSetNoDelayFunction::Work() {
447 bool result = false; 447 bool result = false;
448 Socket* socket = manager_->Get(params_->socket_id); 448 Socket* socket = manager_->Get(params_->socket_id);
449 if (socket) 449 if (socket)
450 result = socket->SetNoDelay(params_->no_delay); 450 result = socket->SetNoDelay(params_->no_delay);
451 else 451 else
452 error_ = kSocketNotFoundError; 452 error_ = kSocketNotFoundError;
453 SetResult(Value::CreateBooleanValue(result)); 453 SetResult(Value::CreateBooleanValue(result));
454 } 454 }
455 455
456 SocketGetInfoFunction::SocketGetInfoFunction()
457 : params_(NULL) {}
458
459 SocketGetInfoFunction::~SocketGetInfoFunction() {}
460
461 bool SocketGetInfoFunction::Prepare() {
462 params_ = api::socket::GetInfo::Params::Create(*args_);
463 EXTENSION_FUNCTION_VALIDATE(params_.get());
464 return true;
465 }
466
467 void SocketGetInfoFunction::Work() {
468 api::socket::SocketInfo info;
469 Socket* socket = manager_->Get(params_->socket_id);
470 if (socket) {
471 // This represents what we know about the socket, and does not call through
472 // to the system.
473 info.socket_type = (socket->IsTCPSocket() ? kTCPOption : kUDPOption);
474 info.connected = socket->IsConnected();
475
476 // Grab the peer address as known by the OS. This and the call below will
477 // always succeed while the socket is connected, even if the socket has
478 // been remotely closed by the peer; only reading the socket will reveal
479 // that it should be closed locally.
480 net::IPEndPoint peerAddress;
481 if (socket->GetPeerAddress(&peerAddress)) {
482 info.peer_address.reset(
483 new std::string(peerAddress.ToStringWithoutPort()));
484 info.peer_port.reset(new int(peerAddress.port()));
485 }
486
487 // Grab the local address as known by the OS.
488 net::IPEndPoint localAddress;
489 if (socket->GetLocalAddress(&localAddress)) {
490 info.local_address.reset(
491 new std::string(localAddress.ToStringWithoutPort()));
492 info.local_port.reset(new int(localAddress.port()));
493 }
494 } else {
495 error_ = kSocketNotFoundError;
496 }
497 SetResult(info.ToValue().release());
498 }
499
456 } // namespace extensions 500 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698