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..7050746f52de14e670c8125afcebad849798e255 100644 |
| --- a/chrome/browser/extensions/api/socket/udp_socket.cc |
| +++ b/chrome/browser/extensions/api/socket/udp_socket.cc |
| @@ -222,4 +222,55 @@ void UDPSocket::OnSendToComplete(int result) { |
| send_to_callback_.Reset(); |
| } |
| +int UDPSocket::JoinGroup(const std::string& address) { |
| + 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) { |
| + 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) { |
| + return socket_.SetMulticastTimeToLive(ttl); |
| +} |
| + |
| +int UDPSocket::SetMulticastLoopbackMode(bool loopback) { |
| + return socket_.SetMulticastLoopbackMode(loopback); |
| +} |
| + |
| +int UDPSocket::GetJoinedGroups(base::hash_set<std::string>* groups) const { |
|
miket_OOO
2013/04/25 21:52:12
Same here -- why hash_set?
|
| + if (!socket_.is_connected()) |
| + return net::ERR_SOCKET_NOT_CONNECTED; |
| + |
| + groups->clear(); |
|
miket_OOO
2013/04/25 21:52:12
This method signature is a bit odd. Why require th
Bei Zhang
2013/04/25 23:56:21
To avoid the copy of the container.
Clear would be
|
| + groups->insert(multicast_groups_.begin(), multicast_groups_.end()); |
| + return 0; |
| +} |
| + |
| } // namespace extensions |