summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 21:45:32 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 21:45:32 +0000
commitfa48a62baee2e842d6479d786eeb2899deb18681 (patch)
treef7c42adacc574277f60782622c00ac78a1d5f11e
parent83c2e233067108fb212ba4082ee02a9bff90d98d (diff)
downloadchromium_src-fa48a62baee2e842d6479d786eeb2899deb18681.zip
chromium_src-fa48a62baee2e842d6479d786eeb2899deb18681.tar.gz
chromium_src-fa48a62baee2e842d6479d786eeb2899deb18681.tar.bz2
Convert a bunch of pepper implementation to use base::Callback.
BUG=35223 TEST=ppapi ui_tests Review URL: http://codereview.chromium.org/8135010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104572 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/renderer/gpu/command_buffer_proxy.cc30
-rw-r--r--content/renderer/gpu/command_buffer_proxy.h15
-rw-r--r--content/renderer/gpu/renderer_gl_context.cc13
-rw-r--r--content/renderer/gpu/renderer_gl_context.h10
-rw-r--r--content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc12
-rw-r--r--content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h5
-rw-r--r--content/renderer/pepper_platform_context_3d_impl.cc18
-rw-r--r--content/renderer/pepper_platform_context_3d_impl.h10
-rw-r--r--content/renderer/pepper_plugin_delegate_impl.cc39
-rw-r--r--content/renderer/pepper_plugin_delegate_impl.h16
-rw-r--r--content/renderer/render_widget_fullscreen_pepper.cc12
-rw-r--r--content/renderer/render_widget_fullscreen_pepper.h4
-rw-r--r--webkit/plugins/ppapi/callbacks.cc8
-rw-r--r--webkit/plugins/ppapi/callbacks.h2
-rw-r--r--webkit/plugins/ppapi/message_channel.cc15
-rw-r--r--webkit/plugins/ppapi/message_channel.h5
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc6
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h6
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h27
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc3
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc5
-rw-r--r--webkit/plugins/ppapi/ppb_context_3d_impl.cc6
-rw-r--r--webkit/plugins/ppapi/ppb_context_3d_impl.h4
-rw-r--r--webkit/plugins/ppapi/ppb_file_io_impl.cc12
-rw-r--r--webkit/plugins/ppapi/ppb_file_io_impl.h3
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.cc10
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.h3
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_3d_impl.cc15
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_3d_impl.h5
-rw-r--r--webkit/plugins/ppapi/ppb_scrollbar_impl.cc13
-rw-r--r--webkit/plugins/ppapi/ppb_scrollbar_impl.h3
-rw-r--r--webkit/plugins/ppapi/ppb_surface_3d_impl.cc8
-rw-r--r--webkit/plugins/ppapi/ppb_surface_3d_impl.h2
-rw-r--r--webkit/plugins/ppapi/quota_file_io.cc7
-rw-r--r--webkit/plugins/ppapi/quota_file_io.h2
-rw-r--r--webkit/plugins/ppapi/quota_file_io_unittest.cc21
36 files changed, 203 insertions, 172 deletions
diff --git a/content/renderer/gpu/command_buffer_proxy.cc b/content/renderer/gpu/command_buffer_proxy.cc
index 907eb072..e1f9a66 100644
--- a/content/renderer/gpu/command_buffer_proxy.cc
+++ b/content/renderer/gpu/command_buffer_proxy.cc
@@ -73,22 +73,23 @@ void CommandBufferProxy::OnDestroyed(gpu::error::ContextLostReason reason) {
last_state_.error = gpu::error::kLostContext;
last_state_.context_lost_reason = reason;
- if (channel_error_callback_.get()) {
- channel_error_callback_->Run();
+ if (!channel_error_callback_.is_null()) {
+ channel_error_callback_.Run();
// Avoid calling the error callback more than once.
- channel_error_callback_.reset();
+ channel_error_callback_.Reset();
}
}
void CommandBufferProxy::OnEchoAck() {
DCHECK(!echo_tasks_.empty());
- Task* task = echo_tasks_.front().release();
+ base::Closure callback = echo_tasks_.front();
echo_tasks_.pop();
- task->Run();
+ callback.Run();
}
-void CommandBufferProxy::SetChannelErrorCallback(Callback0::Type* callback) {
- channel_error_callback_.reset(callback);
+void CommandBufferProxy::SetChannelErrorCallback(
+ const base::Closure& callback) {
+ channel_error_callback_ = callback;
}
bool CommandBufferProxy::Initialize(int32 size) {
@@ -335,9 +336,10 @@ void CommandBufferProxy::SetToken(int32 token) {
}
void CommandBufferProxy::OnNotifyRepaint() {
- if (notify_repaint_task_.get())
+ if (!notify_repaint_task_.is_null())
MessageLoop::current()->PostNonNestableTask(
- FROM_HERE, notify_repaint_task_.release());
+ FROM_HERE, notify_repaint_task_);
+ notify_repaint_task_.Reset();
}
void CommandBufferProxy::SetParseError(
@@ -352,18 +354,16 @@ void CommandBufferProxy::SetContextLostReason(
NOTREACHED();
}
-bool CommandBufferProxy::Echo(Task* task) {
+bool CommandBufferProxy::Echo(const base::Closure& callback) {
if (last_state_.error != gpu::error::kNoError) {
- delete task;
return false;
}
if (!Send(new GpuChannelMsg_Echo(GpuCommandBufferMsg_EchoAck(route_id_)))) {
- delete task;
return false;
}
- echo_tasks_.push(linked_ptr<Task>(task));
+ echo_tasks_.push(callback);
return true;
}
@@ -395,8 +395,8 @@ bool CommandBufferProxy::SetParent(CommandBufferProxy* parent_command_buffer,
return result;
}
-void CommandBufferProxy::SetNotifyRepaintTask(Task* task) {
- notify_repaint_task_.reset(task);
+void CommandBufferProxy::SetNotifyRepaintTask(const base::Closure& task) {
+ notify_repaint_task_ = task;
}
scoped_refptr<GpuVideoDecodeAcceleratorHost>
diff --git a/content/renderer/gpu/command_buffer_proxy.h b/content/renderer/gpu/command_buffer_proxy.h
index 52cc471..efb89fe 100644
--- a/content/renderer/gpu/command_buffer_proxy.h
+++ b/content/renderer/gpu/command_buffer_proxy.h
@@ -11,7 +11,7 @@
#include <map>
#include <queue>
-#include "base/callback_old.h"
+#include "base/callback.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
@@ -31,7 +31,6 @@ class Size;
class GpuChannelHost;
class PluginChannelHost;
-class Task;
// Client side proxy that forwards messages synchronously to a
// CommandBufferStub.
@@ -69,7 +68,7 @@ class CommandBufferProxy : public gpu::CommandBuffer,
// Invoke the task when the channel has been flushed. Takes care of deleting
// the task whether the echo succeeds or not.
- bool Echo(Task* task);
+ bool Echo(const base::Closure& callback);
// Reparent a command buffer. TODO(apatrick): going forward, the notion of
// the parent / child relationship between command buffers is going away in
@@ -78,11 +77,11 @@ class CommandBufferProxy : public gpu::CommandBuffer,
virtual bool SetParent(CommandBufferProxy* parent_command_buffer,
uint32 parent_texture_id);
- void SetChannelErrorCallback(Callback0::Type* callback);
+ void SetChannelErrorCallback(const base::Closure& callback);
// Set a task that will be invoked the next time the window becomes invalid
// and needs to be repainted. Takes ownership of task.
- void SetNotifyRepaintTask(Task* task);
+ void SetNotifyRepaintTask(const base::Closure& callback);
// Sends an IPC message to create a GpuVideoDecodeAccelerator. Creates and
// returns a pointer to a GpuVideoDecodeAcceleratorHost.
@@ -130,11 +129,11 @@ class CommandBufferProxy : public gpu::CommandBuffer,
unsigned int flush_count_;
// Tasks to be invoked in echo responses.
- std::queue<linked_ptr<Task> > echo_tasks_;
+ std::queue<base::Closure> echo_tasks_;
- scoped_ptr<Task> notify_repaint_task_;
+ base::Closure notify_repaint_task_;
- scoped_ptr<Callback0::Type> channel_error_callback_;
+ base::Closure channel_error_callback_;
DISALLOW_COPY_AND_ASSIGN(CommandBufferProxy);
};
diff --git a/content/renderer/gpu/renderer_gl_context.cc b/content/renderer/gpu/renderer_gl_context.cc
index af93c92..2611ec9 100644
--- a/content/renderer/gpu/renderer_gl_context.cc
+++ b/content/renderer/gpu/renderer_gl_context.cc
@@ -4,6 +4,7 @@
#include "content/renderer/gpu/renderer_gl_context.h"
+#include "base/bind.h"
#include "base/debug/trace_event.h"
#include "base/lazy_instance.h"
#include "base/memory/ref_counted.h"
@@ -192,8 +193,8 @@ void RendererGLContext::DeleteParentTexture(uint32 texture) {
}
void RendererGLContext::SetContextLostCallback(
- Callback1<ContextLostReason>::Type* callback) {
- context_lost_callback_.reset(callback);
+ const base::Callback<void (ContextLostReason)>& callback) {
+ context_lost_callback_ = callback;
}
bool RendererGLContext::MakeCurrent(RendererGLContext* context) {
@@ -229,7 +230,7 @@ bool RendererGLContext::SwapBuffers() {
return true;
}
-bool RendererGLContext::Echo(Task* task) {
+bool RendererGLContext::Echo(const base::Closure& task) {
return command_buffer_->Echo(task);
}
@@ -371,7 +372,7 @@ bool RendererGLContext::Initialize(bool onscreen,
}
command_buffer_->SetChannelErrorCallback(
- NewCallback(this, &RendererGLContext::OnContextLost));
+ base::Bind(&RendererGLContext::OnContextLost, base::Unretained(this)));
// Create the GLES2 helper, which writes the command buffer protocol.
gles2_helper_ = new gpu::gles2::GLES2CmdHelper(command_buffer_);
@@ -446,12 +447,12 @@ void RendererGLContext::Destroy() {
}
void RendererGLContext::OnContextLost() {
- if (context_lost_callback_.get()) {
+ if (!context_lost_callback_.is_null()) {
RendererGLContext::ContextLostReason reason = kUnknown;
if (command_buffer_) {
reason = ConvertReason(
command_buffer_->GetLastState().context_lost_reason);
}
- context_lost_callback_->Run(reason);
+ context_lost_callback_.Run(reason);
}
}
diff --git a/content/renderer/gpu/renderer_gl_context.h b/content/renderer/gpu/renderer_gl_context.h
index 8b04fd2..37da68d 100644
--- a/content/renderer/gpu/renderer_gl_context.h
+++ b/content/renderer/gpu/renderer_gl_context.h
@@ -10,7 +10,7 @@
#define CONTENT_RENDERER_GPU_RENDERER_GL_CONTEXT_H_
#pragma once
-#include "base/callback_old.h"
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
@@ -22,7 +22,6 @@
class GpuChannelHost;
class CommandBufferProxy;
class GURL;
-class Task;
class TransportTextureHost;
namespace gpu {
@@ -142,7 +141,8 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext>,
// Deletes a texture in the parent's RendererGLContext.
void DeleteParentTexture(uint32 texture);
- void SetContextLostCallback(Callback1<ContextLostReason>::Type* callback);
+ void SetContextLostCallback(
+ const base::Callback<void(ContextLostReason)>& callback);
// Set the current RendererGLContext for the calling thread.
static bool MakeCurrent(RendererGLContext* context);
@@ -155,7 +155,7 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext>,
// Run the task once the channel has been flushed. Takes care of deleting the
// task whether the echo succeeds or not.
- bool Echo(Task* task);
+ bool Echo(const base::Closure& task);
// Create a TransportTextureHost object associated with the context.
scoped_refptr<TransportTextureHost> CreateTransportTextureHost();
@@ -192,7 +192,7 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext>,
scoped_refptr<GpuChannelHost> channel_;
base::WeakPtr<RendererGLContext> parent_;
- scoped_ptr<Callback1<ContextLostReason>::Type> context_lost_callback_;
+ base::Callback<void(ContextLostReason)> context_lost_callback_;
uint32 parent_texture_id_;
CommandBufferProxy* command_buffer_;
gpu::gles2::GLES2CmdHelper* gles2_helper_;
diff --git a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc
index da50f0c..29a368a 100644
--- a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc
+++ b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc
@@ -15,6 +15,7 @@
#include <algorithm>
#include <set>
+#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/string_tokenizer.h"
#include "base/command_line.h"
@@ -52,7 +53,7 @@ WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl()
cached_width_(0),
cached_height_(0),
bound_fbo_(0),
- method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
WebGraphicsContext3DCommandBufferImpl::
@@ -174,8 +175,8 @@ bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() {
gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
context_->SetContextLostCallback(
- NewCallback(this,
- &WebGraphicsContext3DCommandBufferImpl::OnContextLost));
+ base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnContextLost,
+ weak_ptr_factory_.GetWeakPtr()));
// TODO(gman): Remove this.
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
@@ -245,8 +246,9 @@ void WebGraphicsContext3DCommandBufferImpl::prepareTexture() {
if (renderview)
renderview->OnViewContextSwapBuffersPosted();
context_->SwapBuffers();
- context_->Echo(method_factory_.NewRunnableMethod(
- &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete));
+ context_->Echo(base::Bind(
+ &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete,
+ weak_ptr_factory_.GetWeakPtr()));
#if defined(OS_MACOSX)
// It appears that making the compositor's on-screen context current on
// other platforms implies this flush. TODO(kbr): this means that the
diff --git a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h
index 48e7d9a..c1265f1 100644
--- a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h
+++ b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h
@@ -11,7 +11,7 @@
#include <vector>
#include "base/memory/scoped_ptr.h"
-#include "base/task.h"
+#include "base/memory/weak_ptr.h"
#include "content/renderer/gpu/renderer_gl_context.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
@@ -487,8 +487,7 @@ class WebGraphicsContext3DCommandBufferImpl
// Errors raised by synthesizeGLError().
std::vector<WGC3Denum> synthetic_errors_;
- ScopedRunnableMethodFactory<WebGraphicsContext3DCommandBufferImpl>
- method_factory_;
+ base::WeakPtrFactory<WebGraphicsContext3DCommandBufferImpl> weak_ptr_factory_;
#ifdef FLIP_FRAMEBUFFER_VERTICALLY
scoped_array<uint8> scanline_;
diff --git a/content/renderer/pepper_platform_context_3d_impl.cc b/content/renderer/pepper_platform_context_3d_impl.cc
index 6b50700..af08efd 100644
--- a/content/renderer/pepper_platform_context_3d_impl.cc
+++ b/content/renderer/pepper_platform_context_3d_impl.cc
@@ -4,6 +4,7 @@
#include "content/renderer/pepper_platform_context_3d_impl.h"
+#include "base/bind.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/gpu/renderer_gl_context.h"
#include "content/renderer/gpu/gpu_channel_host.h"
@@ -18,7 +19,7 @@ PlatformContext3DImpl::PlatformContext3DImpl(RendererGLContext* parent_context)
: parent_context_(parent_context->AsWeakPtr()),
parent_texture_id_(0),
command_buffer_(NULL),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
PlatformContext3DImpl::~PlatformContext3DImpl() {
@@ -105,8 +106,9 @@ bool PlatformContext3DImpl::Init(const int32* attrib_list) {
if (!command_buffer_->SetParent(parent_command_buffer, parent_texture_id_))
return false;
- command_buffer_->SetChannelErrorCallback(callback_factory_.NewCallback(
- &PlatformContext3DImpl::OnContextLost));
+ command_buffer_->SetChannelErrorCallback(
+ base::Bind(&PlatformContext3DImpl::OnContextLost,
+ weak_ptr_factory_.GetWeakPtr()));
return true;
}
@@ -125,19 +127,19 @@ int PlatformContext3DImpl::GetCommandBufferRouteId() {
return command_buffer_->route_id();
}
-void PlatformContext3DImpl::SetContextLostCallback(Callback0::Type* callback) {
- context_lost_callback_.reset(callback);
+void PlatformContext3DImpl::SetContextLostCallback(const base::Closure& task) {
+ context_lost_callback_ = task;
}
-bool PlatformContext3DImpl::Echo(Task* task) {
+bool PlatformContext3DImpl::Echo(const base::Closure& task) {
return command_buffer_->Echo(task);
}
void PlatformContext3DImpl::OnContextLost() {
DCHECK(command_buffer_);
- if (context_lost_callback_.get())
- context_lost_callback_->Run();
+ if (!context_lost_callback_.is_null())
+ context_lost_callback_.Run();
}
#endif // ENABLE_GPU
diff --git a/content/renderer/pepper_platform_context_3d_impl.h b/content/renderer/pepper_platform_context_3d_impl.h
index d793758..ff4c1c2 100644
--- a/content/renderer/pepper_platform_context_3d_impl.h
+++ b/content/renderer/pepper_platform_context_3d_impl.h
@@ -5,7 +5,6 @@
#define CONTENT_RENDERER_PEPPER_PLATFORM_CONTEXT_3D_IMPL_H_
#include "base/callback.h"
-#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
@@ -21,7 +20,6 @@ class CommandBuffer;
class CommandBufferProxy;
class GpuChannelHost;
class RendererGLContext;
-class Task;
class PlatformContext3DImpl
: public webkit::ppapi::PluginDelegate::PlatformContext3D {
@@ -33,8 +31,8 @@ class PlatformContext3DImpl
virtual unsigned GetBackingTextureId();
virtual gpu::CommandBuffer* GetCommandBuffer();
virtual int GetCommandBufferRouteId();
- virtual void SetContextLostCallback(Callback0::Type* callback);
- virtual bool Echo(Task* task);
+ virtual void SetContextLostCallback(const base::Closure& callback);
+ virtual bool Echo(const base::Closure& task);
private:
bool InitRaw();
@@ -44,8 +42,8 @@ class PlatformContext3DImpl
scoped_refptr<GpuChannelHost> channel_;
unsigned int parent_texture_id_;
CommandBufferProxy* command_buffer_;
- scoped_ptr<Callback0::Type> context_lost_callback_;
- base::ScopedCallbackFactory<PlatformContext3DImpl> callback_factory_;
+ base::Closure context_lost_callback_;
+ base::WeakPtrFactory<PlatformContext3DImpl> weak_ptr_factory_;
};
#endif // ENABLE_GPU
diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc
index 438afc7..866aa3b 100644
--- a/content/renderer/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper_plugin_delegate_impl.cc
@@ -280,7 +280,7 @@ void PlatformAudioImpl::ShutDown() {
client_ = NULL;
ChildProcess::current()->io_message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread));
+ base::Bind(&PlatformAudioImpl::ShutDownOnIOThread, this));
}
void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) {
@@ -396,18 +396,18 @@ class HostDispatcherWrapper
class QuotaCallbackTranslator : public QuotaDispatcher::Callback {
public:
typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback;
- explicit QuotaCallbackTranslator(PluginCallback* cb) : callback_(cb) {}
+ explicit QuotaCallbackTranslator(const PluginCallback& cb) : callback_(cb) {}
virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE {
- callback_->Run(std::max(static_cast<int64>(0), quota - usage));
+ callback_.Run(std::max(static_cast<int64>(0), quota - usage));
}
virtual void DidGrantStorageQuota(int64 granted_quota) OVERRIDE {
NOTREACHED();
}
virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE {
- callback_->Run(0);
+ callback_.Run(0);
}
private:
- scoped_ptr<PluginCallback> callback_;
+ PluginCallback callback_;
};
class PlatformVideoCaptureImpl
@@ -665,7 +665,6 @@ PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view)
: render_view_(render_view),
has_saved_context_menu_action_(false),
saved_context_menu_action_(0),
- id_generator_(0),
is_pepper_plugin_focused_(false),
mouse_lock_owner_(NULL),
mouse_locked_(false),
@@ -1017,12 +1016,12 @@ bool PepperPluginDelegateImpl::RunFileChooser(
return render_view_->runFileChooser(params, chooser_completion);
}
-bool PepperPluginDelegateImpl::AsyncOpenFile(const FilePath& path,
- int flags,
- AsyncOpenFileCallback* callback) {
- int message_id = id_generator_++;
- DCHECK(!messages_waiting_replies_.Lookup(message_id));
- messages_waiting_replies_.AddWithID(callback, message_id);
+bool PepperPluginDelegateImpl::AsyncOpenFile(
+ const FilePath& path,
+ int flags,
+ const AsyncOpenFileCallback& callback) {
+ int message_id = pending_async_open_files_.Add(
+ new AsyncOpenFileCallback(callback));
IPC::Message* msg = new ViewHostMsg_AsyncOpenFile(
render_view_->routing_id(), path, flags, message_id);
return render_view_->Send(msg);
@@ -1033,9 +1032,9 @@ void PepperPluginDelegateImpl::OnAsyncFileOpened(
base::PlatformFile file,
int message_id) {
AsyncOpenFileCallback* callback =
- messages_waiting_replies_.Lookup(message_id);
+ pending_async_open_files_.Lookup(message_id);
DCHECK(callback);
- messages_waiting_replies_.Remove(message_id);
+ pending_async_open_files_.Remove(message_id);
callback->Run(error_code, base::PassPlatformFile(&file));
// Make sure we won't leak file handle if the requester has died.
if (file != base::kInvalidPlatformFileValue)
@@ -1187,7 +1186,7 @@ void PepperPluginDelegateImpl::PublishPolicy(const std::string& policy_json) {
void PepperPluginDelegateImpl::QueryAvailableSpace(
const GURL& origin, quota::StorageType type,
- AvailableSpaceCallback* callback) {
+ const AvailableSpaceCallback& callback) {
ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
origin, type, new QuotaCallbackTranslator(callback));
}
@@ -1204,7 +1203,7 @@ class AsyncOpenFileSystemURLCallbackTranslator
: public fileapi::FileSystemCallbackDispatcher {
public:
AsyncOpenFileSystemURLCallbackTranslator(
- webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback)
+ const webkit::ppapi::PluginDelegate::AsyncOpenFileCallback& callback)
: callback_(callback) {
}
@@ -1230,7 +1229,7 @@ class AsyncOpenFileSystemURLCallbackTranslator
virtual void DidFail(base::PlatformFileError error_code) {
base::PlatformFile invalid_file = base::kInvalidPlatformFileValue;
- callback_->Run(error_code, base::PassPlatformFile(&invalid_file));
+ callback_.Run(error_code, base::PassPlatformFile(&invalid_file));
}
virtual void DidWrite(int64 bytes, bool complete) {
@@ -1240,7 +1239,7 @@ class AsyncOpenFileSystemURLCallbackTranslator
virtual void DidOpenFile(
base::PlatformFile file,
base::ProcessHandle unused) {
- callback_->Run(base::PLATFORM_FILE_OK, base::PassPlatformFile(&file));
+ callback_.Run(base::PLATFORM_FILE_OK, base::PassPlatformFile(&file));
// Make sure we won't leak file handle if the requester has died.
if (file != base::kInvalidPlatformFileValue) {
base::FileUtilProxy::Close(RenderThreadImpl::current()->
@@ -1249,11 +1248,11 @@ class AsyncOpenFileSystemURLCallbackTranslator
}
private: // TODO(ericu): Delete this?
- webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback_;
+ webkit::ppapi::PluginDelegate::AsyncOpenFileCallback callback_;
};
bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL(
- const GURL& path, int flags, AsyncOpenFileCallback* callback) {
+ const GURL& path, int flags, const AsyncOpenFileCallback& callback) {
FileSystemDispatcher* file_system_dispatcher =
ChildThread::current()->file_system_dispatcher();
diff --git a/content/renderer/pepper_plugin_delegate_impl.h b/content/renderer/pepper_plugin_delegate_impl.h
index 7410490..432e46f 100644
--- a/content/renderer/pepper_plugin_delegate_impl.h
+++ b/content/renderer/pepper_plugin_delegate_impl.h
@@ -208,11 +208,11 @@ class PepperPluginDelegateImpl
WebKit::WebFileChooserCompletion* chooser_completion);
virtual bool AsyncOpenFile(const FilePath& path,
int flags,
- AsyncOpenFileCallback* callback);
+ const AsyncOpenFileCallback& callback);
virtual bool AsyncOpenFileSystemURL(
const GURL& path,
int flags,
- AsyncOpenFileCallback* callback) OVERRIDE;
+ const AsyncOpenFileCallback& callback) OVERRIDE;
virtual bool OpenFileSystem(
const GURL& url,
fileapi::FileSystemType type,
@@ -241,9 +241,10 @@ class PepperPluginDelegateImpl
const GURL& directory_path,
fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
virtual void PublishPolicy(const std::string& policy_json) OVERRIDE;
- virtual void QueryAvailableSpace(const GURL& origin,
- quota::StorageType type,
- AvailableSpaceCallback* callback) OVERRIDE;
+ virtual void QueryAvailableSpace(
+ const GURL& origin,
+ quota::StorageType type,
+ const AvailableSpaceCallback& callback) OVERRIDE;
virtual void WillUpdateFile(const GURL& file_path) OVERRIDE;
virtual void DidUpdateFile(const GURL& file_path, int64_t delta) OVERRIDE;
virtual base::PlatformFileError OpenFile(
@@ -341,10 +342,7 @@ class PepperPluginDelegateImpl
bool has_saved_context_menu_action_;
unsigned saved_context_menu_action_;
- // TODO(viettrungluu): Get rid of |id_generator_| -- just use |IDMap::Add()|.
- // Rename |messages_waiting_replies_| (to specify async open file).
- int id_generator_;
- IDMap<AsyncOpenFileCallback> messages_waiting_replies_;
+ IDMap<AsyncOpenFileCallback> pending_async_open_files_;
IDMap<scoped_refptr<webkit::ppapi::PPB_Flash_NetConnector_Impl>,
IDMapOwnPointer> pending_connect_tcps_;
diff --git a/content/renderer/render_widget_fullscreen_pepper.cc b/content/renderer/render_widget_fullscreen_pepper.cc
index 2a71e50..da41497 100644
--- a/content/renderer/render_widget_fullscreen_pepper.cc
+++ b/content/renderer/render_widget_fullscreen_pepper.cc
@@ -4,6 +4,7 @@
#include "content/renderer/render_widget_fullscreen_pepper.h"
+#include "base/bind.h"
#include "base/message_loop.h"
#include "content/common/view_messages.h"
#include "content/renderer/gpu/gpu_channel_host.h"
@@ -221,7 +222,7 @@ RenderWidgetFullscreenPepper::RenderWidgetFullscreenPepper(
context_(NULL),
buffer_(0),
program_(0),
- method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
RenderWidgetFullscreenPepper::~RenderWidgetFullscreenPepper() {
@@ -361,7 +362,7 @@ void RenderWidgetFullscreenPepper::CreateContext() {
return;
}
context_->SetContextLostCallback(
- NewCallback(this, &RenderWidgetFullscreenPepper::OnLostContext));
+ base::Bind(&RenderWidgetFullscreenPepper::OnLostContext, this));
}
namespace {
@@ -474,8 +475,9 @@ void RenderWidgetFullscreenPepper::SwapBuffers() {
DCHECK(context_);
OnSwapBuffersPosted();
context_->SwapBuffers();
- context_->Echo(method_factory_.NewRunnableMethod(
- &RenderWidgetFullscreenPepper::OnSwapBuffersCompleteByRendererGLContext));
+ context_->Echo(base::Bind(
+ &RenderWidgetFullscreenPepper::OnSwapBuffersCompleteByRendererGLContext,
+ weak_ptr_factory_.GetWeakPtr()));
}
void RenderWidgetFullscreenPepper::OnLostContext(
@@ -487,7 +489,7 @@ void RenderWidgetFullscreenPepper::OnLostContext(
// created when the plugin recreates its own.
MessageLoop::current()->PostTask(
FROM_HERE,
- NewRunnableFunction(DestroyContext, context_, program_, buffer_));
+ base::Bind(DestroyContext, context_, program_, buffer_));
context_ = NULL;
program_ = 0;
buffer_ = 0;
diff --git a/content/renderer/render_widget_fullscreen_pepper.h b/content/renderer/render_widget_fullscreen_pepper.h
index b8f095f..fdae363 100644
--- a/content/renderer/render_widget_fullscreen_pepper.h
+++ b/content/renderer/render_widget_fullscreen_pepper.h
@@ -5,7 +5,7 @@
#ifndef CONTENT_RENDERER_RENDER_WIDGET_FULLSCREEN_PEPPER_H_
#define CONTENT_RENDERER_RENDER_WIDGET_FULLSCREEN_PEPPER_H_
-#include "base/task.h"
+#include "base/memory/weak_ptr.h"
#include "content/renderer/render_widget_fullscreen.h"
#include "content/renderer/gpu/renderer_gl_context.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
@@ -93,7 +93,7 @@ class RenderWidgetFullscreenPepper : public RenderWidgetFullscreen,
unsigned int buffer_;
unsigned int program_;
- ScopedRunnableMethodFactory<RenderWidgetFullscreenPepper> method_factory_;
+ base::WeakPtrFactory<RenderWidgetFullscreenPepper> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(RenderWidgetFullscreenPepper);
};
diff --git a/webkit/plugins/ppapi/callbacks.cc b/webkit/plugins/ppapi/callbacks.cc
index 69cd2e8..84fffd0 100644
--- a/webkit/plugins/ppapi/callbacks.cc
+++ b/webkit/plugins/ppapi/callbacks.cc
@@ -6,6 +6,7 @@
#include <algorithm>
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/message_loop.h"
@@ -95,10 +96,11 @@ void TrackedCallback::PostAbort() {
if (!completed()) {
aborted_ = true;
// Post a task for the abort (only if necessary).
- if (abort_impl_factory_.empty()) {
+ if (!abort_impl_factory_.HasWeakPtrs()) {
MessageLoop::current()->PostTask(
FROM_HERE,
- abort_impl_factory_.NewRunnableMethod(&TrackedCallback::AbortImpl));
+ base::Bind(&TrackedCallback::AbortImpl,
+ abort_impl_factory_.GetWeakPtr()));
}
}
}
@@ -132,7 +134,7 @@ TrackedCompletionCallback::TrackedCompletionCallback(
void TrackedCompletionCallback::Run(int32_t result) {
if (!completed()) {
// Cancel any pending calls.
- abort_impl_factory_.RevokeAll();
+ abort_impl_factory_.InvalidateWeakPtrs();
// Copy |callback_| and look at |aborted()| now, since |MarkAsCompleted()|
// may delete us.
diff --git a/webkit/plugins/ppapi/callbacks.h b/webkit/plugins/ppapi/callbacks.h
index 99e8e1e..5fbee60 100644
--- a/webkit/plugins/ppapi/callbacks.h
+++ b/webkit/plugins/ppapi/callbacks.h
@@ -163,7 +163,7 @@ class TrackedCallback : public base::RefCountedThreadSafe<TrackedCallback> {
// Factory used by |PostAbort()|. Note that it's safe to cancel any pending
// posted aborts on destruction -- before it's destroyed, the "owning"
// |CallbackTracker| must have gone through and done (synchronous) |Abort()|s.
- ScopedRunnableMethodFactory<TrackedCallback> abort_impl_factory_;
+ base::WeakPtrFactory<TrackedCallback> abort_impl_factory_;
private:
scoped_refptr<CallbackTracker> tracker_;
diff --git a/webkit/plugins/ppapi/message_channel.cc b/webkit/plugins/ppapi/message_channel.cc
index 33eacfa..e49ada6 100644
--- a/webkit/plugins/ppapi/message_channel.cc
+++ b/webkit/plugins/ppapi/message_channel.cc
@@ -7,6 +7,7 @@
#include <cstdlib>
#include <string>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
@@ -284,7 +285,7 @@ MessageChannel::MessageChannel(PluginInstance* instance)
: instance_(instance),
passthrough_object_(NULL),
np_object_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
VOID_TO_NPVARIANT(onmessage_invoker_);
// Now create an NPObject for receiving calls to postMessage. This sets the
@@ -347,9 +348,9 @@ void MessageChannel::PostMessageToJavaScript(PP_Var message_data) {
MessageLoop::current()->PostTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &MessageChannel::PostMessageToJavaScriptImpl,
- var_copy));
+ base::Bind(&MessageChannel::PostMessageToJavaScriptImpl,
+ weak_ptr_factory_.GetWeakPtr(),
+ var_copy));
}
void MessageChannel::PostMessageToJavaScriptImpl(PP_Var message_data) {
@@ -396,9 +397,9 @@ void MessageChannel::PostMessageToNative(PP_Var message_data) {
PP_Var var_copy(CopyPPVar(message_data));
MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &MessageChannel::PostMessageToNativeImpl,
- var_copy));
+ base::Bind(&MessageChannel::PostMessageToNativeImpl,
+ weak_ptr_factory_.GetWeakPtr(),
+ var_copy));
}
void MessageChannel::PostMessageToNativeImpl(PP_Var message_data) {
diff --git a/webkit/plugins/ppapi/message_channel.h b/webkit/plugins/ppapi/message_channel.h
index c6470c4..d7979f1 100644
--- a/webkit/plugins/ppapi/message_channel.h
+++ b/webkit/plugins/ppapi/message_channel.h
@@ -96,8 +96,9 @@ class MessageChannel {
// channel's instance. This is used by PostMessageToNative.
void PostMessageToNativeImpl(PP_Var message_data);
- // Ensure pending tasks will not fire after this object is destroyed.
- ScopedRunnableMethodFactory<MessageChannel> method_factory_;
+ // This is used to ensure pending tasks will not fire after this object is
+ // destroyed.
+ base::WeakPtrFactory<MessageChannel> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(MessageChannel);
};
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index cd43087..7725db3 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -85,12 +85,12 @@ bool MockPluginDelegate::RunFileChooser(
bool MockPluginDelegate::AsyncOpenFile(const FilePath& path,
int flags,
- AsyncOpenFileCallback* callback) {
+ const AsyncOpenFileCallback& callback) {
return false;
}
bool MockPluginDelegate::AsyncOpenFileSystemURL(
- const GURL& path, int flags, AsyncOpenFileCallback* callback) {
+ const GURL& path, int flags, const AsyncOpenFileCallback& callback) {
return false;
}
@@ -144,7 +144,7 @@ bool MockPluginDelegate::ReadDirectory(
void MockPluginDelegate::QueryAvailableSpace(
const GURL& origin, quota::StorageType type,
- AvailableSpaceCallback* callback) {
+ const AvailableSpaceCallback& callback) {
}
void MockPluginDelegate::WillUpdateFile(const GURL& file_path) {
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index d96b860..75f5de1 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -40,10 +40,10 @@ class MockPluginDelegate : public PluginDelegate {
WebKit::WebFileChooserCompletion* chooser_completion);
virtual bool AsyncOpenFile(const FilePath& path,
int flags,
- AsyncOpenFileCallback* callback);
+ const AsyncOpenFileCallback& callback);
virtual bool AsyncOpenFileSystemURL(const GURL& path,
int flags,
- AsyncOpenFileCallback* callback);
+ const AsyncOpenFileCallback& callback);
virtual bool OpenFileSystem(
const GURL& url,
fileapi::FileSystemType type,
@@ -69,7 +69,7 @@ class MockPluginDelegate : public PluginDelegate {
fileapi::FileSystemCallbackDispatcher* dispatcher);
virtual void QueryAvailableSpace(const GURL& origin,
quota::StorageType type,
- AvailableSpaceCallback* callback);
+ const AvailableSpaceCallback& callback);
virtual void WillUpdateFile(const GURL& file_path);
virtual void DidUpdateFile(const GURL& file_path, int64_t delta);
virtual base::PlatformFileError OpenFile(const PepperFilePath& path,
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index f69bf24..0a7e47f 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -7,7 +7,7 @@
#include <string>
-#include "base/callback_old.h"
+#include "base/callback.h"
#include "base/message_loop_proxy.h"
#include "base/memory/ref_counted.h"
#include "base/platform_file.h"
@@ -181,11 +181,11 @@ class PluginDelegate {
// Set an optional callback that will be invoked when the context is lost
// (e.g. gpu process crash). Takes ownership of the callback.
- virtual void SetContextLostCallback(Callback0::Type* callback) = 0;
+ virtual void SetContextLostCallback(
+ const base::Callback<void()>& callback) = 0;
- // Run the task once the channel has been flushed. Takes care of deleting
- // the task whether the echo succeeds or not.
- virtual bool Echo(Task* task) = 0;
+ // Run the callback once the channel has been flushed.
+ virtual bool Echo(const base::Callback<void()>& callback) = 0;
};
class PlatformAudio {
@@ -306,14 +306,15 @@ class PluginDelegate {
WebKit::WebFileChooserCompletion* chooser_completion) = 0;
// Sends an async IPC to open a file.
- typedef Callback2<base::PlatformFileError, base::PassPlatformFile
- >::Type AsyncOpenFileCallback;
+ typedef base::Callback<void (base::PlatformFileError, base::PassPlatformFile)>
+ AsyncOpenFileCallback;
virtual bool AsyncOpenFile(const FilePath& path,
int flags,
- AsyncOpenFileCallback* callback) = 0;
- virtual bool AsyncOpenFileSystemURL(const GURL& path,
- int flags,
- AsyncOpenFileCallback* callback) = 0;
+ const AsyncOpenFileCallback& callback) = 0;
+ virtual bool AsyncOpenFileSystemURL(
+ const GURL& path,
+ int flags,
+ const AsyncOpenFileCallback& callback) = 0;
virtual bool OpenFileSystem(
const GURL& url,
@@ -346,10 +347,10 @@ class PluginDelegate {
virtual void PublishPolicy(const std::string& policy_json) = 0;
// For quota handlings for FileIO API.
- typedef Callback1<int64>::Type AvailableSpaceCallback;
+ typedef base::Callback<void (int64)> AvailableSpaceCallback;
virtual void QueryAvailableSpace(const GURL& origin,
quota::StorageType type,
- AvailableSpaceCallback* callback) = 0;
+ const AvailableSpaceCallback& callback) = 0;
virtual void WillUpdateFile(const GURL& file_path) = 0;
virtual void DidUpdateFile(const GURL& file_path, int64_t delta) = 0;
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 43fbd6f..b7877e7 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -6,6 +6,7 @@
#include <set>
+#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -163,7 +164,7 @@ void CallOnMainThread(int delay_in_msec,
if (callback.func) {
GetMainThreadMessageLoop()->PostDelayedTask(
FROM_HERE,
- NewRunnableFunction(callback.func, callback.user_data, result),
+ base::Bind(callback.func, callback.user_data, result),
delay_in_msec);
}
}
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 6df29ee..da85c07 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -4,6 +4,7 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+#include "base/bind.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -977,7 +978,7 @@ bool PluginInstance::SetFullscreen(bool fullscreen, bool delay_report) {
ReportGeometry();
} else {
MessageLoop::current()->PostTask(
- FROM_HERE, NewRunnableMethod(this, &PluginInstance::ReportGeometry));
+ FROM_HERE, base::Bind(&PluginInstance::ReportGeometry, this));
}
return true;
}
@@ -1007,7 +1008,7 @@ void PluginInstance::FlashSetFullscreen(bool fullscreen, bool delay_report) {
ReportGeometry();
} else {
MessageLoop::current()->PostTask(
- FROM_HERE, NewRunnableMethod(this, &PluginInstance::ReportGeometry));
+ FROM_HERE, base::Bind(&PluginInstance::ReportGeometry, this));
}
}
}
diff --git a/webkit/plugins/ppapi/ppb_context_3d_impl.cc b/webkit/plugins/ppapi/ppb_context_3d_impl.cc
index 544adbb..5acf56c 100644
--- a/webkit/plugins/ppapi/ppb_context_3d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_context_3d_impl.cc
@@ -4,6 +4,7 @@
#include "webkit/plugins/ppapi/ppb_context_3d_impl.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/shared_memory.h"
#include "gpu/command_buffer/client/gles2_cmd_helper.h"
@@ -72,7 +73,7 @@ PPB_Context3D_Impl::PPB_Context3D_Impl(PP_Instance instance)
transfer_buffer_id_(0),
draw_surface_(NULL),
read_surface_(NULL),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
PPB_Context3D_Impl::~PPB_Context3D_Impl() {
@@ -304,7 +305,8 @@ bool PPB_Context3D_Impl::InitRaw(PP_Config3D_Dev config,
}
platform_context_->SetContextLostCallback(
- callback_factory_.NewCallback(&PPB_Context3D_Impl::OnContextLost));
+ base::Bind(&PPB_Context3D_Impl::OnContextLost,
+ weak_ptr_factory_.GetWeakPtr()));
return true;
}
diff --git a/webkit/plugins/ppapi/ppb_context_3d_impl.h b/webkit/plugins/ppapi/ppb_context_3d_impl.h
index 5b56482..66f23e2 100644
--- a/webkit/plugins/ppapi/ppb_context_3d_impl.h
+++ b/webkit/plugins/ppapi/ppb_context_3d_impl.h
@@ -5,8 +5,8 @@
#ifndef WEBKIT_PLUGINS_PPAPI_PPB_CONTEXT_3D_IMPL_H_
#define WEBKIT_PLUGINS_PPAPI_PPB_CONTEXT_3D_IMPL_H_
-#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/thunk/ppb_context_3d_api.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
@@ -110,7 +110,7 @@ class PPB_Context3D_Impl : public ::ppapi::Resource,
PPB_Surface3D_Impl* draw_surface_;
PPB_Surface3D_Impl* read_surface_;
- base::ScopedCallbackFactory<PPB_Context3D_Impl> callback_factory_;
+ base::WeakPtrFactory<PPB_Context3D_Impl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PPB_Context3D_Impl);
};
diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.cc b/webkit/plugins/ppapi/ppb_file_io_impl.cc
index 1460b27..213071e 100644
--- a/webkit/plugins/ppapi/ppb_file_io_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_io_impl.cc
@@ -4,6 +4,7 @@
#include "webkit/plugins/ppapi/ppb_file_io_impl.h"
+#include "base/bind.h"
#include "base/callback.h"
#include "base/file_util.h"
#include "base/file_util_proxy.h"
@@ -54,7 +55,8 @@ PPB_FileIO_Impl::PPB_FileIO_Impl(PP_Instance instance)
file_(base::kInvalidPlatformFileValue),
file_system_type_(PP_FILESYSTEMTYPE_INVALID),
pending_op_(OPERATION_NONE),
- info_(NULL) {
+ info_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
}
PPB_FileIO_Impl::~PPB_FileIO_Impl() {
@@ -95,16 +97,16 @@ int32_t PPB_FileIO_Impl::Open(PP_Resource pp_file_ref,
file_system_url_ = file_ref->GetFileSystemURL();
if (!plugin_delegate->AsyncOpenFileSystemURL(
file_system_url_, flags,
- callback_factory_.NewCallback(
- &PPB_FileIO_Impl::AsyncOpenFileCallback)))
+ base::Bind(&PPB_FileIO_Impl::AsyncOpenFileCallback,
+ weak_ptr_factory_.GetWeakPtr())))
return PP_ERROR_FAILED;
} else {
if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL)
return PP_ERROR_FAILED;
if (!plugin_delegate->AsyncOpenFile(
file_ref->GetSystemPath(), flags,
- callback_factory_.NewCallback(
- &PPB_FileIO_Impl::AsyncOpenFileCallback)))
+ base::Bind(&PPB_FileIO_Impl::AsyncOpenFileCallback,
+ weak_ptr_factory_.GetWeakPtr())))
return PP_ERROR_FAILED;
}
diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.h b/webkit/plugins/ppapi/ppb_file_io_impl.h
index 5da3aeb..ec55fb5 100644
--- a/webkit/plugins/ppapi/ppb_file_io_impl.h
+++ b/webkit/plugins/ppapi/ppb_file_io_impl.h
@@ -12,6 +12,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"
#include "ppapi/c/pp_file_info.h"
#include "ppapi/c/pp_time.h"
@@ -143,6 +144,8 @@ class PPB_FileIO_Impl : public ::ppapi::Resource,
// of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened.
scoped_ptr<QuotaFileIO> quota_file_io_;
+ base::WeakPtrFactory<PPB_FileIO_Impl> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl);
};
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
index bbef628..a6c12a8 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
@@ -6,6 +6,7 @@
#include <iterator>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/task.h"
@@ -155,7 +156,8 @@ PPB_Graphics2D_Impl::PPB_Graphics2D_Impl(PP_Instance instance)
: Resource(instance),
bound_instance_(NULL),
offscreen_flush_pending_(false),
- is_always_opaque_(false) {
+ is_always_opaque_(false),
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
PPB_Graphics2D_Impl::~PPB_Graphics2D_Impl() {
@@ -622,9 +624,9 @@ void PPB_Graphics2D_Impl::ScheduleOffscreenCallback(
offscreen_flush_pending_ = true;
MessageLoop::current()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &PPB_Graphics2D_Impl::ExecuteOffscreenCallback,
- callback));
+ base::Bind(&PPB_Graphics2D_Impl::ExecuteOffscreenCallback,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
}
void PPB_Graphics2D_Impl::ExecuteOffscreenCallback(FlushCallbackData data) {
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
index fc36f18..f100f67 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
@@ -8,6 +8,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/memory/weak_ptr.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/ppb_graphics_2d.h"
#include "ppapi/shared_impl/resource.h"
@@ -174,6 +175,8 @@ class PPB_Graphics2D_Impl : public ::ppapi::Resource,
// This allows us to do more optimized painting in some cases.
bool is_always_opaque_;
+ base::WeakPtrFactory<PPB_Graphics2D_Impl> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(PPB_Graphics2D_Impl);
};
diff --git a/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc
index cdd7d6c7..1e26319 100644
--- a/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc
@@ -4,6 +4,7 @@
#include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
+#include "base/bind.h"
#include "base/message_loop.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "webkit/plugins/ppapi/plugin_module.h"
@@ -54,8 +55,7 @@ PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance)
: Resource(instance),
bound_to_instance_(false),
commit_pending_(false),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
- method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() {
@@ -165,8 +165,8 @@ int32 PPB_Graphics3D_Impl::DoSwapBuffers() {
if (gles2_impl())
gles2_impl()->SwapBuffers();
- platform_context_->Echo(method_factory_.NewRunnableMethod(
- &PPB_Graphics3D_Impl::OnSwapBuffers));
+ platform_context_->Echo(base::Bind(&PPB_Graphics3D_Impl::OnSwapBuffers,
+ weak_ptr_factory_.GetWeakPtr()));
return PP_OK_COMPLETIONPENDING;
}
@@ -202,7 +202,8 @@ bool PPB_Graphics3D_Impl::InitRaw(PP_Resource share_context,
return false;
platform_context_->SetContextLostCallback(
- callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnContextLost));
+ base::Bind(&PPB_Graphics3D_Impl::OnContextLost,
+ weak_ptr_factory_.GetWeakPtr()));
return true;
}
@@ -233,8 +234,8 @@ void PPB_Graphics3D_Impl::OnContextLost() {
// Send context lost to plugin. This may have been caused by a PPAPI call, so
// avoid re-entering.
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &PPB_Graphics3D_Impl::SendContextLost));
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
+ &PPB_Graphics3D_Impl::SendContextLost, weak_ptr_factory_.GetWeakPtr()));
}
void PPB_Graphics3D_Impl::SendContextLost() {
diff --git a/webkit/plugins/ppapi/ppb_graphics_3d_impl.h b/webkit/plugins/ppapi/ppb_graphics_3d_impl.h
index 5029b91..250911b 100644
--- a/webkit/plugins/ppapi/ppb_graphics_3d_impl.h
+++ b/webkit/plugins/ppapi/ppb_graphics_3d_impl.h
@@ -5,7 +5,7 @@
#ifndef WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_
#define WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_
-#include "base/memory/scoped_callback_factory.h"
+#include "base/memory/weak_ptr.h"
#include "ppapi/shared_impl/graphics_3d_impl.h"
#include "ppapi/shared_impl/resource.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
@@ -86,8 +86,7 @@ class PPB_Graphics3D_Impl : public ::ppapi::Resource,
bool commit_pending_;
// PluginDelegate's 3D Context. Responsible for providing the command buffer.
scoped_ptr<PluginDelegate::PlatformContext3D> platform_context_;
- base::ScopedCallbackFactory<PPB_Graphics3D_Impl> callback_factory_;
- ScopedRunnableMethodFactory<PPB_Graphics3D_Impl> method_factory_;
+ base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl);
};
diff --git a/webkit/plugins/ppapi/ppb_scrollbar_impl.cc b/webkit/plugins/ppapi/ppb_scrollbar_impl.cc
index 797f7bf..e731e63 100644
--- a/webkit/plugins/ppapi/ppb_scrollbar_impl.cc
+++ b/webkit/plugins/ppapi/ppb_scrollbar_impl.cc
@@ -4,6 +4,7 @@
#include "webkit/plugins/ppapi/ppb_scrollbar_impl.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "ppapi/c/dev/ppp_scrollbar_dev.h"
@@ -44,7 +45,7 @@ PP_Resource PPB_Scrollbar_Impl::Create(PP_Instance instance,
PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PP_Instance instance)
: PPB_Widget_Impl(instance),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
}
PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() {
@@ -210,13 +211,13 @@ void PPB_Scrollbar_Impl::invalidateScrollbarRect(
// Can't call into the client to tell them about the invalidate right away,
// since the PPB_Scrollbar_Impl code is still in the middle of updating its
// internal state.
- // Note: we use a method factory here instead of NewRunnableMethod because the
- // latter would modify the lifetime of this object. That might make
- // WebKit::WebScrollbar outlive WebKit::WebPluginContainer, which is against
- // its contract.
+ // Note: we use a WeakPtrFactory here so that a lingering callback can not
+ // modify the lifetime of this object. Otherwise, WebKit::WebScrollbar could
+ // outlive WebKit::WebPluginContainer, which is against its contract.
MessageLoop::current()->PostTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(&PPB_Scrollbar_Impl::NotifyInvalidate));
+ base::Bind(&PPB_Scrollbar_Impl::NotifyInvalidate,
+ weak_ptr_factory_.GetWeakPtr()));
}
void PPB_Scrollbar_Impl::getTickmarks(
diff --git a/webkit/plugins/ppapi/ppb_scrollbar_impl.h b/webkit/plugins/ppapi/ppb_scrollbar_impl.h
index f08aff4..cbc4ceb 100644
--- a/webkit/plugins/ppapi/ppb_scrollbar_impl.h
+++ b/webkit/plugins/ppapi/ppb_scrollbar_impl.h
@@ -7,6 +7,7 @@
#include <vector>
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "ppapi/thunk/ppb_scrollbar_api.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
@@ -65,7 +66,7 @@ class PPB_Scrollbar_Impl : public PPB_Widget_Impl,
scoped_ptr<WebKit::WebScrollbar> scrollbar_;
// Used so that the post task for Invalidate doesn't keep an extra reference.
- ScopedRunnableMethodFactory<PPB_Scrollbar_Impl> method_factory_;
+ base::WeakPtrFactory<PPB_Scrollbar_Impl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PPB_Scrollbar_Impl);
};
diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc
index 89ff723..6002c1e 100644
--- a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc
@@ -4,6 +4,7 @@
#include "webkit/plugins/ppapi/ppb_surface_3d_impl.h"
+#include "base/bind.h"
#include "base/message_loop.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/common/command_buffer.h"
@@ -25,7 +26,7 @@ PPB_Surface3D_Impl::PPB_Surface3D_Impl(PP_Instance instance)
bound_to_instance_(false),
swap_initiated_(false),
context_(NULL),
- method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
PPB_Surface3D_Impl::~PPB_Surface3D_Impl() {
@@ -82,8 +83,9 @@ int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) {
gpu::gles2::GLES2Implementation* impl = context_->gles2_impl();
if (impl)
context_->gles2_impl()->SwapBuffers();
- context_->platform_context()->Echo(method_factory_.NewRunnableMethod(
- &PPB_Surface3D_Impl::OnSwapBuffers));
+ context_->platform_context()->Echo(
+ base::Bind(&PPB_Surface3D_Impl::OnSwapBuffers,
+ weak_ptr_factory_.GetWeakPtr()));
// |SwapBuffers()| should not call us back synchronously, but double-check.
DCHECK(!swap_callback_->completed());
return PP_OK_COMPLETIONPENDING;
diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.h b/webkit/plugins/ppapi/ppb_surface_3d_impl.h
index fb21e2f..f6455a4 100644
--- a/webkit/plugins/ppapi/ppb_surface_3d_impl.h
+++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.h
@@ -76,7 +76,7 @@ class PPB_Surface3D_Impl : public ::ppapi::Resource,
// The context this surface is currently bound to.
PPB_Context3D_Impl* context_;
- ScopedRunnableMethodFactory<PPB_Surface3D_Impl> method_factory_;
+ base::WeakPtrFactory<PPB_Surface3D_Impl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PPB_Surface3D_Impl);
};
diff --git a/webkit/plugins/ppapi/quota_file_io.cc b/webkit/plugins/ppapi/quota_file_io.cc
index 63db38e..4a26f67 100644
--- a/webkit/plugins/ppapi/quota_file_io.cc
+++ b/webkit/plugins/ppapi/quota_file_io.cc
@@ -6,6 +6,7 @@
#include <algorithm>
+#include "base/bind.h"
#include "base/stl_util.h"
#include "base/message_loop_proxy.h"
#include "base/task.h"
@@ -223,7 +224,8 @@ QuotaFileIO::QuotaFileIO(
outstanding_errors_(0),
max_written_offset_(0),
inflight_operations_(0),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK_NE(base::kInvalidPlatformFileValue, file_);
DCHECK_NE(quota::kStorageTypeUnknown, storage_type_);
}
@@ -303,7 +305,8 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks(
++outstanding_quota_queries_;
plugin_delegate->QueryAvailableSpace(
GURL(file_url_.path()).GetOrigin(), storage_type_,
- callback_factory_.NewCallback(&QuotaFileIO::DidQueryAvailableSpace));
+ base::Bind(&QuotaFileIO::DidQueryAvailableSpace,
+ weak_ptr_factory_.GetWeakPtr()));
}
pending_operations_.push_back(op.release());
return true;
diff --git a/webkit/plugins/ppapi/quota_file_io.h b/webkit/plugins/ppapi/quota_file_io.h
index a57b0dd..02abdd1 100644
--- a/webkit/plugins/ppapi/quota_file_io.h
+++ b/webkit/plugins/ppapi/quota_file_io.h
@@ -9,6 +9,7 @@
#include "base/file_util_proxy.h"
#include "base/memory/scoped_callback_factory.h"
+#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"
#include "googleurl/src/gurl.h"
#include "ppapi/c/pp_file_info.h"
@@ -104,6 +105,7 @@ class QuotaFileIO {
int inflight_operations_;
base::ScopedCallbackFactory<QuotaFileIO> callback_factory_;
+ base::WeakPtrFactory<QuotaFileIO> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(QuotaFileIO);
};
diff --git a/webkit/plugins/ppapi/quota_file_io_unittest.cc b/webkit/plugins/ppapi/quota_file_io_unittest.cc
index a2356fa..2b7d575 100644
--- a/webkit/plugins/ppapi/quota_file_io_unittest.cc
+++ b/webkit/plugins/ppapi/quota_file_io_unittest.cc
@@ -7,7 +7,9 @@
#include <string>
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/memory/scoped_callback_factory.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/platform_file.h"
#include "base/scoped_temp_dir.h"
@@ -33,7 +35,7 @@ class QuotaMockPluginDelegate : public MockPluginDelegate {
: available_space_(0),
will_update_count_(0),
file_thread_(MessageLoopProxy::current()),
- runnable_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
virtual ~QuotaMockPluginDelegate() {}
@@ -44,11 +46,13 @@ class QuotaMockPluginDelegate : public MockPluginDelegate {
virtual void QueryAvailableSpace(
const GURL& origin,
quota::StorageType type,
- Callback* callback) OVERRIDE {
- DCHECK(callback);
+ const Callback& callback) OVERRIDE {
+ DCHECK(!callback.is_null());
MessageLoopProxy::current()->PostTask(
- FROM_HERE, runnable_factory_.NewRunnableMethod(
- &QuotaMockPluginDelegate::RunAvailableSpaceCallback, callback));
+ FROM_HERE, base::Bind(
+ &QuotaMockPluginDelegate::RunAvailableSpaceCallback,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback));
}
virtual void WillUpdateFile(const GURL& file_path) OVERRIDE {
@@ -67,16 +71,15 @@ class QuotaMockPluginDelegate : public MockPluginDelegate {
int64_t available_space() const { return available_space_; }
private:
- void RunAvailableSpaceCallback(Callback* callback) {
- callback->Run(available_space_);
- delete callback;
+ void RunAvailableSpaceCallback(const Callback& callback) {
+ callback.Run(available_space_);
}
int64_t available_space_;
int will_update_count_;
GURL file_path_;
scoped_refptr<MessageLoopProxy> file_thread_;
- ScopedRunnableMethodFactory<QuotaMockPluginDelegate> runnable_factory_;
+ base::WeakPtrFactory<QuotaMockPluginDelegate> weak_ptr_factory_;
};
} // namespace