| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); | 179 socket_event_dispatcher_ = UDPSocketEventDispatcher::Get(browser_context()); |
| 180 DCHECK(socket_event_dispatcher_) | 180 DCHECK(socket_event_dispatcher_) |
| 181 << "There is no socket event dispatcher. " | 181 << "There is no socket event dispatcher. " |
| 182 "If this assertion is failing during a test, then it is likely that " | 182 "If this assertion is failing during a test, then it is likely that " |
| 183 "TestExtensionSystem is failing to provide an instance of " | 183 "TestExtensionSystem is failing to provide an instance of " |
| 184 "UDPSocketEventDispatcher."; | 184 "UDPSocketEventDispatcher."; |
| 185 return socket_event_dispatcher_ != NULL; | 185 return socket_event_dispatcher_ != NULL; |
| 186 } | 186 } |
| 187 | 187 |
| 188 void SocketsUdpBindFunction::Work() { | 188 void SocketsUdpBindFunction::AsyncWorkStart() { |
| 189 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 189 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
| 190 if (!socket) { | 190 if (!socket) { |
| 191 error_ = kSocketNotFoundError; | 191 error_ = kSocketNotFoundError; |
| 192 AsyncWorkCompleted(); |
| 192 return; | 193 return; |
| 193 } | 194 } |
| 194 | 195 |
| 195 content::SocketPermissionRequest param( | 196 content::SocketPermissionRequest param( |
| 196 SocketPermissionRequest::UDP_BIND, params_->address, params_->port); | 197 SocketPermissionRequest::UDP_BIND, params_->address, params_->port); |
| 197 if (!SocketsManifestData::CheckRequest(extension(), param)) { | 198 if (!SocketsManifestData::CheckRequest(extension(), param)) { |
| 198 error_ = kPermissionError; | 199 error_ = kPermissionError; |
| 200 AsyncWorkCompleted(); |
| 199 return; | 201 return; |
| 200 } | 202 } |
| 201 | 203 |
| 202 int net_result = socket->Bind(params_->address, params_->port); | 204 int net_result = socket->Bind(params_->address, params_->port); |
| 205 results_ = sockets_udp::Bind::Results::Create(net_result); |
| 203 if (net_result == net::OK) { | 206 if (net_result == net::OK) { |
| 204 socket_event_dispatcher_->OnSocketBind(extension_->id(), | 207 socket_event_dispatcher_->OnSocketBind(extension_->id(), |
| 205 params_->socket_id); | 208 params_->socket_id); |
| 209 } else { |
| 210 error_ = net::ErrorToString(net_result); |
| 211 AsyncWorkCompleted(); |
| 212 return; |
| 206 } | 213 } |
| 207 | 214 |
| 208 if (net_result != net::OK) | 215 OpenFirewallHole(params_->address, params_->socket_id, socket); |
| 209 error_ = net::ErrorToString(net_result); | |
| 210 results_ = sockets_udp::Bind::Results::Create(net_result); | |
| 211 } | 216 } |
| 212 | 217 |
| 213 SocketsUdpSendFunction::SocketsUdpSendFunction() : io_buffer_size_(0) {} | 218 SocketsUdpSendFunction::SocketsUdpSendFunction() : io_buffer_size_(0) {} |
| 214 | 219 |
| 215 SocketsUdpSendFunction::~SocketsUdpSendFunction() {} | 220 SocketsUdpSendFunction::~SocketsUdpSendFunction() {} |
| 216 | 221 |
| 217 bool SocketsUdpSendFunction::Prepare() { | 222 bool SocketsUdpSendFunction::Prepare() { |
| 218 params_ = sockets_udp::Send::Params::Create(*args_); | 223 params_ = sockets_udp::Send::Params::Create(*args_); |
| 219 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 224 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 220 io_buffer_size_ = params_->data.size(); | 225 io_buffer_size_ = params_->data.size(); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 error_ = kPermissionError; | 501 error_ = kPermissionError; |
| 497 return; | 502 return; |
| 498 } | 503 } |
| 499 | 504 |
| 500 const std::vector<std::string>& groups = socket->GetJoinedGroups(); | 505 const std::vector<std::string>& groups = socket->GetJoinedGroups(); |
| 501 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); | 506 results_ = sockets_udp::GetJoinedGroups::Results::Create(groups); |
| 502 } | 507 } |
| 503 | 508 |
| 504 } // namespace core_api | 509 } // namespace core_api |
| 505 } // namespace extensions | 510 } // namespace extensions |
| OLD | NEW |