| 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/socket/socket_api.h" | 5 #include "extensions/browser/api/socket/socket_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 SocketAsyncApiFunction::~SocketAsyncApiFunction() {} | 69 SocketAsyncApiFunction::~SocketAsyncApiFunction() {} |
| 70 | 70 |
| 71 bool SocketAsyncApiFunction::PrePrepare() { | 71 bool SocketAsyncApiFunction::PrePrepare() { |
| 72 manager_ = CreateSocketResourceManager(); | 72 manager_ = CreateSocketResourceManager(); |
| 73 return manager_->SetBrowserContext(browser_context()); | 73 return manager_->SetBrowserContext(browser_context()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool SocketAsyncApiFunction::Respond() { return error_.empty(); } | 76 bool SocketAsyncApiFunction::Respond() { return error_.empty(); } |
| 77 | 77 |
| 78 scoped_ptr<SocketResourceManagerInterface> | 78 std::unique_ptr<SocketResourceManagerInterface> |
| 79 SocketAsyncApiFunction::CreateSocketResourceManager() { | 79 SocketAsyncApiFunction::CreateSocketResourceManager() { |
| 80 return scoped_ptr<SocketResourceManagerInterface>( | 80 return std::unique_ptr<SocketResourceManagerInterface>( |
| 81 new SocketResourceManager<Socket>()); | 81 new SocketResourceManager<Socket>()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 int SocketAsyncApiFunction::AddSocket(Socket* socket) { | 84 int SocketAsyncApiFunction::AddSocket(Socket* socket) { |
| 85 return manager_->Add(socket); | 85 return manager_->Add(socket); |
| 86 } | 86 } |
| 87 | 87 |
| 88 Socket* SocketAsyncApiFunction::GetSocket(int api_resource_id) { | 88 Socket* SocketAsyncApiFunction::GetSocket(int api_resource_id) { |
| 89 return manager_->Get(extension_->id(), api_resource_id); | 89 return manager_->Get(extension_->id(), api_resource_id); |
| 90 } | 90 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 #if defined(OS_CHROMEOS) | 133 #if defined(OS_CHROMEOS) |
| 134 | 134 |
| 135 void SocketAsyncApiFunction::OpenFirewallHoleOnUIThread( | 135 void SocketAsyncApiFunction::OpenFirewallHoleOnUIThread( |
| 136 AppFirewallHole::PortType type, | 136 AppFirewallHole::PortType type, |
| 137 uint16_t port, | 137 uint16_t port, |
| 138 int socket_id) { | 138 int socket_id) { |
| 139 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 139 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 140 AppFirewallHoleManager* manager = | 140 AppFirewallHoleManager* manager = |
| 141 AppFirewallHoleManager::Get(browser_context()); | 141 AppFirewallHoleManager::Get(browser_context()); |
| 142 scoped_ptr<AppFirewallHole, BrowserThread::DeleteOnUIThread> hole( | 142 std::unique_ptr<AppFirewallHole, BrowserThread::DeleteOnUIThread> hole( |
| 143 manager->Open(type, port, extension_id()).release()); | 143 manager->Open(type, port, extension_id()).release()); |
| 144 BrowserThread::PostTask( | 144 BrowserThread::PostTask( |
| 145 BrowserThread::IO, FROM_HERE, | 145 BrowserThread::IO, FROM_HERE, |
| 146 base::Bind(&SocketAsyncApiFunction::OnFirewallHoleOpened, this, socket_id, | 146 base::Bind(&SocketAsyncApiFunction::OnFirewallHoleOpened, this, socket_id, |
| 147 base::Passed(&hole))); | 147 base::Passed(&hole))); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void SocketAsyncApiFunction::OnFirewallHoleOpened( | 150 void SocketAsyncApiFunction::OnFirewallHoleOpened( |
| 151 int socket_id, | 151 int socket_id, |
| 152 scoped_ptr<AppFirewallHole, BrowserThread::DeleteOnUIThread> hole) { | 152 std::unique_ptr<AppFirewallHole, BrowserThread::DeleteOnUIThread> hole) { |
| 153 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 153 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 154 if (!hole) { | 154 if (!hole) { |
| 155 error_ = kFirewallFailure; | 155 error_ = kFirewallFailure; |
| 156 SetResult(new base::FundamentalValue(-1)); | 156 SetResult(new base::FundamentalValue(-1)); |
| 157 AsyncWorkCompleted(); | 157 AsyncWorkCompleted(); |
| 158 return; | 158 return; |
| 159 } | 159 } |
| 160 | 160 |
| 161 Socket* socket = GetSocket(socket_id); | 161 Socket* socket = GetSocket(socket_id); |
| 162 if (!socket) { | 162 if (!socket) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 void SocketAcceptFunction::AsyncWorkStart() { | 454 void SocketAcceptFunction::AsyncWorkStart() { |
| 455 Socket* socket = GetSocket(params_->socket_id); | 455 Socket* socket = GetSocket(params_->socket_id); |
| 456 if (socket) { | 456 if (socket) { |
| 457 socket->Accept(base::Bind(&SocketAcceptFunction::OnAccept, this)); | 457 socket->Accept(base::Bind(&SocketAcceptFunction::OnAccept, this)); |
| 458 } else { | 458 } else { |
| 459 error_ = kSocketNotFoundError; | 459 error_ = kSocketNotFoundError; |
| 460 OnAccept(-1, NULL); | 460 OnAccept(-1, NULL); |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 | 463 |
| 464 void SocketAcceptFunction::OnAccept(int result_code, | 464 void SocketAcceptFunction::OnAccept( |
| 465 scoped_ptr<net::TCPClientSocket> socket) { | 465 int result_code, |
| 466 std::unique_ptr<net::TCPClientSocket> socket) { |
| 466 base::DictionaryValue* result = new base::DictionaryValue(); | 467 base::DictionaryValue* result = new base::DictionaryValue(); |
| 467 result->SetInteger(kResultCodeKey, result_code); | 468 result->SetInteger(kResultCodeKey, result_code); |
| 468 if (socket) { | 469 if (socket) { |
| 469 Socket* client_socket = | 470 Socket* client_socket = |
| 470 new TCPSocket(std::move(socket), extension_id(), true); | 471 new TCPSocket(std::move(socket), extension_id(), true); |
| 471 result->SetInteger(kSocketIdKey, AddSocket(client_socket)); | 472 result->SetInteger(kSocketIdKey, AddSocket(client_socket)); |
| 472 } | 473 } |
| 473 SetResult(result); | 474 SetResult(result); |
| 474 | 475 |
| 475 AsyncWorkCompleted(); | 476 AsyncWorkCompleted(); |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 TLSSocket::UpgradeSocketToTLS( | 1052 TLSSocket::UpgradeSocketToTLS( |
| 1052 socket, | 1053 socket, |
| 1053 url_request_context->ssl_config_service(), | 1054 url_request_context->ssl_config_service(), |
| 1054 url_request_context->cert_verifier(), | 1055 url_request_context->cert_verifier(), |
| 1055 url_request_context->transport_security_state(), | 1056 url_request_context->transport_security_state(), |
| 1056 extension_id(), | 1057 extension_id(), |
| 1057 params_->options.get(), | 1058 params_->options.get(), |
| 1058 base::Bind(&SocketSecureFunction::TlsConnectDone, this)); | 1059 base::Bind(&SocketSecureFunction::TlsConnectDone, this)); |
| 1059 } | 1060 } |
| 1060 | 1061 |
| 1061 void SocketSecureFunction::TlsConnectDone(scoped_ptr<TLSSocket> socket, | 1062 void SocketSecureFunction::TlsConnectDone(std::unique_ptr<TLSSocket> socket, |
| 1062 int result) { | 1063 int result) { |
| 1063 // if an error occurred, socket MUST be NULL. | 1064 // if an error occurred, socket MUST be NULL. |
| 1064 DCHECK(result == net::OK || socket == NULL); | 1065 DCHECK(result == net::OK || socket == NULL); |
| 1065 | 1066 |
| 1066 if (socket && result == net::OK) { | 1067 if (socket && result == net::OK) { |
| 1067 ReplaceSocket(params_->socket_id, socket.release()); | 1068 ReplaceSocket(params_->socket_id, socket.release()); |
| 1068 } else { | 1069 } else { |
| 1069 RemoveSocket(params_->socket_id); | 1070 RemoveSocket(params_->socket_id); |
| 1070 error_ = net::ErrorToString(result); | 1071 error_ = net::ErrorToString(result); |
| 1071 } | 1072 } |
| 1072 | 1073 |
| 1073 results_ = api::socket::Secure::Results::Create(result); | 1074 results_ = api::socket::Secure::Results::Create(result); |
| 1074 AsyncWorkCompleted(); | 1075 AsyncWorkCompleted(); |
| 1075 } | 1076 } |
| 1076 | 1077 |
| 1077 } // namespace extensions | 1078 } // namespace extensions |
| OLD | NEW |