Commit 5376eb75 authored by jhawkins@chromium.org's avatar jhawkins@chromium.org

base::Bind: Finish conversion in ServiceProcessControl.

BUG=none
TEST=none

R=csilv@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107878 0039d316-1c4b-4281-b951-d872f2087c98
parent acdf14f8
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/service/service_process_control.h" #include "chrome/browser/service/service_process_control.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/process_util.h" #include "base/process_util.h"
...@@ -144,8 +146,8 @@ void ServiceProcessControl::Launch(const base::Closure& success_task, ...@@ -144,8 +146,8 @@ void ServiceProcessControl::Launch(const base::Closure& success_task,
// And then start the process asynchronously. // And then start the process asynchronously.
launcher_ = new Launcher(this, cmd_line); launcher_ = new Launcher(this, cmd_line);
launcher_->Run( launcher_->Run(base::Bind(&ServiceProcessControl::OnProcessLaunched,
NewRunnableMethod(this, &ServiceProcessControl::OnProcessLaunched)); base::Unretained(this)));
} }
void ServiceProcessControl::Disconnect() { void ServiceProcessControl::Disconnect() {
...@@ -260,29 +262,30 @@ ServiceProcessControl::Launcher::Launcher(ServiceProcessControl* process, ...@@ -260,29 +262,30 @@ ServiceProcessControl::Launcher::Launcher(ServiceProcessControl* process,
// Execute the command line to start the process asynchronously. // Execute the command line to start the process asynchronously.
// After the command is executed, |task| is called with the process handle on // After the command is executed, |task| is called with the process handle on
// the UI thread. // the UI thread.
void ServiceProcessControl::Launcher::Run(Task* task) { void ServiceProcessControl::Launcher::Run(const base::Closure& task) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
notify_task_.reset(task); notify_task_ = task;
BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
NewRunnableMethod(this, &Launcher::DoRun)); base::Bind(&Launcher::DoRun, this));
} }
ServiceProcessControl::Launcher::~Launcher() {} ServiceProcessControl::Launcher::~Launcher() {}
void ServiceProcessControl::Launcher::Notify() { void ServiceProcessControl::Launcher::Notify() {
DCHECK(notify_task_.get()); DCHECK_EQ(false, notify_task_.is_null());
notify_task_->Run(); notify_task_.Run();
notify_task_.reset(); notify_task_.Reset();
} }
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
void ServiceProcessControl::Launcher::DoDetectLaunched() { void ServiceProcessControl::Launcher::DoDetectLaunched() {
DCHECK(notify_task_.get()); DCHECK_EQ(false, notify_task_.is_null());
const uint32 kMaxLaunchDetectRetries = 10; const uint32 kMaxLaunchDetectRetries = 10;
launched_ = CheckServiceProcessReady(); launched_ = CheckServiceProcessReady();
if (launched_ || (retry_count_ >= kMaxLaunchDetectRetries)) { if (launched_ || (retry_count_ >= kMaxLaunchDetectRetries)) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, BrowserThread::PostTask(
NewRunnableMethod(this, &Launcher::Notify)); BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this));
return; return;
} }
retry_count_++; retry_count_++;
...@@ -290,24 +293,24 @@ void ServiceProcessControl::Launcher::DoDetectLaunched() { ...@@ -290,24 +293,24 @@ void ServiceProcessControl::Launcher::DoDetectLaunched() {
// If the service process is not launched yet then check again in 2 seconds. // If the service process is not launched yet then check again in 2 seconds.
const int kDetectLaunchRetry = 2000; const int kDetectLaunchRetry = 2000;
MessageLoop::current()->PostDelayedTask( MessageLoop::current()->PostDelayedTask(
FROM_HERE, FROM_HERE, base::Bind(&Launcher::DoDetectLaunched, this),
NewRunnableMethod(this, &Launcher::DoDetectLaunched),
kDetectLaunchRetry); kDetectLaunchRetry);
} }
void ServiceProcessControl::Launcher::DoRun() { void ServiceProcessControl::Launcher::DoRun() {
DCHECK(notify_task_.get()); DCHECK_EQ(false, notify_task_.is_null());
base::LaunchOptions options; base::LaunchOptions options;
#if defined(OS_WIN) #if defined(OS_WIN)
options.start_hidden = true; options.start_hidden = true;
#endif #endif
if (base::LaunchProcess(*cmd_line_, options, NULL)) { if (base::LaunchProcess(*cmd_line_, options, NULL)) {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, BrowserThread::PostTask(
NewRunnableMethod(this, BrowserThread::IO, FROM_HERE,
&Launcher::DoDetectLaunched)); base::Bind(&Launcher::DoDetectLaunched, this));
} else { } else {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, BrowserThread::PostTask(
NewRunnableMethod(this, &Launcher::Notify)); BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this));
} }
} }
#endif // !OS_MACOSX #endif // !OS_MACOSX
...@@ -101,10 +101,10 @@ class ServiceProcessControl : public IPC::Channel::Sender, ...@@ -101,10 +101,10 @@ class ServiceProcessControl : public IPC::Channel::Sender,
: public base::RefCountedThreadSafe<ServiceProcessControl::Launcher> { : public base::RefCountedThreadSafe<ServiceProcessControl::Launcher> {
public: public:
Launcher(ServiceProcessControl* process, CommandLine* cmd_line); Launcher(ServiceProcessControl* process, CommandLine* cmd_line);
// Execute the command line to start the process asynchronously. // Execute the command line to start the process asynchronously. After the
// After the comamnd is executed |task| is called with the process handle on // command is executed |task| is called with the process handle on the UI
// the UI thread. // thread.
void Run(Task* task); void Run(const base::Closure& task);
bool launched() const { return launched_; } bool launched() const { return launched_; }
...@@ -120,7 +120,7 @@ class ServiceProcessControl : public IPC::Channel::Sender, ...@@ -120,7 +120,7 @@ class ServiceProcessControl : public IPC::Channel::Sender,
void Notify(); void Notify();
ServiceProcessControl* process_; ServiceProcessControl* process_;
scoped_ptr<CommandLine> cmd_line_; scoped_ptr<CommandLine> cmd_line_;
scoped_ptr<Task> notify_task_; base::Closure notify_task_;
bool launched_; bool launched_;
uint32 retry_count_; uint32 retry_count_;
}; };
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/service/service_process_control.h" #include "chrome/browser/service/service_process_control.h"
#include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "chrome/common/service_process_util_posix.h" #include "chrome/common/service_process_util_posix.h"
...@@ -21,5 +22,5 @@ void ServiceProcessControl::Launcher::DoRun() { ...@@ -21,5 +22,5 @@ void ServiceProcessControl::Launcher::DoRun() {
launched_ = true; launched_ = true;
} }
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this, &Launcher::Notify)); base::Bind(&Launcher::Notify, this));
} }
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