Chromium Code Reviews| Index: chrome/browser/extensions/api/socket/udp_socket.cc | 
| diff --git a/chrome/browser/extensions/api/socket/udp_socket.cc b/chrome/browser/extensions/api/socket/udp_socket.cc | 
| index b9a804cbb98d8e3d2ff057ca1b548de9eda27628..8ccdb4e029d1e1b105f03693db8d1e65714e9d18 100644 | 
| --- a/chrome/browser/extensions/api/socket/udp_socket.cc | 
| +++ b/chrome/browser/extensions/api/socket/udp_socket.cc | 
| @@ -222,4 +222,62 @@ void UDPSocket::OnSendToComplete(int result) { | 
| send_to_callback_.Reset(); | 
| } | 
| +int UDPSocket::JoinGroup(const std::string& address) { | 
| + if (!socket_.is_connected()) | 
| + return net::ERR_SOCKET_NOT_CONNECTED; | 
| + net::IPAddressNumber ip; | 
| + if (!net::ParseIPLiteralToNumber(address, &ip)) | 
| + return net::ERR_ADDRESS_INVALID; | 
| + | 
| + std::string normalized_address = net::IPAddressToString(ip); | 
| + base::hash_set<std::string>::iterator find_result = | 
| + multicast_groups_.find(normalized_address); | 
| + if (find_result != multicast_groups_.end()) | 
| + return net::ERR_ADDRESS_INVALID; | 
| + | 
| + int rv = socket_.JoinGroup(ip); | 
| + if (rv == 0) | 
| + multicast_groups_.insert(normalized_address); | 
| + return rv; | 
| +} | 
| + | 
| +int UDPSocket::LeaveGroup(const std::string& address) { | 
| + if (!socket_.is_connected()) | 
| + return net::ERR_SOCKET_NOT_CONNECTED; | 
| + net::IPAddressNumber ip; | 
| + if (!net::ParseIPLiteralToNumber(address, &ip)) | 
| + return net::ERR_ADDRESS_INVALID; | 
| + | 
| + std::string normalized_address = net::IPAddressToString(ip); | 
| + base::hash_set<std::string>::iterator find_result = | 
| + multicast_groups_.find(normalized_address); | 
| + if (find_result == multicast_groups_.end()) | 
| + return net::ERR_ADDRESS_INVALID; | 
| + | 
| + int rv = socket_.LeaveGroup(ip); | 
| + if (rv == 0) | 
| + multicast_groups_.erase(find_result); | 
| + return rv; | 
| +} | 
| + | 
| +int UDPSocket::SetMulticastTimeToLive(int ttl) { | 
| + if (socket_.is_connected()) | 
| + return net::ERR_FAILED; | 
| 
 
wtc
2013/04/22 19:19:53
Please use net::ERR_UNEXPECTED here and on line 27
 
Bei Zhang
2013/04/23 17:26:53
net::UDPSocket should be used internally. I think
 
wtc
2013/04/23 18:01:07
I see. Thank you for the explanation.
net::UDPSoc
 
 | 
| + return socket_.SetMulticastTimeToLive(ttl); | 
| +} | 
| + | 
| +int UDPSocket::SetMulticastLoopbackMode(bool loopback) { | 
| + if (socket_.is_connected()) | 
| + return net::ERR_FAILED; | 
| + return socket_.SetMulticastLoopbackMode(loopback); | 
| +} | 
| + | 
| +int UDPSocket::GetJoinedGroups(base::hash_set<std::string>* groups) const { | 
| + if (!socket_.is_connected()) | 
| + return net::ERR_SOCKET_NOT_CONNECTED; | 
| + groups->clear(); | 
| + groups->insert(multicast_groups_.begin(), multicast_groups_.end()); | 
| + return 0; | 
| +} | 
| + | 
| } // namespace extensions |