| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 sockets_udp::SocketInfo CreateSocketInfo(int socket_id, | 49 sockets_udp::SocketInfo CreateSocketInfo(int socket_id, |
| 50 ResumableUDPSocket* socket) { | 50 ResumableUDPSocket* socket) { |
| 51 sockets_udp::SocketInfo socket_info; | 51 sockets_udp::SocketInfo socket_info; |
| 52 // 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 |
| 53 // to the system. | 53 // to the system. |
| 54 socket_info.socket_id = socket_id; | 54 socket_info.socket_id = socket_id; |
| 55 if (!socket->name().empty()) { | 55 if (!socket->name().empty()) { |
| 56 socket_info.name.reset(new std::string(socket->name())); | 56 socket_info.name.reset(new std::string(socket->name())); |
| 57 } | 57 } |
| 58 socket_info.persistent = socket->persistent(); | 58 socket_info.persistent = socket->persistent(); |
| 59 socket_info.address_reusable = socket->allow_address_reuse(); |
| 59 if (socket->buffer_size() > 0) { | 60 if (socket->buffer_size() > 0) { |
| 60 socket_info.buffer_size.reset(new int(socket->buffer_size())); | 61 socket_info.buffer_size.reset(new int(socket->buffer_size())); |
| 61 } | 62 } |
| 62 socket_info.paused = socket->paused(); | 63 socket_info.paused = socket->paused(); |
| 63 | 64 |
| 64 // Grab the local address as known by the OS. | 65 // Grab the local address as known by the OS. |
| 65 net::IPEndPoint localAddress; | 66 net::IPEndPoint localAddress; |
| 66 if (socket->GetLocalAddress(&localAddress)) { | 67 if (socket->GetLocalAddress(&localAddress)) { |
| 67 socket_info.local_address.reset( | 68 socket_info.local_address.reset( |
| 68 new std::string(localAddress.ToStringWithoutPort())); | 69 new std::string(localAddress.ToStringWithoutPort())); |
| 69 socket_info.local_port.reset(new int(localAddress.port())); | 70 socket_info.local_port.reset(new int(localAddress.port())); |
| 70 } | 71 } |
| 71 | 72 |
| 72 return socket_info; | 73 return socket_info; |
| 73 } | 74 } |
| 74 | 75 |
| 75 void SetSocketProperties(ResumableUDPSocket* socket, | 76 void SetSocketProperties(ResumableUDPSocket* socket, |
| 76 sockets_udp::SocketProperties* properties) { | 77 sockets_udp::SocketProperties* properties) { |
| 77 if (properties->name.get()) { | 78 if (properties->name.get()) { |
| 78 socket->set_name(*properties->name); | 79 socket->set_name(*properties->name); |
| 79 } | 80 } |
| 80 if (properties->persistent.get()) { | 81 if (properties->persistent.get()) { |
| 81 socket->set_persistent(*properties->persistent); | 82 socket->set_persistent(*properties->persistent); |
| 82 } | 83 } |
| 84 if (properties->allow_address_reuse.get()) { |
| 85 socket->set_allow_address_reuse(*properties->allow_address_reuse); |
| 86 } |
| 83 if (properties->buffer_size.get()) { | 87 if (properties->buffer_size.get()) { |
| 84 socket->set_buffer_size(*properties->buffer_size); | 88 socket->set_buffer_size(*properties->buffer_size); |
| 85 } | 89 } |
| 86 } | 90 } |
| 87 | 91 |
| 88 SocketsUdpCreateFunction::SocketsUdpCreateFunction() {} | 92 SocketsUdpCreateFunction::SocketsUdpCreateFunction() {} |
| 89 | 93 |
| 90 SocketsUdpCreateFunction::~SocketsUdpCreateFunction() {} | 94 SocketsUdpCreateFunction::~SocketsUdpCreateFunction() {} |
| 91 | 95 |
| 92 bool SocketsUdpCreateFunction::Prepare() { | 96 bool SocketsUdpCreateFunction::Prepare() { |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 521 |
| 518 int net_result = socket->SetBroadcast(params_->enabled); | 522 int net_result = socket->SetBroadcast(params_->enabled); |
| 519 if (net_result != net::OK) { | 523 if (net_result != net::OK) { |
| 520 error_ = net::ErrorToString(net_result); | 524 error_ = net::ErrorToString(net_result); |
| 521 } | 525 } |
| 522 results_ = sockets_udp::SetBroadcast::Results::Create(net_result); | 526 results_ = sockets_udp::SetBroadcast::Results::Create(net_result); |
| 523 } | 527 } |
| 524 | 528 |
| 525 } // namespace api | 529 } // namespace api |
| 526 } // namespace extensions | 530 } // namespace extensions |
| OLD | NEW |