summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/common/service_process_util.h4
-rw-r--r--chrome/common/service_process_util_posix.cc22
-rw-r--r--chrome/common/service_process_util_posix.h5
-rw-r--r--chrome/common/service_process_util_unittest.cc21
-rw-r--r--chrome/common/service_process_util_win.cc18
-rw-r--r--chrome/service/service_process.cc5
6 files changed, 42 insertions, 33 deletions
diff --git a/chrome/common/service_process_util.h b/chrome/common/service_process_util.h
index 006247c..b5f631e 100644
--- a/chrome/common/service_process_util.h
+++ b/chrome/common/service_process_util.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/process.h"
#include "base/shared_memory.h"
@@ -72,7 +73,8 @@ class ServiceProcessState {
// |message_loop_proxy| must be of type IO and is the loop that POSIX uses
// to monitor the service process.
bool SignalReady(
- base::MessageLoopProxy* message_loop_proxy, Task* terminate_task);
+ base::MessageLoopProxy* message_loop_proxy,
+ const base::Closure& terminate_task);
// Signal that the service process is stopped.
void SignalStopped();
diff --git a/chrome/common/service_process_util_posix.cc b/chrome/common/service_process_util_posix.cc
index 41780f8..95c92fb 100644
--- a/chrome/common/service_process_util_posix.cc
+++ b/chrome/common/service_process_util_posix.cc
@@ -5,6 +5,7 @@
#include "chrome/common/service_process_util_posix.h"
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/eintr_wrapper.h"
#include "base/message_loop_proxy.h"
#include "base/synchronization/waitable_event.h"
@@ -14,7 +15,7 @@ int g_signal_socket = -1;
}
ServiceProcessTerminateMonitor::ServiceProcessTerminateMonitor(
- Task* terminate_task)
+ const base::Closure& terminate_task)
: terminate_task_(terminate_task) {
}
@@ -22,12 +23,12 @@ ServiceProcessTerminateMonitor::~ServiceProcessTerminateMonitor() {
}
void ServiceProcessTerminateMonitor::OnFileCanReadWithoutBlocking(int fd) {
- if (terminate_task_.get()) {
+ if (!terminate_task_.is_null()) {
int buffer;
int length = read(fd, &buffer, sizeof(buffer));
if ((length == sizeof(buffer)) && (buffer == kTerminateMessage)) {
- terminate_task_->Run();
- terminate_task_.reset();
+ terminate_task_.Run();
+ terminate_task_.Reset();
} else if (length > 0) {
DLOG(ERROR) << "Unexpected read: " << buffer;
} else if (length == 0) {
@@ -136,10 +137,10 @@ void ServiceProcessState::CreateState() {
}
bool ServiceProcessState::SignalReady(
- base::MessageLoopProxy* message_loop_proxy, Task* terminate_task) {
+ base::MessageLoopProxy* message_loop_proxy,
+ const base::Closure& terminate_task) {
DCHECK(state_);
- scoped_ptr<Task> scoped_terminate_task(terminate_task);
#if defined(OS_POSIX) && !defined(OS_MACOSX)
state_->running_lock_.reset(TakeServiceRunningLock(true));
if (state_->running_lock_.get() == NULL) {
@@ -147,7 +148,7 @@ bool ServiceProcessState::SignalReady(
}
#endif
state_->terminate_monitor_.reset(
- new ServiceProcessTerminateMonitor(scoped_terminate_task.release()));
+ new ServiceProcessTerminateMonitor(terminate_task));
if (pipe(state_->sockets_) < 0) {
DPLOG(ERROR) << "pipe";
return false;
@@ -156,9 +157,10 @@ bool ServiceProcessState::SignalReady(
bool success = false;
message_loop_proxy->PostTask(FROM_HERE,
- NewRunnableMethod(state_, &ServiceProcessState::StateData::SignalReady,
- &signal_ready,
- &success));
+ base::Bind(&ServiceProcessState::StateData::SignalReady,
+ state_,
+ &signal_ready,
+ &success));
signal_ready.Wait();
return success;
}
diff --git a/chrome/common/service_process_util_posix.h b/chrome/common/service_process_util_posix.h
index 2202d0a..451180a 100644
--- a/chrome/common/service_process_util_posix.h
+++ b/chrome/common/service_process_util_posix.h
@@ -10,6 +10,7 @@
#include <signal.h>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
@@ -42,7 +43,7 @@ class ServiceProcessTerminateMonitor
kTerminateMessage = 0xdecea5e
};
- explicit ServiceProcessTerminateMonitor(Task* terminate_task);
+ explicit ServiceProcessTerminateMonitor(const base::Closure& terminate_task);
virtual ~ServiceProcessTerminateMonitor();
// MessageLoopForIO::Watcher overrides
@@ -50,7 +51,7 @@ class ServiceProcessTerminateMonitor
virtual void OnFileCanWriteWithoutBlocking(int fd);
private:
- scoped_ptr<Task> terminate_task_;
+ base::Closure terminate_task_;
};
struct ServiceProcessState::StateData
diff --git a/chrome/common/service_process_util_unittest.cc b/chrome/common/service_process_util_unittest.cc
index 3add0c2..071b90d 100644
--- a/chrome/common/service_process_util_unittest.cc
+++ b/chrome/common/service_process_util_unittest.cc
@@ -5,6 +5,7 @@
#include "chrome/common/service_process_util.h"
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/process_util.h"
@@ -110,7 +111,7 @@ TEST_F(ServiceProcessStateTest, ReadyState) {
ASSERT_FALSE(CheckServiceProcessReady());
ServiceProcessState state;
ASSERT_TRUE(state.Initialize());
- ASSERT_TRUE(state.SignalReady(IOMessageLoopProxy(), NULL));
+ ASSERT_TRUE(state.SignalReady(IOMessageLoopProxy(), base::Closure()));
LaunchAndWait("ServiceProcessStateTestReadyTrue");
state.SignalStopped();
LaunchAndWait("ServiceProcessStateTestReadyFalse");
@@ -223,8 +224,8 @@ MULTIPROCESS_TEST_MAIN(ServiceProcessStateTestShutdown) {
ServiceProcessState state;
EXPECT_TRUE(state.Initialize());
EXPECT_TRUE(state.SignalReady(io_thread_.message_loop_proxy(),
- NewRunnableFunction(&ShutdownTask,
- MessageLoop::current())));
+ base::Bind(&ShutdownTask,
+ MessageLoop::current())));
message_loop.PostDelayedTask(FROM_HERE,
new MessageLoop::QuitTask(),
TestTimeouts::action_max_timeout_ms());
@@ -379,7 +380,7 @@ class ServiceProcessStateFileManipulationTest : public ::testing::Test {
ASSERT_TRUE(service_process_state_.Initialize());
ASSERT_TRUE(service_process_state_.SignalReady(
io_thread_.message_loop_proxy(),
- NULL));
+ base::Closure()));
loop_.PostDelayedTask(FROM_HERE,
new MessageLoop::QuitTask,
TestTimeouts::action_max_timeout_ms());
@@ -521,7 +522,7 @@ TEST_F(ServiceProcessStateFileManipulationTest, VerifyLaunchD) {
TEST_F(ServiceProcessStateFileManipulationTest, DeleteFile) {
GetIOMessageLoopProxy()->PostTask(
FROM_HERE,
- NewRunnableFunction(&DeleteFunc, executable_path()));
+ base::Bind(&DeleteFunc, executable_path()));
Run();
ASSERT_TRUE(mock_launchd()->remove_called());
ASSERT_TRUE(mock_launchd()->delete_called());
@@ -530,7 +531,7 @@ TEST_F(ServiceProcessStateFileManipulationTest, DeleteFile) {
TEST_F(ServiceProcessStateFileManipulationTest, DeleteBundle) {
GetIOMessageLoopProxy()->PostTask(
FROM_HERE,
- NewRunnableFunction(&DeleteFunc, bundle_path()));
+ base::Bind(&DeleteFunc, bundle_path()));
Run();
ASSERT_TRUE(mock_launchd()->remove_called());
ASSERT_TRUE(mock_launchd()->delete_called());
@@ -540,7 +541,7 @@ TEST_F(ServiceProcessStateFileManipulationTest, MoveBundle) {
FilePath new_loc = GetTempDirPath().AppendASCII("MoveBundle");
GetIOMessageLoopProxy()->PostTask(
FROM_HERE,
- NewRunnableFunction(&MoveFunc, bundle_path(), new_loc));
+ base::Bind(&MoveFunc, bundle_path(), new_loc));
Run();
ASSERT_TRUE(mock_launchd()->restart_called());
ASSERT_TRUE(mock_launchd()->write_called());
@@ -550,7 +551,7 @@ TEST_F(ServiceProcessStateFileManipulationTest, MoveFile) {
FilePath new_loc = GetTempDirPath().AppendASCII("MoveFile");
GetIOMessageLoopProxy()->PostTask(
FROM_HERE,
- NewRunnableFunction(&MoveFunc, executable_path(), new_loc));
+ base::Bind(&MoveFunc, executable_path(), new_loc));
Run();
ASSERT_TRUE(mock_launchd()->remove_called());
ASSERT_TRUE(mock_launchd()->delete_called());
@@ -561,7 +562,7 @@ TEST_F(ServiceProcessStateFileManipulationTest, TrashBundle) {
ASSERT_TRUE(base::mac::FSRefFromPath(bundle_path().value(), &bundle_ref));
GetIOMessageLoopProxy()->PostTask(
FROM_HERE,
- NewRunnableFunction(&TrashFunc, bundle_path()));
+ base::Bind(&TrashFunc, bundle_path()));
Run();
ASSERT_TRUE(mock_launchd()->remove_called());
ASSERT_TRUE(mock_launchd()->delete_called());
@@ -574,7 +575,7 @@ TEST_F(ServiceProcessStateFileManipulationTest, ChangeAttr) {
ScopedAttributesRestorer restorer(bundle_path(), 0777);
GetIOMessageLoopProxy()->PostTask(
FROM_HERE,
- NewRunnableFunction(&ChangeAttr, bundle_path(), 0222));
+ base::Bind(&ChangeAttr, bundle_path(), 0222));
Run();
ASSERT_TRUE(mock_launchd()->remove_called());
ASSERT_TRUE(mock_launchd()->delete_called());
diff --git a/chrome/common/service_process_util_win.cc b/chrome/common/service_process_util_win.cc
index 25ff7cf..cccb7a9 100644
--- a/chrome/common/service_process_util_win.cc
+++ b/chrome/common/service_process_util_win.cc
@@ -51,7 +51,7 @@ std::string GetObsoleteServiceProcessAutoRunKey() {
class ServiceProcessTerminateMonitor
: public base::win::ObjectWatcher::Delegate {
public:
- explicit ServiceProcessTerminateMonitor(Task* terminate_task)
+ explicit ServiceProcessTerminateMonitor(const base::Closure& terminate_task)
: terminate_task_(terminate_task) {
}
void Start() {
@@ -63,14 +63,16 @@ class ServiceProcessTerminateMonitor
// base::ObjectWatcher::Delegate implementation.
virtual void OnObjectSignaled(HANDLE object) {
- terminate_task_->Run();
- terminate_task_.reset();
+ if (!terminate_task_.is_null()) {
+ terminate_task_.Run();
+ terminate_task_.Reset();
+ }
}
private:
base::win::ScopedHandle terminate_event_;
base::win::ObjectWatcher watcher_;
- scoped_ptr<Task> terminate_task_;
+ base::Closure terminate_task_;
};
} // namespace
@@ -131,16 +133,16 @@ bool ServiceProcessState::TakeSingletonLock() {
}
bool ServiceProcessState::SignalReady(
- base::MessageLoopProxy* message_loop_proxy, Task* terminate_task) {
+ base::MessageLoopProxy* message_loop_proxy,
+ const base::Closure& terminate_task) {
DCHECK(state_);
DCHECK(state_->ready_event.IsValid());
- scoped_ptr<Task> scoped_terminate_task(terminate_task);
if (!SetEvent(state_->ready_event.Get())) {
return false;
}
- if (terminate_task) {
+ if (!terminate_task.is_null()) {
state_->terminate_monitor.reset(
- new ServiceProcessTerminateMonitor(scoped_terminate_task.release()));
+ new ServiceProcessTerminateMonitor(terminate_task));
state_->terminate_monitor->Start();
}
return true;
diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc
index 5088334..a7ecabc 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/i18n/rtl.h"
@@ -210,7 +211,7 @@ bool ServiceProcess::Initialize(MessageLoopForUI* message_loop,
// ready.
if (!service_process_state_->SignalReady(
io_thread_->message_loop_proxy(),
- NewRunnableMethod(this, &ServiceProcess::Terminate))) {
+ base::Bind(&ServiceProcess::Terminate, base::Unretained(this)))) {
return false;
}
@@ -345,7 +346,7 @@ void ServiceProcess::OnServiceDisabled() {
void ServiceProcess::ScheduleShutdownCheck() {
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- NewRunnableMethod(this, &ServiceProcess::ShutdownIfNeeded),
+ base::Bind(&ServiceProcess::ShutdownIfNeeded, base::Unretained(this)),
kShutdownDelay);
}