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

Side by Side Diff: chrome/browser/extensions/api/socket/udp_socket.cc

Issue 12684008: Multicast socket API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add License info to multicast.js Created 7 years, 7 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 | Annotate | Revision Log
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/udp_socket.h" 5 #include "chrome/browser/extensions/api/socket/udp_socket.h"
6 6
7 #include <algorithm>
8
7 #include "chrome/browser/extensions/api/api_resource.h" 9 #include "chrome/browser/extensions/api/api_resource.h"
8 #include "net/base/ip_endpoint.h" 10 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
10 #include "net/udp/datagram_socket.h" 12 #include "net/udp/datagram_socket.h"
11 #include "net/udp/udp_client_socket.h" 13 #include "net/udp/udp_client_socket.h"
12 14
13 namespace extensions { 15 namespace extensions {
14 16
15 UDPSocket::UDPSocket(const std::string& owner_extension_id) 17 UDPSocket::UDPSocket(const std::string& owner_extension_id)
16 : Socket(owner_extension_id), 18 : Socket(owner_extension_id),
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 recv_from_callback_.Run(result, io_buffer, ip, port); 217 recv_from_callback_.Run(result, io_buffer, ip, port);
216 recv_from_callback_.Reset(); 218 recv_from_callback_.Reset();
217 } 219 }
218 220
219 void UDPSocket::OnSendToComplete(int result) { 221 void UDPSocket::OnSendToComplete(int result) {
220 DCHECK(!send_to_callback_.is_null()); 222 DCHECK(!send_to_callback_.is_null());
221 send_to_callback_.Run(result); 223 send_to_callback_.Run(result);
222 send_to_callback_.Reset(); 224 send_to_callback_.Reset();
223 } 225 }
224 226
227 int UDPSocket::JoinGroup(const std::string& address) {
228 net::IPAddressNumber ip;
229 if (!net::ParseIPLiteralToNumber(address, &ip))
230 return net::ERR_ADDRESS_INVALID;
231
232 std::string normalized_address = net::IPAddressToString(ip);
233 std::vector<std::string>::iterator find_result =
234 std::find(multicast_groups_.begin(),
235 multicast_groups_.end(),
236 normalized_address);
237 if (find_result != multicast_groups_.end())
238 return net::ERR_ADDRESS_INVALID;
239
240 int rv = socket_.JoinGroup(ip);
241 if (rv == 0)
242 multicast_groups_.push_back(normalized_address);
243 return rv;
244 }
245
246 int UDPSocket::LeaveGroup(const std::string& address) {
247 net::IPAddressNumber ip;
248 if (!net::ParseIPLiteralToNumber(address, &ip))
249 return net::ERR_ADDRESS_INVALID;
250
251 std::string normalized_address = net::IPAddressToString(ip);
252 std::vector<std::string>::iterator find_result =
253 std::find(multicast_groups_.begin(),
254 multicast_groups_.end(),
255 normalized_address);
256 if (find_result == multicast_groups_.end())
257 return net::ERR_ADDRESS_INVALID;
258
259 int rv = socket_.LeaveGroup(ip);
260 if (rv == 0)
261 multicast_groups_.erase(find_result);
262 return rv;
263 }
264
265 int UDPSocket::SetMulticastTimeToLive(int ttl) {
266 return socket_.SetMulticastTimeToLive(ttl);
267 }
268
269 int UDPSocket::SetMulticastLoopbackMode(bool loopback) {
270 return socket_.SetMulticastLoopbackMode(loopback);
271 }
272
273 const std::vector<std::string>& UDPSocket::GetJoinedGroups() const {
274 return multicast_groups_;
275 }
276
225 } // namespace extensions 277 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/socket/udp_socket.h ('k') | chrome/browser/extensions/api/socket/udp_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698