| 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_tcp_server/sockets_tcp_server_api.h" | 5 #include "extensions/browser/api/sockets_tcp_server/sockets_tcp_server_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/tcp_socket.h" | 8 #include "extensions/browser/api/socket/tcp_socket.h" |
| 9 #include "extensions/browser/api/sockets_tcp_server/tcp_server_socket_event_disp
atcher.h" | 9 #include "extensions/browser/api/sockets_tcp_server/tcp_server_socket_event_disp
atcher.h" |
| 10 #include "extensions/common/api/sockets/sockets_manifest_data.h" | 10 #include "extensions/common/api/sockets/sockets_manifest_data.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 socket_event_dispatcher_ = | 169 socket_event_dispatcher_ = |
| 170 TCPServerSocketEventDispatcher::Get(browser_context()); | 170 TCPServerSocketEventDispatcher::Get(browser_context()); |
| 171 DCHECK(socket_event_dispatcher_) | 171 DCHECK(socket_event_dispatcher_) |
| 172 << "There is no socket event dispatcher. " | 172 << "There is no socket event dispatcher. " |
| 173 "If this assertion is failing during a test, then it is likely that " | 173 "If this assertion is failing during a test, then it is likely that " |
| 174 "TestExtensionSystem is failing to provide an instance of " | 174 "TestExtensionSystem is failing to provide an instance of " |
| 175 "TCPServerSocketEventDispatcher."; | 175 "TCPServerSocketEventDispatcher."; |
| 176 return socket_event_dispatcher_ != NULL; | 176 return socket_event_dispatcher_ != NULL; |
| 177 } | 177 } |
| 178 | 178 |
| 179 void SocketsTcpServerListenFunction::Work() { | 179 void SocketsTcpServerListenFunction::AsyncWorkStart() { |
| 180 ResumableTCPServerSocket* socket = GetTcpSocket(params_->socket_id); | 180 ResumableTCPServerSocket* socket = GetTcpSocket(params_->socket_id); |
| 181 if (!socket) { | 181 if (!socket) { |
| 182 error_ = kSocketNotFoundError; | 182 error_ = kSocketNotFoundError; |
| 183 AsyncWorkCompleted(); |
| 183 return; | 184 return; |
| 184 } | 185 } |
| 185 | 186 |
| 186 SocketPermissionRequest param( | 187 SocketPermissionRequest param( |
| 187 SocketPermissionRequest::TCP_LISTEN, params_->address, params_->port); | 188 SocketPermissionRequest::TCP_LISTEN, params_->address, params_->port); |
| 188 if (!SocketsManifestData::CheckRequest(extension(), param)) { | 189 if (!SocketsManifestData::CheckRequest(extension(), param)) { |
| 189 error_ = kPermissionError; | 190 error_ = kPermissionError; |
| 191 AsyncWorkCompleted(); |
| 190 return; | 192 return; |
| 191 } | 193 } |
| 192 | 194 |
| 193 int net_result = socket->Listen( | 195 int net_result = socket->Listen( |
| 194 params_->address, | 196 params_->address, |
| 195 params_->port, | 197 params_->port, |
| 196 params_->backlog.get() ? *params_->backlog.get() : kDefaultListenBacklog, | 198 params_->backlog.get() ? *params_->backlog.get() : kDefaultListenBacklog, |
| 197 &error_); | 199 &error_); |
| 198 | 200 results_ = sockets_tcp_server::Listen::Results::Create(net_result); |
| 199 if (net_result != net::OK) | |
| 200 error_ = net::ErrorToString(net_result); | |
| 201 | |
| 202 if (net_result == net::OK) { | 201 if (net_result == net::OK) { |
| 203 socket_event_dispatcher_->OnServerSocketListen(extension_->id(), | 202 socket_event_dispatcher_->OnServerSocketListen(extension_->id(), |
| 204 params_->socket_id); | 203 params_->socket_id); |
| 204 } else { |
| 205 error_ = net::ErrorToString(net_result); |
| 206 AsyncWorkCompleted(); |
| 207 return; |
| 205 } | 208 } |
| 206 | 209 |
| 207 results_ = sockets_tcp_server::Listen::Results::Create(net_result); | 210 OpenFirewallHole(params_->address, params_->socket_id, socket); |
| 208 } | 211 } |
| 209 | 212 |
| 210 SocketsTcpServerDisconnectFunction::SocketsTcpServerDisconnectFunction() {} | 213 SocketsTcpServerDisconnectFunction::SocketsTcpServerDisconnectFunction() {} |
| 211 | 214 |
| 212 SocketsTcpServerDisconnectFunction::~SocketsTcpServerDisconnectFunction() {} | 215 SocketsTcpServerDisconnectFunction::~SocketsTcpServerDisconnectFunction() {} |
| 213 | 216 |
| 214 bool SocketsTcpServerDisconnectFunction::Prepare() { | 217 bool SocketsTcpServerDisconnectFunction::Prepare() { |
| 215 params_ = sockets_tcp_server::Disconnect::Params::Create(*args_); | 218 params_ = sockets_tcp_server::Disconnect::Params::Create(*args_); |
| 216 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 219 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 217 return true; | 220 return true; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 if (socket) { | 292 if (socket) { |
| 290 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 293 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
| 291 } | 294 } |
| 292 } | 295 } |
| 293 } | 296 } |
| 294 results_ = sockets_tcp_server::GetSockets::Results::Create(socket_infos); | 297 results_ = sockets_tcp_server::GetSockets::Results::Create(socket_infos); |
| 295 } | 298 } |
| 296 | 299 |
| 297 } // namespace core_api | 300 } // namespace core_api |
| 298 } // namespace extensions | 301 } // namespace extensions |
| OLD | NEW |