Commit 35a5b75c authored by dcheng@chromium.org's avatar dcheng@chromium.org

base::Bind() conversion for content/common/gpu and content/gpu

There will be a followup patch to finish the conversion for GpuCommandBufferStub.

BUG=none
TEST=compiles and passes try bots

Review URL: http://codereview.chromium.org/8572047

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110607 0039d316-1c4b-4281-b951-d872f2087c98
parent 9c7db28e
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "content/common/gpu/gpu_channel.h" #include "content/common/gpu/gpu_channel.h"
#include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/debug/trace_event.h" #include "base/debug/trace_event.h"
#include "base/process_util.h" #include "base/process_util.h"
...@@ -39,7 +40,7 @@ GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, ...@@ -39,7 +40,7 @@ GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager,
handle_messages_scheduled_(false), handle_messages_scheduled_(false),
processed_get_state_fast_(false), processed_get_state_fast_(false),
num_contexts_preferring_discrete_gpu_(0), num_contexts_preferring_discrete_gpu_(0),
task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(gpu_channel_manager); DCHECK(gpu_channel_manager);
DCHECK(renderer_id); DCHECK(renderer_id);
const CommandLine* command_line = CommandLine::ForCurrentProcess(); const CommandLine* command_line = CommandLine::ForCurrentProcess();
...@@ -157,8 +158,7 @@ void GpuChannel::OnScheduled() { ...@@ -157,8 +158,7 @@ void GpuChannel::OnScheduled() {
// task to prevent reentrancy. // task to prevent reentrancy.
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE,
task_factory_.NewRunnableMethod( base::Bind(&GpuChannel::HandleMessage, weak_factory_.GetWeakPtr()));
&GpuChannel::HandleMessage));
handle_messages_scheduled_ = true; handle_messages_scheduled_ = true;
} }
...@@ -168,8 +168,7 @@ void GpuChannel::LoseAllContexts() { ...@@ -168,8 +168,7 @@ void GpuChannel::LoseAllContexts() {
void GpuChannel::DestroySoon() { void GpuChannel::DestroySoon() {
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, NewRunnableMethod(this, FROM_HERE, base::Bind(&GpuChannel::OnDestroy, this));
&GpuChannel::OnDestroy));
} }
void GpuChannel::OnDestroy() { void GpuChannel::OnDestroy() {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/id_map.h" #include "base/id_map.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/process.h" #include "base/process.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/common/gpu/gpu_command_buffer_stub.h" #include "content/common/gpu/gpu_command_buffer_stub.h"
...@@ -185,7 +186,7 @@ class GpuChannel : public IPC::Channel::Listener, ...@@ -185,7 +186,7 @@ class GpuChannel : public IPC::Channel::Listener,
bool processed_get_state_fast_; bool processed_get_state_fast_;
int32 num_contexts_preferring_discrete_gpu_; int32 num_contexts_preferring_discrete_gpu_;
ScopedRunnableMethodFactory<GpuChannel> task_factory_; base::WeakPtrFactory<GpuChannel> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(GpuChannel); DISALLOW_COPY_AND_ASSIGN(GpuChannel);
}; };
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/common/gpu/gpu_channel_manager.h" #include "content/common/gpu/gpu_channel_manager.h"
#include "base/bind.h"
#include "content/common/child_thread.h" #include "content/common/child_thread.h"
#include "content/common/gpu/gpu_channel.h" #include "content/common/gpu/gpu_channel.h"
#include "content/common/gpu/gpu_messages.h" #include "content/common/gpu/gpu_messages.h"
...@@ -12,7 +13,7 @@ GpuChannelManager::GpuChannelManager(ChildThread* gpu_child_thread, ...@@ -12,7 +13,7 @@ GpuChannelManager::GpuChannelManager(ChildThread* gpu_child_thread,
GpuWatchdog* watchdog, GpuWatchdog* watchdog,
base::MessageLoopProxy* io_message_loop, base::MessageLoopProxy* io_message_loop,
base::WaitableEvent* shutdown_event) base::WaitableEvent* shutdown_event)
: ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
io_message_loop_(io_message_loop), io_message_loop_(io_message_loop),
shutdown_event_(shutdown_event), shutdown_event_(shutdown_event),
gpu_child_thread_(gpu_child_thread), gpu_child_thread_(gpu_child_thread),
...@@ -149,8 +150,9 @@ void GpuChannelManager::OnResizeViewACK(int32 renderer_id, ...@@ -149,8 +150,9 @@ void GpuChannelManager::OnResizeViewACK(int32 renderer_id,
void GpuChannelManager::LoseAllContexts() { void GpuChannelManager::LoseAllContexts() {
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, method_factory_.NewRunnableMethod( FROM_HERE,
&GpuChannelManager::OnLoseAllContexts)); base::Bind(&GpuChannelManager::OnLoseAllContexts,
weak_factory_.GetWeakPtr()));
} }
void GpuChannelManager::OnLoseAllContexts() { void GpuChannelManager::OnLoseAllContexts() {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/hash_tables.h" #include "base/hash_tables.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop_proxy.h" #include "base/message_loop_proxy.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ipc/ipc_channel.h" #include "ipc/ipc_channel.h"
...@@ -57,7 +58,7 @@ class GpuChannelManager : public IPC::Channel::Listener, ...@@ -57,7 +58,7 @@ class GpuChannelManager : public IPC::Channel::Listener,
void LoseAllContexts(); void LoseAllContexts();
ScopedRunnableMethodFactory<GpuChannelManager> method_factory_; base::WeakPtrFactory<GpuChannelManager> weak_factory_;
int GenerateRouteID(); int GenerateRouteID();
void AddRoute(int32 routing_id, IPC::Channel::Listener* listener); void AddRoute(int32 routing_id, IPC::Channel::Listener* listener);
......
...@@ -49,8 +49,7 @@ GpuCommandBufferStub::GpuCommandBufferStub( ...@@ -49,8 +49,7 @@ GpuCommandBufferStub::GpuCommandBufferStub(
render_view_id_(render_view_id), render_view_id_(render_view_id),
parent_stub_for_initialization_(), parent_stub_for_initialization_(),
parent_texture_for_initialization_(0), parent_texture_for_initialization_(0),
watchdog_(watchdog), watchdog_(watchdog) {
task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
if (share_group) { if (share_group) {
context_group_ = share_group->context_group_; context_group_ = share_group->context_group_;
} else { } else {
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/id_map.h" #include "base/id_map.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "content/common/gpu/media/gpu_video_decode_accelerator.h" #include "content/common/gpu/media/gpu_video_decode_accelerator.h"
#include "gpu/command_buffer/common/constants.h" #include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/service/command_buffer_service.h" #include "gpu/command_buffer/service/command_buffer_service.h"
...@@ -174,8 +173,6 @@ class GpuCommandBufferStub ...@@ -174,8 +173,6 @@ class GpuCommandBufferStub
// decoder_route_id. // decoder_route_id.
IDMap<GpuVideoDecodeAccelerator, IDMapOwnPointer> video_decoders_; IDMap<GpuVideoDecodeAccelerator, IDMapOwnPointer> video_decoders_;
ScopedRunnableMethodFactory<GpuCommandBufferStub> task_factory_;
DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub); DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub);
}; };
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "content/gpu/gpu_watchdog_thread.h" #include "content/gpu/gpu_watchdog_thread.h"
#include "base/bind.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/process_util.h" #include "base/process_util.h"
#include "base/process.h" #include "base/process.h"
...@@ -30,7 +31,8 @@ GpuWatchdogThread::GpuWatchdogThread(int timeout) ...@@ -30,7 +31,8 @@ GpuWatchdogThread::GpuWatchdogThread(int timeout)
watched_thread_handle_(0), watched_thread_handle_(0),
arm_cpu_time_(0), arm_cpu_time_(0),
#endif #endif
ALLOW_THIS_IN_INITIALIZER_LIST(task_observer_(this)) { ALLOW_THIS_IN_INITIALIZER_LIST(task_observer_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK(timeout >= 0); DCHECK(timeout >= 0);
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -53,7 +55,7 @@ GpuWatchdogThread::GpuWatchdogThread(int timeout) ...@@ -53,7 +55,7 @@ GpuWatchdogThread::GpuWatchdogThread(int timeout)
GpuWatchdogThread::~GpuWatchdogThread() { GpuWatchdogThread::~GpuWatchdogThread() {
// Verify that the thread was explicitly stopped. If the thread is stopped // Verify that the thread was explicitly stopped. If the thread is stopped
// implicitly by the destructor, CleanUp() will not be called. // implicitly by the destructor, CleanUp() will not be called.
DCHECK(!method_factory_.get()); DCHECK(!weak_factory_.HasWeakPtrs());
#if defined(OS_WIN) #if defined(OS_WIN)
CloseHandle(watched_thread_handle_); CloseHandle(watched_thread_handle_);
...@@ -67,21 +69,16 @@ void GpuWatchdogThread::PostAcknowledge() { ...@@ -67,21 +69,16 @@ void GpuWatchdogThread::PostAcknowledge() {
// the method factory. Rely on reference counting instead. // the method factory. Rely on reference counting instead.
message_loop()->PostTask( message_loop()->PostTask(
FROM_HERE, FROM_HERE,
NewRunnableMethod(this, &GpuWatchdogThread::OnAcknowledge)); base::Bind(&GpuWatchdogThread::OnAcknowledge, this));
} }
void GpuWatchdogThread::Init() { void GpuWatchdogThread::Init() {
// The method factory must be created on the watchdog thread.
method_factory_.reset(new MethodFactory(this));
// Schedule the first check. // Schedule the first check.
OnCheck(); OnCheck();
} }
void GpuWatchdogThread::CleanUp() { void GpuWatchdogThread::CleanUp() {
// The method factory must be destroyed on the watchdog thread. weak_factory_.InvalidateWeakPtrs();
method_factory_->RevokeAll();
method_factory_.reset();
} }
GpuWatchdogThread::GpuWatchdogTaskObserver::GpuWatchdogTaskObserver( GpuWatchdogThread::GpuWatchdogTaskObserver::GpuWatchdogTaskObserver(
...@@ -119,13 +116,13 @@ void GpuWatchdogThread::OnAcknowledge() { ...@@ -119,13 +116,13 @@ void GpuWatchdogThread::OnAcknowledge() {
return; return;
// Revoke any pending hang termination. // Revoke any pending hang termination.
method_factory_->RevokeAll(); weak_factory_.InvalidateWeakPtrs();
armed_ = false; armed_ = false;
// The monitored thread has responded. Post a task to check it again. // The monitored thread has responded. Post a task to check it again.
message_loop()->PostDelayedTask( message_loop()->PostDelayedTask(
FROM_HERE, FROM_HERE,
method_factory_->NewRunnableMethod(&GpuWatchdogThread::OnCheck), base::Bind(&GpuWatchdogThread::OnCheck, weak_factory_.GetWeakPtr()),
kCheckPeriod); kCheckPeriod);
} }
...@@ -182,14 +179,15 @@ void GpuWatchdogThread::OnCheck() { ...@@ -182,14 +179,15 @@ void GpuWatchdogThread::OnCheck() {
// also wake up the observer. This simply ensures there is at least one. // also wake up the observer. This simply ensures there is at least one.
watched_message_loop_->PostTask( watched_message_loop_->PostTask(
FROM_HERE, FROM_HERE,
NewRunnableFunction(DoNothing)); base::Bind(&DoNothing));
// Post a task to the watchdog thread to exit if the monitored thread does // Post a task to the watchdog thread to exit if the monitored thread does
// not respond in time. // not respond in time.
message_loop()->PostDelayedTask( message_loop()->PostDelayedTask(
FROM_HERE, FROM_HERE,
method_factory_->NewRunnableMethod( base::Bind(
&GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang), &GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang,
weak_factory_.GetWeakPtr()),
timeout_); timeout_);
} }
...@@ -202,8 +200,9 @@ void GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang() { ...@@ -202,8 +200,9 @@ void GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang() {
if (time_since_arm < timeout_) { if (time_since_arm < timeout_) {
message_loop()->PostDelayedTask( message_loop()->PostDelayedTask(
FROM_HERE, FROM_HERE,
method_factory_->NewRunnableMethod( base::Bind(
&GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang), &GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang,
weak_factory_.GetWeakPtr()),
timeout_ - time_since_arm); timeout_ - time_since_arm);
return; return;
} }
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/task.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/time.h" #include "base/time.h"
#include "content/common/gpu/gpu_watchdog.h" #include "content/common/gpu/gpu_watchdog.h"
...@@ -69,8 +69,7 @@ class GpuWatchdogThread : public base::Thread, ...@@ -69,8 +69,7 @@ class GpuWatchdogThread : public base::Thread,
base::Time arm_absolute_time_; base::Time arm_absolute_time_;
typedef ScopedRunnableMethodFactory<GpuWatchdogThread> MethodFactory; base::WeakPtrFactory<GpuWatchdogThread> weak_factory_;
scoped_ptr<MethodFactory> method_factory_;
DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment