| 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/sockets_tcp_api.h" | 5 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" |
| 6 | 6 |
| 7 #include "content/public/browser/browser_context.h" | 7 #include "content/public/browser/browser_context.h" |
| 8 #include "content/public/common/socket_permission_request.h" | 8 #include "content/public/common/socket_permission_request.h" |
| 9 #include "extensions/browser/api/socket/tcp_socket.h" | 9 #include "extensions/browser/api/socket/tcp_socket.h" |
| 10 #include "extensions/browser/api/socket/tls_socket.h" | 10 #include "extensions/browser/api/socket/tls_socket.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (!socket) { | 150 if (!socket) { |
| 151 error_ = kSocketNotFoundError; | 151 error_ = kSocketNotFoundError; |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 | 154 |
| 155 SetSocketProperties(socket, ¶ms_.get()->properties); | 155 SetSocketProperties(socket, ¶ms_.get()->properties); |
| 156 results_ = sockets_tcp::Update::Results::Create(); | 156 results_ = sockets_tcp::Update::Results::Create(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() | 159 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() |
| 160 : socket_event_dispatcher_(NULL) {} | 160 : socket_event_dispatcher_(nullptr) { |
| 161 } |
| 161 | 162 |
| 162 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} | 163 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} |
| 163 | 164 |
| 164 bool SocketsTcpSetPausedFunction::Prepare() { | 165 bool SocketsTcpSetPausedFunction::Prepare() { |
| 165 params_ = core_api::sockets_tcp::SetPaused::Params::Create(*args_); | 166 params_ = core_api::sockets_tcp::SetPaused::Params::Create(*args_); |
| 166 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 167 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 167 | 168 |
| 168 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); | 169 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); |
| 169 DCHECK(socket_event_dispatcher_) | 170 DCHECK(socket_event_dispatcher_) |
| 170 << "There is no socket event dispatcher. " | 171 << "There is no socket event dispatcher. " |
| 171 "If this assertion is failing during a test, then it is likely that " | 172 "If this assertion is failing during a test, then it is likely that " |
| 172 "TestExtensionSystem is failing to provide an instance of " | 173 "TestExtensionSystem is failing to provide an instance of " |
| 173 "TCPSocketEventDispatcher."; | 174 "TCPSocketEventDispatcher."; |
| 174 return socket_event_dispatcher_ != NULL; | 175 return socket_event_dispatcher_ != nullptr; |
| 175 } | 176 } |
| 176 | 177 |
| 177 void SocketsTcpSetPausedFunction::Work() { | 178 void SocketsTcpSetPausedFunction::Work() { |
| 178 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 179 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 179 if (!socket) { | 180 if (!socket) { |
| 180 error_ = kSocketNotFoundError; | 181 error_ = kSocketNotFoundError; |
| 181 return; | 182 return; |
| 182 } | 183 } |
| 183 | 184 |
| 184 if (socket->paused() != params_->paused) { | 185 if (socket->paused() != params_->paused) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } | 237 } |
| 237 | 238 |
| 238 bool success = socket->SetNoDelay(params_->no_delay); | 239 bool success = socket->SetNoDelay(params_->no_delay); |
| 239 int net_result = (success ? net::OK : net::ERR_FAILED); | 240 int net_result = (success ? net::OK : net::ERR_FAILED); |
| 240 if (net_result != net::OK) | 241 if (net_result != net::OK) |
| 241 error_ = net::ErrorToString(net_result); | 242 error_ = net::ErrorToString(net_result); |
| 242 results_ = sockets_tcp::SetNoDelay::Results::Create(net_result); | 243 results_ = sockets_tcp::SetNoDelay::Results::Create(net_result); |
| 243 } | 244 } |
| 244 | 245 |
| 245 SocketsTcpConnectFunction::SocketsTcpConnectFunction() | 246 SocketsTcpConnectFunction::SocketsTcpConnectFunction() |
| 246 : socket_event_dispatcher_(NULL) {} | 247 : socket_event_dispatcher_(nullptr) { |
| 248 } |
| 247 | 249 |
| 248 SocketsTcpConnectFunction::~SocketsTcpConnectFunction() {} | 250 SocketsTcpConnectFunction::~SocketsTcpConnectFunction() {} |
| 249 | 251 |
| 250 bool SocketsTcpConnectFunction::Prepare() { | 252 bool SocketsTcpConnectFunction::Prepare() { |
| 251 params_ = sockets_tcp::Connect::Params::Create(*args_); | 253 params_ = sockets_tcp::Connect::Params::Create(*args_); |
| 252 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 254 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 253 | 255 |
| 254 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); | 256 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); |
| 255 DCHECK(socket_event_dispatcher_) | 257 DCHECK(socket_event_dispatcher_) |
| 256 << "There is no socket event dispatcher. " | 258 << "There is no socket event dispatcher. " |
| 257 "If this assertion is failing during a test, then it is likely that " | 259 "If this assertion is failing during a test, then it is likely that " |
| 258 "TestExtensionSystem is failing to provide an instance of " | 260 "TestExtensionSystem is failing to provide an instance of " |
| 259 "TCPSocketEventDispatcher."; | 261 "TCPSocketEventDispatcher."; |
| 260 return socket_event_dispatcher_ != NULL; | 262 return socket_event_dispatcher_ != nullptr; |
| 261 } | 263 } |
| 262 | 264 |
| 263 void SocketsTcpConnectFunction::AsyncWorkStart() { | 265 void SocketsTcpConnectFunction::AsyncWorkStart() { |
| 264 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 266 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 265 if (!socket) { | 267 if (!socket) { |
| 266 error_ = kSocketNotFoundError; | 268 error_ = kSocketNotFoundError; |
| 267 AsyncWorkCompleted(); | 269 AsyncWorkCompleted(); |
| 268 return; | 270 return; |
| 269 } | 271 } |
| 270 | 272 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 431 |
| 430 SocketsTcpGetSocketsFunction::SocketsTcpGetSocketsFunction() {} | 432 SocketsTcpGetSocketsFunction::SocketsTcpGetSocketsFunction() {} |
| 431 | 433 |
| 432 SocketsTcpGetSocketsFunction::~SocketsTcpGetSocketsFunction() {} | 434 SocketsTcpGetSocketsFunction::~SocketsTcpGetSocketsFunction() {} |
| 433 | 435 |
| 434 bool SocketsTcpGetSocketsFunction::Prepare() { return true; } | 436 bool SocketsTcpGetSocketsFunction::Prepare() { return true; } |
| 435 | 437 |
| 436 void SocketsTcpGetSocketsFunction::Work() { | 438 void SocketsTcpGetSocketsFunction::Work() { |
| 437 std::vector<linked_ptr<sockets_tcp::SocketInfo> > socket_infos; | 439 std::vector<linked_ptr<sockets_tcp::SocketInfo> > socket_infos; |
| 438 base::hash_set<int>* resource_ids = GetSocketIds(); | 440 base::hash_set<int>* resource_ids = GetSocketIds(); |
| 439 if (resource_ids != NULL) { | 441 if (resource_ids != nullptr) { |
| 440 for (base::hash_set<int>::iterator it = resource_ids->begin(); | 442 for (base::hash_set<int>::iterator it = resource_ids->begin(); |
| 441 it != resource_ids->end(); | 443 it != resource_ids->end(); |
| 442 ++it) { | 444 ++it) { |
| 443 int socket_id = *it; | 445 int socket_id = *it; |
| 444 ResumableTCPSocket* socket = GetTcpSocket(socket_id); | 446 ResumableTCPSocket* socket = GetTcpSocket(socket_id); |
| 445 if (socket) { | 447 if (socket) { |
| 446 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); | 448 socket_infos.push_back(CreateSocketInfo(socket_id, socket)); |
| 447 } | 449 } |
| 448 } | 450 } |
| 449 } | 451 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 476 AsyncWorkCompleted(); | 478 AsyncWorkCompleted(); |
| 477 return; | 479 return; |
| 478 } | 480 } |
| 479 | 481 |
| 480 paused_ = socket->paused(); | 482 paused_ = socket->paused(); |
| 481 persistent_ = socket->persistent(); | 483 persistent_ = socket->persistent(); |
| 482 | 484 |
| 483 // Make sure it's a connected TCP client socket. Error out if it's already | 485 // Make sure it's a connected TCP client socket. Error out if it's already |
| 484 // secure()'d. | 486 // secure()'d. |
| 485 if (socket->GetSocketType() != Socket::TYPE_TCP || | 487 if (socket->GetSocketType() != Socket::TYPE_TCP || |
| 486 socket->ClientStream() == NULL) { | 488 socket->ClientStream() == nullptr) { |
| 487 SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT)); | 489 SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT)); |
| 488 error_ = kInvalidSocketStateError; | 490 error_ = kInvalidSocketStateError; |
| 489 AsyncWorkCompleted(); | 491 AsyncWorkCompleted(); |
| 490 return; | 492 return; |
| 491 } | 493 } |
| 492 | 494 |
| 493 if (!socket->IsConnected()) { | 495 if (!socket->IsConnected()) { |
| 494 SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT)); | 496 SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT)); |
| 495 error_ = kSocketNotConnectedError; | 497 error_ = kSocketNotConnectedError; |
| 496 AsyncWorkCompleted(); | 498 AsyncWorkCompleted(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 522 url_request_context->cert_verifier(), | 524 url_request_context->cert_verifier(), |
| 523 url_request_context->transport_security_state(), | 525 url_request_context->transport_security_state(), |
| 524 extension_id(), | 526 extension_id(), |
| 525 &legacy_params, | 527 &legacy_params, |
| 526 base::Bind(&SocketsTcpSecureFunction::TlsConnectDone, this)); | 528 base::Bind(&SocketsTcpSecureFunction::TlsConnectDone, this)); |
| 527 } | 529 } |
| 528 | 530 |
| 529 void SocketsTcpSecureFunction::TlsConnectDone(scoped_ptr<TLSSocket> socket, | 531 void SocketsTcpSecureFunction::TlsConnectDone(scoped_ptr<TLSSocket> socket, |
| 530 int result) { | 532 int result) { |
| 531 // If an error occurred, socket MUST be NULL | 533 // If an error occurred, socket MUST be NULL |
| 532 DCHECK(result == net::OK || socket == NULL); | 534 DCHECK(result == net::OK || socket == nullptr); |
| 533 | 535 |
| 534 if (socket && result == net::OK) { | 536 if (socket && result == net::OK) { |
| 535 socket->set_persistent(persistent_); | 537 socket->set_persistent(persistent_); |
| 536 socket->set_paused(paused_); | 538 socket->set_paused(paused_); |
| 537 ReplaceSocket(params_->socket_id, socket.release()); | 539 ReplaceSocket(params_->socket_id, socket.release()); |
| 538 } else { | 540 } else { |
| 539 RemoveSocket(params_->socket_id); | 541 RemoveSocket(params_->socket_id); |
| 540 error_ = net::ErrorToString(result); | 542 error_ = net::ErrorToString(result); |
| 541 } | 543 } |
| 542 | 544 |
| 543 results_ = core_api::sockets_tcp::Secure::Results::Create(result); | 545 results_ = core_api::sockets_tcp::Secure::Results::Create(result); |
| 544 AsyncWorkCompleted(); | 546 AsyncWorkCompleted(); |
| 545 } | 547 } |
| 546 | 548 |
| 547 } // namespace api | 549 } // namespace api |
| 548 } // namespace extensions | 550 } // namespace extensions |
| OLD | NEW |