OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/socket/udp_socket.h" | 5 #include "extensions/browser/api/socket/udp_socket.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/stl_util.h" |
11 #include "extensions/browser/api/api_resource.h" | 12 #include "extensions/browser/api/api_resource.h" |
12 #include "net/base/ip_address.h" | 13 #include "net/base/ip_address.h" |
13 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
15 #include "net/log/net_log_source.h" | 16 #include "net/log/net_log_source.h" |
16 #include "net/socket/datagram_socket.h" | 17 #include "net/socket/datagram_socket.h" |
17 #include "net/socket/udp_client_socket.h" | 18 #include "net/socket/udp_client_socket.h" |
18 | 19 |
19 namespace extensions { | 20 namespace extensions { |
20 | 21 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 254 } |
254 | 255 |
255 bool UDPSocket::IsBound() { return socket_.is_connected(); } | 256 bool UDPSocket::IsBound() { return socket_.is_connected(); } |
256 | 257 |
257 int UDPSocket::JoinGroup(const std::string& address) { | 258 int UDPSocket::JoinGroup(const std::string& address) { |
258 net::IPAddress ip; | 259 net::IPAddress ip; |
259 if (!ip.AssignFromIPLiteral(address)) | 260 if (!ip.AssignFromIPLiteral(address)) |
260 return net::ERR_ADDRESS_INVALID; | 261 return net::ERR_ADDRESS_INVALID; |
261 | 262 |
262 std::string normalized_address = ip.ToString(); | 263 std::string normalized_address = ip.ToString(); |
263 std::vector<std::string>::iterator find_result = std::find( | 264 if (base::ContainsValue(multicast_groups_, normalized_address)) |
264 multicast_groups_.begin(), multicast_groups_.end(), normalized_address); | |
265 if (find_result != multicast_groups_.end()) | |
266 return net::ERR_ADDRESS_INVALID; | 265 return net::ERR_ADDRESS_INVALID; |
267 | 266 |
268 int rv = socket_.JoinGroup(ip); | 267 int rv = socket_.JoinGroup(ip); |
269 if (rv == 0) | 268 if (rv == 0) |
270 multicast_groups_.push_back(normalized_address); | 269 multicast_groups_.push_back(normalized_address); |
271 return rv; | 270 return rv; |
272 } | 271 } |
273 | 272 |
274 int UDPSocket::LeaveGroup(const std::string& address) { | 273 int UDPSocket::LeaveGroup(const std::string& address) { |
275 net::IPAddress ip; | 274 net::IPAddress ip; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 308 |
310 ResumableUDPSocket::ResumableUDPSocket(const std::string& owner_extension_id) | 309 ResumableUDPSocket::ResumableUDPSocket(const std::string& owner_extension_id) |
311 : UDPSocket(owner_extension_id), | 310 : UDPSocket(owner_extension_id), |
312 persistent_(false), | 311 persistent_(false), |
313 buffer_size_(0), | 312 buffer_size_(0), |
314 paused_(false) {} | 313 paused_(false) {} |
315 | 314 |
316 bool ResumableUDPSocket::IsPersistent() const { return persistent(); } | 315 bool ResumableUDPSocket::IsPersistent() const { return persistent(); } |
317 | 316 |
318 } // namespace extensions | 317 } // namespace extensions |
OLD | NEW |