Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1639)

Unified Diff: chrome/browser/extensions/api/socket/socket_api.cc

Issue 76403004: An implementation of chrome.socket.secure(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made TLSSocket resumable, responses to sleevi's round-1 comments. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/socket/socket_api.cc
diff --git a/chrome/browser/extensions/api/socket/socket_api.cc b/chrome/browser/extensions/api/socket/socket_api.cc
index da173c2952ae873f8068a4db783838efd5bf2225..d9829e95bef5e72a7d380705cb63fdcf87381048 100644
--- a/chrome/browser/extensions/api/socket/socket_api.cc
+++ b/chrome/browser/extensions/api/socket/socket_api.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h"
#include "chrome/browser/extensions/api/socket/socket.h"
#include "chrome/browser/extensions/api/socket/tcp_socket.h"
+#include "chrome/browser/extensions/api/socket/tls_socket.h"
#include "chrome/browser/extensions/api/socket/udp_socket.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/io_thread.h"
@@ -76,6 +77,11 @@ Socket* SocketAsyncApiFunction::GetSocket(int api_resource_id) {
return manager_->Get(extension_->id(), api_resource_id);
}
+void SocketAsyncApiFunction::SetSocket(int api_resource_id,
+ Socket* socket) {
+ manager_->Set(extension_->id(), api_resource_id, socket);
+}
+
base::hash_set<int>* SocketAsyncApiFunction::GetSocketIds() {
return manager_->GetResourceIds(extension_->id());
}
@@ -239,6 +245,7 @@ void SocketConnectFunction::AfterDnsLookup(int lookup_result) {
}
void SocketConnectFunction::StartConnect() {
+ socket_->SetHostname(hostname_);
socket_->Connect(resolved_address_, port_,
base::Bind(&SocketConnectFunction::OnConnect, this));
}
@@ -896,4 +903,60 @@ void SocketGetJoinedGroupsFunction::Work() {
SetResult(values);
}
+SocketSecureFunction::SocketSecureFunction() {}
+SocketSecureFunction::~SocketSecureFunction() {}
+
+bool SocketSecureFunction::Prepare() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ params_ = api::socket::Secure::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params_.get());
+ url_request_getter_ = GetProfile()->GetRequestContext();
+ return true;
+}
+
+void SocketSecureFunction::Work() {
rpaquay 2013/12/09 23:02:03 Using "Work" is slightly different than the conven
lally 2013/12/12 02:31:39 Done.
+ base::Value *result;
+ async_completed_needs_invocation_ = false;
+ const char * error_str = TLSSocket::SecureTCPSocket(
rpaquay 2013/12/09 23:02:03 There are issues with the way error handling is do
lally 2013/12/12 02:31:39 Done.
+ GetSocket(params_->socket_id),
+ GetProfile(),
+ url_request_getter_,
+ extension_id(),
+ params_->options.get(),
+ base::Bind(&SocketSecureFunction::TlsConnectDone, this),
+ &result);
+ if (error_str) {
+ error_ = error_str;
+ }
+ SetResult(result);
+
+ if (async_completed_needs_invocation_) {
+ AsyncWorkCompleted();
+ async_completed_needs_invocation_ = false;
+ } else {
+ async_completed_needs_invocation_ = true;
+ }
+}
+
+// Override the regular implementation, which would call AsyncWorkCompleted
+// immediately after Work().
+void SocketSecureFunction::AsyncWorkStart() {
+ Work();
+}
+
+void SocketSecureFunction::TlsConnectDone(Socket *sock, int result) {
+ if (sock) {
+ SetSocket(params_->socket_id, sock);
+ } else {
+ RemoveSocket(params_->socket_id);
+ }
+
+ if (async_completed_needs_invocation_) {
rpaquay 2013/12/09 23:02:03 As mentioned above, the code here should be someth
lally 2013/12/12 02:31:39 Done.
+ AsyncWorkCompleted();
+ async_completed_needs_invocation_ = false;
+ } else {
+ async_completed_needs_invocation_ = true;
+ }
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698