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

Unified Diff: webkit/plugins/ppapi/ppb_websocket_impl.cc

Issue 8956008: WebSocket Pepper API: C++ utility class implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 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
« no previous file with comments | « webkit/plugins/ppapi/ppb_websocket_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/ppb_websocket_impl.cc
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.cc b/webkit/plugins/ppapi/ppb_websocket_impl.cc
index 825a4e94f92ee5cab56ebfcb8042cc66041ad07f..b3fb63ed9ec721c5c087fa3bf27c47d93ef3fadb 100644
--- a/webkit/plugins/ppapi/ppb_websocket_impl.cc
+++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc
@@ -79,22 +79,26 @@ PPB_WebSocket_Impl::PPB_WebSocket_Impl(PP_Instance instance)
: Resource(instance),
state_(PP_WEBSOCKETREADYSTATE_INVALID_DEV),
error_was_received_(false),
+ connect_callback_(PP_BlockUntilComplete()),
+ receive_callback_(PP_BlockUntilComplete()),
receive_callback_var_(NULL),
wait_for_receive_(false),
+ close_callback_(PP_BlockUntilComplete()),
close_code_(0),
close_was_clean_(PP_FALSE),
buffered_amount_(0),
buffered_amount_after_close_(0) {
Takashi Toyoshima 2011/12/22 07:56:29 Replace initializers for callbacks by my ongoing c
- connect_callback_.func = NULL;
- connect_callback_.user_data = NULL;
- receive_callback_.func = NULL;
- receive_callback_.user_data = NULL;
- close_callback_.func = NULL;
- close_callback_.user_data = NULL;
empty_string_ = new StringVar("", 0);
}
PPB_WebSocket_Impl::~PPB_WebSocket_Impl() {
+ // Abort outstanding processings having a callback.
+ if (connect_callback_.func)
+ PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_ABORTED);
+ AbortOutstandingReceive();
+ if (close_callback_.func)
+ PP_RunAndClearCompletionCallback(&close_callback_, PP_ERROR_ABORTED);
+
if (websocket_.get())
websocket_->disconnect();
@@ -262,11 +266,7 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code,
}
// Abort ongoing receive.
- if (wait_for_receive_) {
- wait_for_receive_ = false;
- receive_callback_var_ = NULL;
- PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_ABORTED);
- }
+ AbortOutstandingReceive();
// Close connection.
state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV;
@@ -484,11 +484,7 @@ void PPB_WebSocket_Impl::didClose(unsigned long unhandled_buffered_amount,
if (state == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV)
PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_FAILED);
- if (wait_for_receive_) {
- wait_for_receive_ = false;
- receive_callback_var_ = NULL;
- PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_ABORTED);
- }
+ AbortOutstandingReceive();
if (state == PP_WEBSOCKETREADYSTATE_CLOSING_DEV)
PP_RunAndClearCompletionCallback(&close_callback_, PP_OK);
@@ -509,5 +505,13 @@ int32_t PPB_WebSocket_Impl::DoReceive() {
return PP_OK;
}
+void PPB_WebSocket_Impl::AbortOutstandingReceive() {
+ if (!wait_for_receive_)
+ return;
+ wait_for_receive_ = false;
+ receive_callback_var_ = NULL;
+ PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_ABORTED);
+}
+
} // namespace ppapi
} // namespace webkit
« no previous file with comments | « webkit/plugins/ppapi/ppb_websocket_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698