summaryrefslogtreecommitdiffstats
path: root/webkit/plugins
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-06 23:05:05 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-06 23:05:05 +0000
commit1bb503a5a20170764117a121007aafb29f306355 (patch)
tree0444f45fc05a75310b932bd74eaab3a95754b8d4 /webkit/plugins
parentfcd36fc95d953e44731164b0568e87bf472aa4de (diff)
downloadchromium_src-1bb503a5a20170764117a121007aafb29f306355.zip
chromium_src-1bb503a5a20170764117a121007aafb29f306355.tar.gz
chromium_src-1bb503a5a20170764117a121007aafb29f306355.tar.bz2
Convert callers to use the new TrackedCallback.
This converts callers in webkit/plugins/ppapi that used raw PP_CompletionCallbacks to use the new TrackedCallback code. Review URL: http://codereview.chromium.org/9015013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116763 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins')
-rw-r--r--webkit/plugins/ppapi/audio_helper.cc24
-rw-r--r--webkit/plugins/ppapi/audio_helper.h11
-rw-r--r--webkit/plugins/ppapi/ppb_audio_impl.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_audio_input_impl.cc3
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.cc7
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.h16
-rw-r--r--webkit/plugins/ppapi/ppb_websocket_impl.cc38
-rw-r--r--webkit/plugins/ppapi/ppb_websocket_impl.h7
8 files changed, 54 insertions, 55 deletions
diff --git a/webkit/plugins/ppapi/audio_helper.cc b/webkit/plugins/ppapi/audio_helper.cc
index a077e5b..4a04f82 100644
--- a/webkit/plugins/ppapi/audio_helper.cc
+++ b/webkit/plugins/ppapi/audio_helper.cc
@@ -7,24 +7,17 @@
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/resource_helper.h"
+using ppapi::TrackedCallback;
+
namespace webkit {
namespace ppapi {
// AudioHelper -----------------------------------------------------------------
-AudioHelper::AudioHelper()
- : create_callback_pending_(false),
- shared_memory_size_for_create_callback_(0) {
- create_callback_ = PP_MakeCompletionCallback(NULL, NULL);
+AudioHelper::AudioHelper() {
}
AudioHelper::~AudioHelper() {
- // If the completion callback hasn't fired yet, do so here
- // with an error condition.
- if (create_callback_pending_) {
- PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED);
- create_callback_pending_ = false;
- }
}
int32_t AudioHelper::GetSyncSocketImpl(int* sync_socket) {
@@ -61,7 +54,7 @@ void AudioHelper::StreamCreated(
base::SharedMemoryHandle shared_memory_handle,
size_t shared_memory_size,
base::SyncSocket::Handle socket_handle) {
- if (create_callback_pending_) {
+ if (TrackedCallback::IsPending(create_callback_)) {
// Trusted side of proxy can specify a callback to recieve handles. In
// this case we don't need to map any data or start the thread since it
// will be handled by the proxy.
@@ -70,8 +63,7 @@ void AudioHelper::StreamCreated(
shared_memory_size_for_create_callback_ = shared_memory_size;
socket_for_create_callback_.reset(new base::SyncSocket(socket_handle));
- PP_RunCompletionCallback(&create_callback_, 0);
- create_callback_pending_ = false;
+ ::ppapi::TrackedCallback::ClearAndRun(&create_callback_, PP_OK);
// It might be nice to close the handles here to free up some system
// resources, but we can't since there's a race condition. The handles must
@@ -85,9 +77,9 @@ void AudioHelper::StreamCreated(
}
}
-void AudioHelper::SetCallbackInfo(bool create_callback_pending,
- PP_CompletionCallback create_callback) {
- create_callback_pending_ = create_callback_pending;
+void AudioHelper::SetCreateCallback(
+ scoped_refptr< ::ppapi::TrackedCallback> create_callback) {
+ DCHECK(!TrackedCallback::IsPending(create_callback_));
create_callback_ = create_callback;
}
diff --git a/webkit/plugins/ppapi/audio_helper.h b/webkit/plugins/ppapi/audio_helper.h
index 5d5df54..2f8b511 100644
--- a/webkit/plugins/ppapi/audio_helper.h
+++ b/webkit/plugins/ppapi/audio_helper.h
@@ -12,6 +12,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/scoped_pp_resource.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
@@ -28,8 +29,8 @@ class AudioHelper : public PluginDelegate::PlatformAudioCommonClient {
size_t shared_memory_size_,
base::SyncSocket::Handle socket) OVERRIDE;
- void SetCallbackInfo(bool create_callback_pending,
- PP_CompletionCallback create_callback);
+ void SetCreateCallback(
+ scoped_refptr< ::ppapi::TrackedCallback> create_callback);
protected:
// TODO(viettrungluu): This is all very poorly thought out. Refactor.
@@ -44,11 +45,7 @@ class AudioHelper : public PluginDelegate::PlatformAudioCommonClient {
base::SyncSocket::Handle socket_handle) = 0;
private:
- // Is a create callback pending to fire?
- bool create_callback_pending_;
-
- // Trusted callback invoked from StreamCreated.
- PP_CompletionCallback create_callback_;
+ scoped_refptr< ::ppapi::TrackedCallback> create_callback_;
// When a create callback is being issued, these will save the info for
// querying from the callback. The proxy uses this to get the handles to the
diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc
index c92c9b1..9408897 100644
--- a/webkit/plugins/ppapi/ppb_audio_impl.cc
+++ b/webkit/plugins/ppapi/ppb_audio_impl.cc
@@ -20,6 +20,7 @@ using ppapi::PpapiGlobals;
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_Audio_API;
using ppapi::thunk::PPB_AudioConfig_API;
+using ppapi::TrackedCallback;
namespace webkit {
namespace ppapi {
@@ -131,7 +132,7 @@ int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config,
// At this point, we are guaranteeing ownership of the completion
// callback. Audio promises to fire the completion callback
// once and only once.
- SetCallbackInfo(true, create_callback);
+ SetCreateCallback(new TrackedCallback(this, create_callback));
return PP_OK_COMPLETIONPENDING;
}
diff --git a/webkit/plugins/ppapi/ppb_audio_input_impl.cc b/webkit/plugins/ppapi/ppb_audio_input_impl.cc
index 8b4c114..3f2a672 100644
--- a/webkit/plugins/ppapi/ppb_audio_input_impl.cc
+++ b/webkit/plugins/ppapi/ppb_audio_input_impl.cc
@@ -20,6 +20,7 @@ using ppapi::PpapiGlobals;
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_AudioInput_API;
using ppapi::thunk::PPB_AudioConfig_API;
+using ppapi::TrackedCallback;
namespace webkit {
namespace ppapi {
@@ -138,7 +139,7 @@ int32_t PPB_AudioInput_Impl::OpenTrusted(
// At this point, we are guaranteeing ownership of the completion
// callback. Audio promises to fire the completion callback
// once and only once.
- SetCallbackInfo(true, create_callback);
+ SetCreateCallback(new TrackedCallback(this, create_callback));
return PP_OK_COMPLETIONPENDING;
}
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
index caeef5c..027e8eb 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
@@ -33,6 +33,7 @@
using ppapi::thunk::EnterResourceNoLock;
using ppapi::thunk::PPB_ImageData_API;
+using ppapi::TrackedCallback;
namespace webkit {
namespace ppapi {
@@ -348,9 +349,11 @@ int32_t PPB_Graphics2D_Impl::Flush(PP_CompletionCallback callback) {
if (nothing_visible) {
// There's nothing visible to invalidate so just schedule the callback to
// execute in the next round of the message loop.
- ScheduleOffscreenCallback(FlushCallbackData(callback));
+ ScheduleOffscreenCallback(FlushCallbackData(
+ scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback))));
} else {
- unpainted_flush_callback_.Set(callback);
+ unpainted_flush_callback_.Set(
+ scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback)));
}
return PP_OK_COMPLETIONPENDING;
}
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
index 2cce83b..bfe530d 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
@@ -12,6 +12,7 @@
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/ppb_graphics_2d.h"
#include "ppapi/shared_impl/resource.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/ppb_graphics_2d_api.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h"
@@ -83,26 +84,29 @@ class PPB_Graphics2D_Impl : public ::ppapi::Resource,
Clear();
}
- explicit FlushCallbackData(const PP_CompletionCallback& callback) {
+ explicit FlushCallbackData(
+ scoped_refptr< ::ppapi::TrackedCallback> callback) {
Set(callback);
}
- bool is_null() const { return !callback_.func; }
+ bool is_null() const {
+ return !::ppapi::TrackedCallback::IsPending(callback_);
+ }
- void Set(const PP_CompletionCallback& callback) {
+ void Set(scoped_refptr< ::ppapi::TrackedCallback> callback) {
callback_ = callback;
}
void Clear() {
- callback_ = PP_MakeCompletionCallback(NULL, 0);
+ callback_ = NULL;
}
void Execute(int32_t result) {
- PP_RunAndClearCompletionCallback(&callback_, result);
+ ::ppapi::TrackedCallback::ClearAndRun(&callback_, result);
}
private:
- PP_CompletionCallback callback_;
+ scoped_refptr< ::ppapi::TrackedCallback> callback_;
};
// Called internally to execute the different queued commands. The
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.cc b/webkit/plugins/ppapi/ppb_websocket_impl.cc
index 1282b13..ef2d6dd 100644
--- a/webkit/plugins/ppapi/ppb_websocket_impl.cc
+++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc
@@ -33,6 +33,7 @@ using ppapi::ArrayBufferVar;
using ppapi::PpapiGlobals;
using ppapi::StringVar;
using ppapi::thunk::PPB_WebSocket_API;
+using ppapi::TrackedCallback;
using ppapi::VarTracker;
using WebKit::WebData;
using WebKit::WebDocument;
@@ -82,15 +83,9 @@ PPB_WebSocket_Impl::PPB_WebSocket_Impl(PP_Instance instance)
wait_for_receive_(false),
close_code_(0),
close_was_clean_(PP_FALSE),
+ empty_string_(new StringVar("", 0)),
buffered_amount_(0),
buffered_amount_after_close_(0) {
- 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() {
@@ -209,7 +204,7 @@ int32_t PPB_WebSocket_Impl::Connect(PP_Var url,
state_ = PP_WEBSOCKETREADYSTATE_CONNECTING_DEV;
// Install callback.
- connect_callback_ = callback;
+ connect_callback_ = new TrackedCallback(this, callback);
return PP_OK_COMPLETIONPENDING;
}
@@ -250,12 +245,14 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code,
return PP_ERROR_BLOCKS_MAIN_THREAD;
// Install |callback|.
- close_callback_ = callback;
+ close_callback_ = new TrackedCallback(this, callback);
// Abort ongoing connect.
if (state_ == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) {
state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV;
- PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_ABORTED);
+ // Need to do a "Post" to avoid reentering the plugin.
+ connect_callback_->PostAbort();
+ connect_callback_ = NULL;
websocket_->fail(
"WebSocket was closed before the connection was established.");
return PP_OK_COMPLETIONPENDING;
@@ -265,7 +262,10 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code,
if (wait_for_receive_) {
wait_for_receive_ = false;
receive_callback_var_ = NULL;
- PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_ABORTED);
+
+ // Need to do a "Post" to avoid reentering the plugin.
+ receive_callback_->PostAbort();
+ receive_callback_ = NULL;
}
// Close connection.
@@ -305,7 +305,7 @@ int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message,
// Or retain |message| as buffer to store and install |callback|.
wait_for_receive_ = true;
receive_callback_var_ = message;
- receive_callback_ = callback;
+ receive_callback_ = new TrackedCallback(this, callback);
return PP_OK_COMPLETIONPENDING;
}
@@ -422,7 +422,7 @@ PP_Var PPB_WebSocket_Impl::GetURL() {
void PPB_WebSocket_Impl::didConnect() {
DCHECK_EQ(PP_WEBSOCKETREADYSTATE_CONNECTING_DEV, state_);
state_ = PP_WEBSOCKETREADYSTATE_OPEN_DEV;
- PP_RunAndClearCompletionCallback(&connect_callback_, PP_OK);
+ TrackedCallback::ClearAndRun(&connect_callback_, PP_OK);
}
void PPB_WebSocket_Impl::didReceiveMessage(const WebString& message) {
@@ -438,7 +438,7 @@ void PPB_WebSocket_Impl::didReceiveMessage(const WebString& message) {
if (!wait_for_receive_)
return;
- PP_RunAndClearCompletionCallback(&receive_callback_, DoReceive());
+ TrackedCallback::ClearAndRun(&receive_callback_, DoReceive());
}
void PPB_WebSocket_Impl::didReceiveBinaryData(const WebData& binaryData) {
@@ -457,7 +457,7 @@ void PPB_WebSocket_Impl::didReceiveBinaryData(const WebData& binaryData) {
if (!wait_for_receive_)
return;
- PP_RunAndClearCompletionCallback(&receive_callback_, DoReceive());
+ TrackedCallback::ClearAndRun(&receive_callback_, DoReceive());
}
void PPB_WebSocket_Impl::didReceiveMessageError() {
@@ -476,7 +476,7 @@ void PPB_WebSocket_Impl::didReceiveMessageError() {
// We must invoke the callback with error code here.
wait_for_receive_ = false;
receive_callback_var_ = NULL;
- PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_FAILED);
+ TrackedCallback::ClearAndRun(&receive_callback_, PP_ERROR_FAILED);
}
void PPB_WebSocket_Impl::didUpdateBufferedAmount(
@@ -515,16 +515,16 @@ void PPB_WebSocket_Impl::didClose(unsigned long unhandled_buffered_amount,
state_ = PP_WEBSOCKETREADYSTATE_CLOSED_DEV;
if (state == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV)
- PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_FAILED);
+ TrackedCallback::ClearAndRun(&connect_callback_, PP_ERROR_FAILED);
if (wait_for_receive_) {
wait_for_receive_ = false;
receive_callback_var_ = NULL;
- PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_ABORTED);
+ TrackedCallback::ClearAndAbort(&receive_callback_);
}
if (state == PP_WEBSOCKETREADYSTATE_CLOSING_DEV)
- PP_RunAndClearCompletionCallback(&close_callback_, PP_OK);
+ TrackedCallback::ClearAndRun(&close_callback_, PP_OK);
// Disconnect.
if (websocket_.get())
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.h b/webkit/plugins/ppapi/ppb_websocket_impl.h
index c33df7f..16544f1 100644
--- a/webkit/plugins/ppapi/ppb_websocket_impl.h
+++ b/webkit/plugins/ppapi/ppb_websocket_impl.h
@@ -9,6 +9,7 @@
#include "base/memory/scoped_ptr.h"
#include "ppapi/shared_impl/resource.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/ppb_websocket_api.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSocketClient.h"
@@ -75,15 +76,15 @@ class PPB_WebSocket_Impl : public ::ppapi::Resource,
PP_WebSocketReadyState_Dev state_;
bool error_was_received_;
- PP_CompletionCallback connect_callback_;
+ scoped_refptr< ::ppapi::TrackedCallback> connect_callback_;
- PP_CompletionCallback receive_callback_;
+ scoped_refptr< ::ppapi::TrackedCallback> receive_callback_;
PP_Var* receive_callback_var_;
bool wait_for_receive_;
// TODO(toyoshim): Use std::queue<Var> when it supports binary.
std::queue<PP_Var> received_messages_;
- PP_CompletionCallback close_callback_;
+ scoped_refptr< ::ppapi::TrackedCallback> close_callback_;
uint16_t close_code_;
scoped_refptr< ::ppapi::StringVar> close_reason_;
PP_Bool close_was_clean_;