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

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

Issue 10827390: Implement chrome.socket.bind/listen/accept for TCP server socket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months 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 951f60005d772158d1fd1507a95b2453c27103ae..6e5aa02a4186e989bea5c21ecc4e540ddcc2b94c 100644
--- a/chrome/browser/extensions/api/socket/socket_api.cc
+++ b/chrome/browser/extensions/api/socket/socket_api.cc
@@ -224,6 +224,59 @@ void SocketBindFunction::Work() {
SetResult(Value::CreateIntegerValue(result));
}
+bool SocketListenFunction::Prepare() {
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_));
miket_OOO 2012/08/31 23:18:01 You can do an EXTENSION_FUNCTION_VALIDATE(params_.
justinlin 2012/09/11 04:32:32 Done.
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &backlog_));
+ return true;
+}
+
+void SocketListenFunction::Work() {
+ int result = -1;
+ Socket* socket = manager_->Get(socket_id_);
+ if (socket)
+ result = socket->Listen(backlog_);
+ else
+ error_ = kSocketNotFoundError;
+
+ SetResult(Value::CreateIntegerValue(result));
+}
+
+SocketAcceptFunction::SocketAcceptFunction()
+ : params_(NULL),
+ event_notifier_(NULL),
+ src_id_(-1) {
+
+}
miket_OOO 2012/08/31 23:18:01 vertical whitespace
justinlin 2012/09/11 04:32:32 Done.
+SocketAcceptFunction::~SocketAcceptFunction() {}
+
+bool SocketAcceptFunction::Prepare() {
+ params_ = api::socket::Accept::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params_.get());
+
+ event_notifier_ = CreateEventNotifier(src_id_);
+ return true;
+}
+
+void SocketAcceptFunction::Work() {
+ Socket* socket = manager_->Get(params_->socket_id);
+ if (socket) {
+ socket->Accept(base::Bind(&SocketAcceptFunction::OnAccept, this));
+ } else {
+ error_ = kSocketNotFoundError;
+ }
+}
+
+void SocketAcceptFunction::OnAccept(int result_code,
+ net::TCPClientSocket *socket) {
+ DCHECK(socket);
+ Socket *client_socket = new TCPSocket(event_notifier_, socket);
+
+ DictionaryValue* result = new DictionaryValue();
+ result->SetInteger(kResultCodeKey, result_code);
+ result->SetInteger(kSocketIdKey, manager_->Add(client_socket));
miket_OOO 2012/08/31 23:18:01 You might want to add a note to http://code.google
justinlin 2012/09/11 04:32:32 I'll keep an eye out for that issue. I'm not entir
+ SetResult(result);
+}
+
SocketReadFunction::SocketReadFunction()
: params_(NULL) {
}

Powered by Google App Engine
This is Rietveld 408576698