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