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) { |
} |