| 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/sockets_udp/sockets_udp_api.h" | 5 #include "extensions/browser/api/sockets_udp/sockets_udp_api.h" |
| 6 | 6 |
| 7 #include "content/public/common/socket_permission_request.h" | 7 #include "content/public/common/socket_permission_request.h" |
| 8 #include "extensions/browser/api/socket/udp_socket.h" | 8 #include "extensions/browser/api/socket/udp_socket.h" |
| 9 #include "extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.h" | 9 #include "extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.h" |
| 10 #include "extensions/common/api/sockets/sockets_manifest_data.h" | 10 #include "extensions/common/api/sockets/sockets_manifest_data.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 UDPSocketExtensionWithDnsLookupFunction::CreateSocketResourceManager() { | 39 UDPSocketExtensionWithDnsLookupFunction::CreateSocketResourceManager() { |
| 40 return scoped_ptr<SocketResourceManagerInterface>( | 40 return scoped_ptr<SocketResourceManagerInterface>( |
| 41 new SocketResourceManager<ResumableUDPSocket>()); | 41 new SocketResourceManager<ResumableUDPSocket>()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 ResumableUDPSocket* UDPSocketExtensionWithDnsLookupFunction::GetUdpSocket( | 44 ResumableUDPSocket* UDPSocketExtensionWithDnsLookupFunction::GetUdpSocket( |
| 45 int socket_id) { | 45 int socket_id) { |
| 46 return static_cast<ResumableUDPSocket*>(GetSocket(socket_id)); | 46 return static_cast<ResumableUDPSocket*>(GetSocket(socket_id)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 linked_ptr<sockets_udp::SocketInfo> CreateSocketInfo( | 49 sockets_udp::SocketInfo CreateSocketInfo(int socket_id, |
| 50 int socket_id, | 50 ResumableUDPSocket* socket) { |
| 51 ResumableUDPSocket* socket) { | 51 sockets_udp::SocketInfo socket_info; |
| 52 linked_ptr<sockets_udp::SocketInfo> socket_info( | |
| 53 new sockets_udp::SocketInfo()); | |
| 54 // This represents what we know about the socket, and does not call through | 52 // This represents what we know about the socket, and does not call through |
| 55 // to the system. | 53 // to the system. |
| 56 socket_info->socket_id = socket_id; | 54 socket_info.socket_id = socket_id; |
| 57 if (!socket->name().empty()) { | 55 if (!socket->name().empty()) { |
| 58 socket_info->name.reset(new std::string(socket->name())); | 56 socket_info.name.reset(new std::string(socket->name())); |
| 59 } | 57 } |
| 60 socket_info->persistent = socket->persistent(); | 58 socket_info.persistent = socket->persistent(); |
| 61 if (socket->buffer_size() > 0) { | 59 if (socket->buffer_size() > 0) { |
| 62 socket_info->buffer_size.reset(new int(socket->buffer_size())); | 60 socket_info.buffer_size.reset(new int(socket->buffer_size())); |
| 63 } | 61 } |
| 64 socket_info->paused = socket->paused(); | 62 socket_info.paused = socket->paused(); |
| 65 | 63 |
| 66 // Grab the local address as known by the OS. | 64 // Grab the local address as known by the OS. |
| 67 net::IPEndPoint localAddress; | 65 net::IPEndPoint localAddress; |
| 68 if (socket->GetLocalAddress(&localAddress)) { | 66 if (socket->GetLocalAddress(&localAddress)) { |
| 69 socket_info->local_address.reset( | 67 socket_info.local_address.reset( |
| 70 new std::string(localAddress.ToStringWithoutPort())); | 68 new std::string(localAddress.ToStringWithoutPort())); |
| 71 socket_info->local_port.reset(new int(localAddress.port())); | 69 socket_info.local_port.reset(new int(localAddress.port())); |
| 72 } | 70 } |
| 73 | 71 |
| 74 return socket_info; | 72 return socket_info; |
| 75 } | 73 } |
| 76 | 74 |
| 77 void SetSocketProperties(ResumableUDPSocket* socket, | 75 void SetSocketProperties(ResumableUDPSocket* socket, |
| 78 sockets_udp::SocketProperties* properties) { | 76 sockets_udp::SocketProperties* properties) { |
| 79 if (properties->name.get()) { | 77 if (properties->name.get()) { |
| 80 socket->set_name(*properties->name.get()); | 78 socket->set_name(*properties->name.get()); |
| 81 } | 79 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 return true; | 320 return true; |
| 323 } | 321 } |
| 324 | 322 |
| 325 void SocketsUdpGetInfoFunction::Work() { | 323 void SocketsUdpGetInfoFunction::Work() { |
| 326 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 324 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 327 if (!socket) { | 325 if (!socket) { |
| 328 error_ = kSocketNotFoundError; | 326 error_ = kSocketNotFoundError; |
| 329 return; | 327 return; |
| 330 } | 328 } |
| 331 | 329 |
| 332 linked_ptr<sockets_udp::SocketInfo> socket_info = | 330 sockets_udp::SocketInfo socket_info = |
| 333 CreateSocketInfo(params_->socket_id, socket); | 331 CreateSocketInfo(params_->socket_id, socket); |
| 334 results_ = sockets_udp::GetInfo::Results::Create(*socket_info); | 332 results_ = sockets_udp::GetInfo::Results::Create(socket_info); |
| 335 } | 333 } |
| 336 | 334 |
| 337 SocketsUdpGetSocketsFunction::SocketsUdpGetSocketsFunction() {} | 335 SocketsUdpGetSocketsFunction::SocketsUdpGetSocketsFunction() {} |
| 338 | 336 |
| 339 SocketsUdpGetSocketsFunction::~SocketsUdpGetSocketsFunction() {} | 337 SocketsUdpGetSocketsFunction::~SocketsUdpGetSocketsFunction() {} |
| 340 | 338 |
| 341 bool SocketsUdpGetSocketsFunction::Prepare() { return true; } | 339 bool SocketsUdpGetSocketsFunction::Prepare() { return true; } |
| 342 | 340 |
| 343 void SocketsUdpGetSocketsFunction::Work() { | 341 void SocketsUdpGetSocketsFunction::Work() { |
| 344 std::vector<linked_ptr<sockets_udp::SocketInfo> > socket_infos; | 342 std::vector<sockets_udp::SocketInfo> socket_infos; |
| 345 base::hash_set<int>* resource_ids = GetSocketIds(); | 343 base::hash_set<int>* resource_ids = GetSocketIds(); |
| 346 if (resource_ids != NULL) { | 344 if (resource_ids != NULL) { |
| 347 for (base::hash_set<int>::iterator it = resource_ids->begin(); | 345 for (int socket_id : *resource_ids) { |
| 348 it != resource_ids->end(); | |
| 349 ++it) { | |
| 350 int socket_id = *it; | |
| 351 ResumableUDPSocket* socket = GetUdpSocket(socket_id); | 346 ResumableUDPSocket* socket = GetUdpSocket(socket_id); |
| 352 if (socket) { | 347 if (socket) { |
| 353 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 348 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
| 354 } | 349 } |
| 355 } | 350 } |
| 356 } | 351 } |
| 357 results_ = sockets_udp::GetSockets::Results::Create(socket_infos); | 352 results_ = sockets_udp::GetSockets::Results::Create(socket_infos); |
| 358 } | 353 } |
| 359 | 354 |
| 360 SocketsUdpJoinGroupFunction::SocketsUdpJoinGroupFunction() {} | 355 SocketsUdpJoinGroupFunction::SocketsUdpJoinGroupFunction() {} |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 517 |
| 523 int net_result = socket->SetBroadcast(params_->enabled); | 518 int net_result = socket->SetBroadcast(params_->enabled); |
| 524 if (net_result != net::OK) { | 519 if (net_result != net::OK) { |
| 525 error_ = net::ErrorToString(net_result); | 520 error_ = net::ErrorToString(net_result); |
| 526 } | 521 } |
| 527 results_ = sockets_udp::SetBroadcast::Results::Create(net_result); | 522 results_ = sockets_udp::SetBroadcast::Results::Create(net_result); |
| 528 } | 523 } |
| 529 | 524 |
| 530 } // namespace api | 525 } // namespace api |
| 531 } // namespace extensions | 526 } // namespace extensions |
| OLD | NEW |