| 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" |
| 11 #include "extensions/common/permissions/permissions_data.h" | 11 #include "extensions/common/permissions/permissions_data.h" |
| 12 #include "extensions/common/permissions/socket_permission.h" | 12 #include "extensions/common/permissions/socket_permission.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 | 14 |
| 15 using content::SocketPermissionRequest; | 15 using content::SocketPermissionRequest; |
| 16 using extensions::ResumableTCPServerSocket; | 16 using extensions::ResumableTCPServerSocket; |
| 17 using extensions::core_api::sockets_tcp_server::SocketInfo; | 17 using extensions::api::sockets_tcp_server::SocketInfo; |
| 18 using extensions::core_api::sockets_tcp_server::SocketProperties; | 18 using extensions::api::sockets_tcp_server::SocketProperties; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const char kSocketNotFoundError[] = "Socket not found"; | 22 const char kSocketNotFoundError[] = "Socket not found"; |
| 23 const char kPermissionError[] = "Does not have permission"; | 23 const char kPermissionError[] = "Does not have permission"; |
| 24 const int kDefaultListenBacklog = SOMAXCONN; | 24 const int kDefaultListenBacklog = SOMAXCONN; |
| 25 | 25 |
| 26 linked_ptr<SocketInfo> CreateSocketInfo(int socket_id, | 26 linked_ptr<SocketInfo> CreateSocketInfo(int socket_id, |
| 27 ResumableTCPServerSocket* socket) { | 27 ResumableTCPServerSocket* socket) { |
| 28 linked_ptr<SocketInfo> socket_info(new SocketInfo()); | 28 linked_ptr<SocketInfo> socket_info(new SocketInfo()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 52 socket->set_name(*properties->name.get()); | 52 socket->set_name(*properties->name.get()); |
| 53 } | 53 } |
| 54 if (properties->persistent.get()) { | 54 if (properties->persistent.get()) { |
| 55 socket->set_persistent(*properties->persistent.get()); | 55 socket->set_persistent(*properties->persistent.get()); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 namespace extensions { | 61 namespace extensions { |
| 62 namespace core_api { | 62 namespace api { |
| 63 | 63 |
| 64 TCPServerSocketAsyncApiFunction::~TCPServerSocketAsyncApiFunction() {} | 64 TCPServerSocketAsyncApiFunction::~TCPServerSocketAsyncApiFunction() {} |
| 65 | 65 |
| 66 scoped_ptr<SocketResourceManagerInterface> | 66 scoped_ptr<SocketResourceManagerInterface> |
| 67 TCPServerSocketAsyncApiFunction::CreateSocketResourceManager() { | 67 TCPServerSocketAsyncApiFunction::CreateSocketResourceManager() { |
| 68 return scoped_ptr<SocketResourceManagerInterface>( | 68 return scoped_ptr<SocketResourceManagerInterface>( |
| 69 new SocketResourceManager<ResumableTCPServerSocket>()).Pass(); | 69 new SocketResourceManager<ResumableTCPServerSocket>()).Pass(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 ResumableTCPServerSocket* TCPServerSocketAsyncApiFunction::GetTcpSocket( | 72 ResumableTCPServerSocket* TCPServerSocketAsyncApiFunction::GetTcpSocket( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 SetSocketProperties(socket, ¶ms_.get()->properties); | 119 SetSocketProperties(socket, ¶ms_.get()->properties); |
| 120 results_ = sockets_tcp_server::Update::Results::Create(); | 120 results_ = sockets_tcp_server::Update::Results::Create(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 SocketsTcpServerSetPausedFunction::SocketsTcpServerSetPausedFunction() | 123 SocketsTcpServerSetPausedFunction::SocketsTcpServerSetPausedFunction() |
| 124 : socket_event_dispatcher_(NULL) {} | 124 : socket_event_dispatcher_(NULL) {} |
| 125 | 125 |
| 126 SocketsTcpServerSetPausedFunction::~SocketsTcpServerSetPausedFunction() {} | 126 SocketsTcpServerSetPausedFunction::~SocketsTcpServerSetPausedFunction() {} |
| 127 | 127 |
| 128 bool SocketsTcpServerSetPausedFunction::Prepare() { | 128 bool SocketsTcpServerSetPausedFunction::Prepare() { |
| 129 params_ = core_api::sockets_tcp_server::SetPaused::Params::Create(*args_); | 129 params_ = api::sockets_tcp_server::SetPaused::Params::Create(*args_); |
| 130 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 130 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 131 | 131 |
| 132 socket_event_dispatcher_ = | 132 socket_event_dispatcher_ = |
| 133 TCPServerSocketEventDispatcher::Get(browser_context()); | 133 TCPServerSocketEventDispatcher::Get(browser_context()); |
| 134 DCHECK(socket_event_dispatcher_) | 134 DCHECK(socket_event_dispatcher_) |
| 135 << "There is no socket event dispatcher. " | 135 << "There is no socket event dispatcher. " |
| 136 "If this assertion is failing during a test, then it is likely that " | 136 "If this assertion is failing during a test, then it is likely that " |
| 137 "TestExtensionSystem is failing to provide an instance of " | 137 "TestExtensionSystem is failing to provide an instance of " |
| 138 "TCPServerSocketEventDispatcher."; | 138 "TCPServerSocketEventDispatcher."; |
| 139 return socket_event_dispatcher_ != NULL; | 139 return socket_event_dispatcher_ != NULL; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 156 | 156 |
| 157 results_ = sockets_tcp_server::SetPaused::Results::Create(); | 157 results_ = sockets_tcp_server::SetPaused::Results::Create(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 SocketsTcpServerListenFunction::SocketsTcpServerListenFunction() | 160 SocketsTcpServerListenFunction::SocketsTcpServerListenFunction() |
| 161 : socket_event_dispatcher_(NULL) {} | 161 : socket_event_dispatcher_(NULL) {} |
| 162 | 162 |
| 163 SocketsTcpServerListenFunction::~SocketsTcpServerListenFunction() {} | 163 SocketsTcpServerListenFunction::~SocketsTcpServerListenFunction() {} |
| 164 | 164 |
| 165 bool SocketsTcpServerListenFunction::Prepare() { | 165 bool SocketsTcpServerListenFunction::Prepare() { |
| 166 params_ = core_api::sockets_tcp_server::Listen::Params::Create(*args_); | 166 params_ = api::sockets_tcp_server::Listen::Params::Create(*args_); |
| 167 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 167 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 168 | 168 |
| 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; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 int socket_id = *it; | 290 int socket_id = *it; |
| 291 ResumableTCPServerSocket* socket = GetTcpSocket(socket_id); | 291 ResumableTCPServerSocket* socket = GetTcpSocket(socket_id); |
| 292 if (socket) { | 292 if (socket) { |
| 293 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 293 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 } | 296 } |
| 297 results_ = sockets_tcp_server::GetSockets::Results::Create(socket_infos); | 297 results_ = sockets_tcp_server::GetSockets::Results::Create(socket_infos); |
| 298 } | 298 } |
| 299 | 299 |
| 300 } // namespace core_api | 300 } // namespace api |
| 301 } // namespace extensions | 301 } // namespace extensions |
| OLD | NEW |