OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h" | 5 #include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/socket/tcp_socket.h" | 7 #include "chrome/browser/extensions/api/socket/tcp_socket.h" |
8 #include "chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.
h" | 8 #include "chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.
h" |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" | 9 #include "chrome/common/extensions/api/sockets/sockets_manifest_data.h" |
11 #include "content/public/common/socket_permission_request.h" | 10 #include "content/public/common/socket_permission_request.h" |
12 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
13 | 12 |
14 using extensions::ResumableTCPSocket; | 13 using extensions::ResumableTCPSocket; |
15 using extensions::api::sockets_tcp::SocketInfo; | 14 using extensions::api::sockets_tcp::SocketInfo; |
16 using extensions::api::sockets_tcp::SocketProperties; | 15 using extensions::api::sockets_tcp::SocketProperties; |
17 | 16 |
18 namespace { | 17 namespace { |
19 | 18 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 151 |
153 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() | 152 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() |
154 : socket_event_dispatcher_(NULL) {} | 153 : socket_event_dispatcher_(NULL) {} |
155 | 154 |
156 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} | 155 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} |
157 | 156 |
158 bool SocketsTcpSetPausedFunction::Prepare() { | 157 bool SocketsTcpSetPausedFunction::Prepare() { |
159 params_ = api::sockets_tcp::SetPaused::Params::Create(*args_); | 158 params_ = api::sockets_tcp::SetPaused::Params::Create(*args_); |
160 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 159 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
161 | 160 |
162 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(GetProfile()); | 161 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); |
163 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " | 162 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " |
164 "If this assertion is failing during a test, then it is likely that " | 163 "If this assertion is failing during a test, then it is likely that " |
165 "TestExtensionSystem is failing to provide an instance of " | 164 "TestExtensionSystem is failing to provide an instance of " |
166 "TCPSocketEventDispatcher."; | 165 "TCPSocketEventDispatcher."; |
167 return socket_event_dispatcher_ != NULL; | 166 return socket_event_dispatcher_ != NULL; |
168 } | 167 } |
169 | 168 |
170 void SocketsTcpSetPausedFunction::Work() { | 169 void SocketsTcpSetPausedFunction::Work() { |
171 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 170 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
172 if (!socket) { | 171 if (!socket) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 236 |
238 SocketsTcpConnectFunction::SocketsTcpConnectFunction() | 237 SocketsTcpConnectFunction::SocketsTcpConnectFunction() |
239 : socket_event_dispatcher_(NULL) {} | 238 : socket_event_dispatcher_(NULL) {} |
240 | 239 |
241 SocketsTcpConnectFunction::~SocketsTcpConnectFunction() {} | 240 SocketsTcpConnectFunction::~SocketsTcpConnectFunction() {} |
242 | 241 |
243 bool SocketsTcpConnectFunction::Prepare() { | 242 bool SocketsTcpConnectFunction::Prepare() { |
244 params_ = sockets_tcp::Connect::Params::Create(*args_); | 243 params_ = sockets_tcp::Connect::Params::Create(*args_); |
245 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 244 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
246 | 245 |
247 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(GetProfile()); | 246 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); |
248 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " | 247 DCHECK(socket_event_dispatcher_) << "There is no socket event dispatcher. " |
249 "If this assertion is failing during a test, then it is likely that " | 248 "If this assertion is failing during a test, then it is likely that " |
250 "TestExtensionSystem is failing to provide an instance of " | 249 "TestExtensionSystem is failing to provide an instance of " |
251 "TCPSocketEventDispatcher."; | 250 "TCPSocketEventDispatcher."; |
252 return socket_event_dispatcher_ != NULL; | 251 return socket_event_dispatcher_ != NULL; |
253 } | 252 } |
254 | 253 |
255 void SocketsTcpConnectFunction::AsyncWorkStart() { | 254 void SocketsTcpConnectFunction::AsyncWorkStart() { |
256 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 255 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
257 if (!socket) { | 256 if (!socket) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 if (socket) { | 435 if (socket) { |
437 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 436 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
438 } | 437 } |
439 } | 438 } |
440 } | 439 } |
441 results_ = sockets_tcp::GetSockets::Results::Create(socket_infos); | 440 results_ = sockets_tcp::GetSockets::Results::Create(socket_infos); |
442 } | 441 } |
443 | 442 |
444 } // namespace api | 443 } // namespace api |
445 } // namespace extensions | 444 } // namespace extensions |
OLD | NEW |