diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 23:19:51 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 23:19:51 +0000 |
commit | 1c35a4843a9b0b4db2d317c08a1dd3181c3c7be8 (patch) | |
tree | 021d68d85e1f8082e54146d199f1b6be6d05e59c /chrome/browser/service | |
parent | f824f91a3b11fabc98dce7c5f9339b7046971f29 (diff) | |
download | chromium_src-1c35a4843a9b0b4db2d317c08a1dd3181c3c7be8.zip chromium_src-1c35a4843a9b0b4db2d317c08a1dd3181c3c7be8.tar.gz chromium_src-1c35a4843a9b0b4db2d317c08a1dd3181c3c7be8.tar.bz2 |
base::Bind: Convert CloudPrintProxyService.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8368014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107235 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/service')
-rw-r--r-- | chrome/browser/service/service_process_control.cc | 54 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control.h | 22 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control_browsertest.cc | 20 |
3 files changed, 38 insertions, 58 deletions
diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc index 368ff75..de257f6 100644 --- a/chrome/browser/service/service_process_control.cc +++ b/chrome/browser/service/service_process_control.cc @@ -27,9 +27,6 @@ ServiceProcessControl::ServiceProcessControl() { } ServiceProcessControl::~ServiceProcessControl() { - STLDeleteElements(&connect_done_tasks_); - STLDeleteElements(&connect_success_tasks_); - STLDeleteElements(&connect_failure_tasks_); } void ServiceProcessControl::ConnectInternal() { @@ -55,60 +52,48 @@ void ServiceProcessControl::RunConnectDoneTasks() { // them to the stack before executing them. This way recursion is // avoided. TaskList tasks; - tasks.swap(connect_done_tasks_); - RunAllTasksHelper(&tasks); - DCHECK(tasks.empty()); if (is_connected()) { tasks.swap(connect_success_tasks_); RunAllTasksHelper(&tasks); DCHECK(tasks.empty()); - - STLDeleteElements(&connect_failure_tasks_); + connect_failure_tasks_.clear(); } else { tasks.swap(connect_failure_tasks_); RunAllTasksHelper(&tasks); DCHECK(tasks.empty()); - - STLDeleteElements(&connect_success_tasks_); + connect_success_tasks_.clear(); } - DCHECK(connect_done_tasks_.empty()); - DCHECK(connect_success_tasks_.empty()); - DCHECK(connect_failure_tasks_.empty()); + // If the same callback is passed for both success and failure tasks, one + // container or the other may not be empty. + connect_success_tasks_.clear(); + connect_failure_tasks_.clear(); } // static void ServiceProcessControl::RunAllTasksHelper(TaskList* task_list) { TaskList::iterator index = task_list->begin(); while (index != task_list->end()) { - (*index)->Run(); - delete (*index); + (*index).Run(); index = task_list->erase(index); } } -void ServiceProcessControl::Launch(Task* success_task, Task* failure_task) { +void ServiceProcessControl::Launch(const base::Closure& success_task, + const base::Closure& failure_task) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (success_task) { - if (success_task == failure_task) { - // If the tasks are the same, then the same task needs to be invoked - // for success and failure. - failure_task = NULL; - connect_done_tasks_.push_back(success_task); - } else { - connect_success_tasks_.push_back(success_task); - } - } + base::Closure failure = failure_task; + if (!success_task.is_null()) + connect_success_tasks_.push_back(success_task); - if (failure_task) - connect_failure_tasks_.push_back(failure_task); + if (!failure.is_null()) + connect_failure_tasks_.push_back(failure); // If we already in the process of launching, then we are done. - if (launcher_) { + if (launcher_) return; - } // If the service process is already running then connects to it. if (CheckServiceProcessReady()) { @@ -126,9 +111,8 @@ void ServiceProcessControl::Launch(Task* success_task, Task* failure_task) { #endif FilePath exe_path = ChildProcessHost::GetChildPath(flags); - if (exe_path.empty()) { + if (exe_path.empty()) NOTREACHED() << "Unable to get service process binary name."; - } CommandLine* cmd_line = new CommandLine(exe_path); cmd_line->AppendSwitchASCII(switches::kProcessType, @@ -155,13 +139,11 @@ void ServiceProcessControl::Launch(Task* success_task, Task* failure_task) { if (!v_modules.empty()) cmd_line->AppendSwitchASCII(switches::kVModule, v_modules); - if (browser_command_line.HasSwitch(switches::kWaitForDebuggerChildren)) { + if (browser_command_line.HasSwitch(switches::kWaitForDebuggerChildren)) cmd_line->AppendSwitch(switches::kWaitForDebugger); - } - if (browser_command_line.HasSwitch(switches::kEnableLogging)) { + if (browser_command_line.HasSwitch(switches::kEnableLogging)) cmd_line->AppendSwitch(switches::kEnableLogging); - } std::string locale = g_browser_process->GetApplicationLocale(); cmd_line->AppendSwitchASCII(switches::kLang, locale); diff --git a/chrome/browser/service/service_process_control.h b/chrome/browser/service/service_process_control.h index 69740b4..eba4866 100644 --- a/chrome/browser/service/service_process_control.h +++ b/chrome/browser/service/service_process_control.h @@ -11,6 +11,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/callback.h" #include "base/callback_old.h" #include "base/id_map.h" #include "base/memory/scoped_ptr.h" @@ -52,9 +53,8 @@ class ServiceProcessControl : public IPC::Channel::Sender, bool is_connected() const { return channel_.get() != NULL; } // If no service process is currently running, creates a new service process - // and connects to it. - // If a service process is already running this method will try to connect - // to it. + // and connects to it. If a service process is already running this method + // will try to connect to it. // |success_task| is called when we have successfully launched the process // and connected to it. // |failure_task| is called when we failed to connect to the service process. @@ -62,8 +62,9 @@ class ServiceProcessControl : public IPC::Channel::Sender, // this case, the task is invoked on success or failure. // Note that if we are already connected to service process then // |success_task| can be invoked in the context of the Launch call. - // Takes ownership of |success_task| and |failure_task|. - void Launch(Task* success_task, Task* failure_task); + void Launch(const base::Closure& success_task, + const base::Closure& failure_task); + // Disconnect the IPC channel from the service process. void Disconnect(); @@ -130,9 +131,9 @@ class ServiceProcessControl : public IPC::Channel::Sender, friend struct DefaultSingletonTraits<ServiceProcessControl>; - typedef std::vector<Task*> TaskList; + typedef std::vector<base::Closure> TaskList; - // Helper method to invoke all the callbacks based on success on failure. + // Helper method to invoke all the callbacks based on success or failure. void RunConnectDoneTasks(); // Method called by Launcher when the service process is launched. @@ -149,12 +150,9 @@ class ServiceProcessControl : public IPC::Channel::Sender, // Service process launcher. scoped_refptr<Launcher> launcher_; - // Callbacks that get invoked when the channel is successfully connected or - // if there was a failure in connecting. - TaskList connect_done_tasks_; - // Callbacks that get invoked ONLY when the channel is successfully connected. + // Callbacks that get invoked when the channel is successfully connected. TaskList connect_success_tasks_; - // Callbacks that get invoked ONLY when there was a connection failure. + // Callbacks that get invoked when there was a connection failure. TaskList connect_failure_tasks_; // Callback that gets invoked when a status message is received from diff --git a/chrome/browser/service/service_process_control_browsertest.cc b/chrome/browser/service/service_process_control_browsertest.cc index 4a41c4d..4a37367 100644 --- a/chrome/browser/service/service_process_control_browsertest.cc +++ b/chrome/browser/service/service_process_control_browsertest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" +#include "base/callback.h" #include "base/process_util.h" #include "base/test/test_timeouts.h" #include "chrome/browser/service/service_process_control.h" @@ -33,12 +35,11 @@ class ServiceProcessControlBrowserTest void LaunchServiceProcessControl() { // Launch the process asynchronously. ServiceProcessControl::GetInstance()->Launch( - NewRunnableMethod( - this, - &ServiceProcessControlBrowserTest::ProcessControlLaunched), - NewRunnableMethod( - this, - &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed)); + base::Bind(&ServiceProcessControlBrowserTest::ProcessControlLaunched, + this), + base::Bind( + &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed, + this)); // Then run the message loop to keep things running. ui_test_utils::RunMessageLoop(); @@ -139,9 +140,8 @@ IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, int launch_count = 5; for (int i = 0; i < launch_count; i++) { // Launch the process asynchronously. - process->Launch( - NewRunnableFunction(&DecrementUntilZero, &launch_count), - new MessageLoop::QuitTask()); + process->Launch(base::Bind(&DecrementUntilZero, &launch_count), + MessageLoop::QuitClosure()); } // Then run the message loop to keep things running. ui_test_utils::RunMessageLoop(); @@ -156,7 +156,7 @@ IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, SameLaunchTask) { int launch_count = 5; for (int i = 0; i < launch_count; i++) { // Launch the process asynchronously. - Task * task = NewRunnableFunction(&DecrementUntilZero, &launch_count); + base::Closure task = base::Bind(&DecrementUntilZero, &launch_count); process->Launch(task, task); } // Then run the message loop to keep things running. |