Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/common/extensions/permissions/socket_permission.h" | 8 #include "chrome/common/extensions/permissions/socket_permission.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h" | 10 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 src_id_(-1), | 113 src_id_(-1), |
| 114 event_notifier_(NULL) { | 114 event_notifier_(NULL) { |
| 115 } | 115 } |
| 116 | 116 |
| 117 SocketCreateFunction::~SocketCreateFunction() {} | 117 SocketCreateFunction::~SocketCreateFunction() {} |
| 118 | 118 |
| 119 bool SocketCreateFunction::Prepare() { | 119 bool SocketCreateFunction::Prepare() { |
| 120 params_ = api::socket::Create::Params::Create(*args_); | 120 params_ = api::socket::Create::Params::Create(*args_); |
| 121 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 121 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 122 | 122 |
| 123 if (params_->type == kTCPOption) { | 123 std::string type = extensions::api::socket::ToString(params_->type); |
| 124 if (type.empty()) | |
| 125 type = kUnknown; | |
|
not at google - send to devlin
2012/09/18 03:55:20
going to string here is actually unnecessary, you
cduvall
2012/09/21 00:39:28
Done.
| |
| 126 | |
| 127 if (type == kTCPOption) { | |
| 124 socket_type_ = kSocketTypeTCP; | 128 socket_type_ = kSocketTypeTCP; |
| 125 } else if (params_->type == kUDPOption) { | 129 } else if (type == kUDPOption) { |
| 126 socket_type_ = kSocketTypeUDP; | 130 socket_type_ = kSocketTypeUDP; |
| 127 } else { | |
| 128 error_ = kSocketTypeInvalidError; | |
| 129 return false; | |
| 130 } | 131 } |
| 131 if (params_->options.get()) { | 132 if (params_->options.get()) { |
| 132 scoped_ptr<DictionaryValue> options = params_->options->ToValue(); | 133 scoped_ptr<DictionaryValue> options = params_->options->ToValue(); |
| 133 src_id_ = ExtractSrcId(options.get()); | 134 src_id_ = ExtractSrcId(options.get()); |
| 134 event_notifier_ = CreateEventNotifier(src_id_); | 135 event_notifier_ = CreateEventNotifier(src_id_); |
| 135 } | 136 } |
| 136 | 137 |
| 137 return true; | 138 return true; |
| 138 } | 139 } |
| 139 | 140 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 528 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 528 return true; | 529 return true; |
| 529 } | 530 } |
| 530 | 531 |
| 531 void SocketGetInfoFunction::Work() { | 532 void SocketGetInfoFunction::Work() { |
| 532 api::socket::SocketInfo info; | 533 api::socket::SocketInfo info; |
| 533 Socket* socket = GetSocket(params_->socket_id); | 534 Socket* socket = GetSocket(params_->socket_id); |
| 534 if (socket) { | 535 if (socket) { |
| 535 // This represents what we know about the socket, and does not call through | 536 // This represents what we know about the socket, and does not call through |
| 536 // to the system. | 537 // to the system. |
| 537 switch (socket->GetSocketType()) { | 538 if (socket->GetSocketType() == Socket::TYPE_TCP) |
| 538 case Socket::TYPE_TCP: | 539 info.socket_type = extensions::api::socket::SOCKET_SOCKET_TYPE_TCP; |
| 539 info.socket_type = kTCPOption; | 540 else |
| 540 break; | 541 info.socket_type = extensions::api::socket::SOCKET_SOCKET_TYPE_UDP; |
| 541 case Socket::TYPE_UDP: | |
| 542 info.socket_type = kUDPOption; | |
| 543 break; | |
| 544 default: | |
| 545 NOTREACHED() << "Unknown socket type."; | |
| 546 info.socket_type = kUnknown; | |
| 547 break; | |
| 548 } | |
| 549 info.connected = socket->IsConnected(); | 542 info.connected = socket->IsConnected(); |
| 550 | 543 |
| 551 // Grab the peer address as known by the OS. This and the call below will | 544 // Grab the peer address as known by the OS. This and the call below will |
| 552 // always succeed while the socket is connected, even if the socket has | 545 // always succeed while the socket is connected, even if the socket has |
| 553 // been remotely closed by the peer; only reading the socket will reveal | 546 // been remotely closed by the peer; only reading the socket will reveal |
| 554 // that it should be closed locally. | 547 // that it should be closed locally. |
| 555 net::IPEndPoint peerAddress; | 548 net::IPEndPoint peerAddress; |
| 556 if (socket->GetPeerAddress(&peerAddress)) { | 549 if (socket->GetPeerAddress(&peerAddress)) { |
| 557 info.peer_address.reset( | 550 info.peer_address.reset( |
| 558 new std::string(peerAddress.ToStringWithoutPort())); | 551 new std::string(peerAddress.ToStringWithoutPort())); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 info->name = i->name; | 605 info->name = i->name; |
| 613 info->address = net::IPAddressToString(i->address); | 606 info->address = net::IPAddressToString(i->address); |
| 614 create_arg.push_back(info); | 607 create_arg.push_back(info); |
| 615 } | 608 } |
| 616 | 609 |
| 617 results_ = api::socket::GetNetworkList::Results::Create(create_arg); | 610 results_ = api::socket::GetNetworkList::Results::Create(create_arg); |
| 618 SendResponse(true); | 611 SendResponse(true); |
| 619 } | 612 } |
| 620 | 613 |
| 621 } // namespace extensions | 614 } // namespace extensions |
| OLD | NEW |