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

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: fix completion callback leaks? 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
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 48bc1f56580a883572947b659e5b2d5f67e5657d..b3fb63ed9ec721c5c087fa3bf27c47d93ef3fadb 100644
--- a/webkit/plugins/ppapi/ppb_websocket_impl.cc
+++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc
@@ -79,8 +79,11 @@ 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),
@@ -89,6 +92,13 @@ PPB_WebSocket_Impl::PPB_WebSocket_Impl(PP_Instance instance)
}
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();
@@ -256,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;
@@ -478,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);
@@ -503,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
« ppapi/cpp/helper/dev/websocket_api_dev.cc ('K') | « 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