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

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: 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 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) {
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
452 }
453
454 SocketGetInfoFunction::~SocketGetInfoFunction() {}
455
456 bool SocketGetInfoFunction::Prepare() {
457 params_ = api::experimental_socket::GetInfo::Params::Create(*args_);
458 EXTENSION_FUNCTION_VALIDATE(params_.get());
459 return true;
460 }
461
462 void SocketGetInfoFunction::Work() {
463 api::experimental_socket::SocketInfo info;
464 Socket* socket = manager_->Get(params_->socket_id);
465 if (socket) {
466 // This represents what we know about the socket, and does not call through
467 // to the system.
468 info.socket_type = (socket->IsTCPSocket() ? kTCPOption : kUDPOption);
469 info.connected = socket->IsConnected();
470
471 // Grab the peer address as known by the OS. This is racey along with the
472 // second call below; it is possible e.g. for a TCP socket to be connected
473 // here, but disconnected by the OS before we grab our localAddress, which
474 // will then be blank.
475 net::IPEndPoint peerAddress;
476 if (socket->GetPeerAddress(&peerAddress)) {
477 info.peer_address.reset(
478 new std::string(peerAddress.ToStringWithoutPort()));
479 info.peer_port.reset(new int(peerAddress.port()));
480 }
481
482 // Grab the local address as known by the OS.
483 net::IPEndPoint localAddress;
484 if (socket->GetLocalAddress(&localAddress)) {
485 info.local_address.reset(
486 new std::string(localAddress.ToStringWithoutPort()));
487 info.local_port.reset(new int(localAddress.port()));
488 }
489 } else {
490 error_ = kSocketNotFoundError;
491 }
492 SetResult(info.ToValue().release());
493 }
494
450 } // namespace extensions 495 } // namespace extensions
OLDNEW
« 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