summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 01:20:36 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 01:20:36 +0000
commit8c6517e5e15b7e9a3d3c95f697f674d221968acc (patch)
tree315dfbae873b9b79e2aa62bc1b51de1c307189b7
parent83fc28d5f4523f516154f63c08a084d26d9aab6e (diff)
downloadchromium_src-8c6517e5e15b7e9a3d3c95f697f674d221968acc.zip
chromium_src-8c6517e5e15b7e9a3d3c95f697f674d221968acc.tar.gz
chromium_src-8c6517e5e15b7e9a3d3c95f697f674d221968acc.tar.bz2
base::Bind: Cleanup in automation.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8212006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105761 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/message_loop.cc14
-rw-r--r--base/message_loop.h14
-rw-r--r--chrome/browser/automation/automation_provider_gtk.cc121
-rw-r--r--chrome/browser/automation/automation_provider_win.cc3
-rw-r--r--chrome/browser/automation/automation_resource_message_filter.cc31
-rw-r--r--chrome/browser/automation/automation_resource_message_filter.h2
-rw-r--r--chrome/browser/automation/automation_util.cc34
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc11
-rw-r--r--chrome/browser/automation/testing_automation_provider_views.cc12
-rw-r--r--chrome/browser/automation/ui_controls.h24
-rw-r--r--chrome/browser/automation/ui_controls_gtk.cc30
-rw-r--r--chrome/browser/automation/ui_controls_internal.cc14
-rw-r--r--chrome/browser/automation/ui_controls_internal.h20
-rw-r--r--chrome/browser/automation/ui_controls_mac.mm82
-rw-r--r--chrome/browser/automation/ui_controls_win.cc47
-rw-r--r--chrome/browser/automation/url_request_automation_job.cc15
-rw-r--r--chrome/browser/automation/url_request_automation_job.h5
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc35
-rw-r--r--chrome/browser/ui/views/menu_item_view_test.cc3
-rw-r--r--chrome/browser/ui/views/menu_model_adapter_test.cc5
-rw-r--r--chrome/test/base/ui_test_utils.cc2
-rw-r--r--chrome/test/base/ui_test_utils_gtk.cc2
-rw-r--r--chrome/test/base/ui_test_utils_mac.mm2
-rw-r--r--chrome/test/base/ui_test_utils_win.cc2
-rw-r--r--chrome/test/base/view_event_test_base.cc16
-rw-r--r--chrome/test/base/view_event_test_base.h15
26 files changed, 251 insertions, 310 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc
index ce5e900..f2e07b9 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -306,7 +306,7 @@ void MessageLoop::PostNonNestableDelayedTask(
void MessageLoop::PostTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
- CHECK(!task.is_null());
+ CHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(task, from_here, CalculateDelayedRuntime(0), true);
AddToIncomingQueue(&pending_task);
}
@@ -314,7 +314,7 @@ void MessageLoop::PostTask(
void MessageLoop::PostDelayedTask(
const tracked_objects::Location& from_here, const base::Closure& task,
int64 delay_ms) {
- CHECK(!task.is_null());
+ CHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(task, from_here,
CalculateDelayedRuntime(delay_ms), true);
AddToIncomingQueue(&pending_task);
@@ -322,7 +322,7 @@ void MessageLoop::PostDelayedTask(
void MessageLoop::PostNonNestableTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
- CHECK(!task.is_null());
+ CHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(task, from_here, CalculateDelayedRuntime(0), false);
AddToIncomingQueue(&pending_task);
}
@@ -330,7 +330,7 @@ void MessageLoop::PostNonNestableTask(
void MessageLoop::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here, const base::Closure& task,
int64 delay_ms) {
- CHECK(!task.is_null());
+ CHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(task, from_here,
CalculateDelayedRuntime(delay_ms), false);
AddToIncomingQueue(&pending_task);
@@ -365,6 +365,12 @@ void MessageLoop::QuitNow() {
}
}
+// static
+base::Closure MessageLoop::QuitClosure() {
+ return base::Bind(&MessageLoop::Quit,
+ base::Unretained(MessageLoop::current()));
+}
+
void MessageLoop::SetNestableTasksAllowed(bool allowed) {
if (nestable_tasks_allowed_ != allowed) {
nestable_tasks_allowed_ = allowed;
diff --git a/base/message_loop.h b/base/message_loop.h
index 29c736c..adb58e3 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -242,11 +242,10 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
// messages. This method may only be called on the same thread that called
// Run, and Run must still be on the call stack.
//
- // Use QuitTask if you need to Quit another thread's MessageLoop, but note
- // that doing so is fairly dangerous if the target thread makes nested calls
- // to MessageLoop::Run. The problem being that you won't know which nested
- // run loop you are quiting, so be careful!
- //
+ // Use QuitTask or QuitClosure if you need to Quit another thread's
+ // MessageLoop, but note that doing so is fairly dangerous if the target
+ // thread makes nested calls to MessageLoop::Run. The problem being that you
+ // won't know which nested run loop you are quitting, so be careful!
void Quit();
// This method is a variant of Quit, that does not wait for pending messages
@@ -255,6 +254,7 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
// Invokes Quit on the current MessageLoop when run. Useful to schedule an
// arbitrary MessageLoop to Quit.
+ // TODO(jhawkins): Remove once task.h is removed.
class QuitTask : public Task {
public:
virtual void Run() {
@@ -262,6 +262,10 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
}
};
+ // Invokes Quit on the current MessageLoop when run. Useful to schedule an
+ // arbitrary MessageLoop to Quit.
+ static base::Closure QuitClosure();
+
// Returns the type passed to the constructor.
Type type() const { return type_; }
diff --git a/chrome/browser/automation/automation_provider_gtk.cc b/chrome/browser/automation/automation_provider_gtk.cc
index 11b6d31..0dfec43 100644
--- a/chrome/browser/automation/automation_provider_gtk.cc
+++ b/chrome/browser/automation/automation_provider_gtk.cc
@@ -6,6 +6,9 @@
#include <gtk/gtk.h>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/automation/automation_browser_tracker.h"
#include "chrome/browser/automation/automation_window_tracker.h"
@@ -18,90 +21,21 @@
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
-void AutomationProvider::PrintAsync(int tab_handle) {
- NOTIMPLEMENTED();
-}
-
-// This task sends a WindowDragResponse message with the appropriate
-// routing ID to the automation proxy. This is implemented as a task so that
-// we know that the mouse events (and any tasks that they spawn on the message
-// loop) have been processed by the time this is sent.
-class WindowDragResponseTask : public Task {
- public:
- WindowDragResponseTask(AutomationProvider* provider,
- IPC::Message* reply_message)
- : provider_(provider),
- reply_message_(reply_message) {
- DCHECK(provider_);
- DCHECK(reply_message_);
- }
-
- virtual ~WindowDragResponseTask() {
- }
+namespace {
- virtual void Run() {
- AutomationMsg_WindowDrag::WriteReplyParams(reply_message_, true);
- provider_->Send(reply_message_);
- }
-
- private:
- AutomationProvider* provider_;
- IPC::Message* reply_message_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask);
-};
-
-// A task that just runs a SendMouseEvent and performs another task when done.
-class MouseEventTask : public Task {
- public:
- MouseEventTask(Task* next_task, ui_controls::MouseButtonState state)
- : next_task_(next_task),
- state_(state) {}
-
- virtual ~MouseEventTask() {
- }
-
- virtual void Run() {
- ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT, state_,
- next_task_);
- }
-
- private:
- // The task to execute when we are done.
- Task* next_task_;
-
- // Mouse press or mouse release.
- ui_controls::MouseButtonState state_;
-
- DISALLOW_COPY_AND_ASSIGN(MouseEventTask);
-};
-
-// A task that just runs a SendMouseMove and performs another task when done.
-class MouseMoveTask : public Task {
- public:
- MouseMoveTask(Task* next_task, int absolute_x, int absolute_y)
- : next_task_(next_task),
- x_(absolute_x),
- y_(absolute_y) {
- }
-
- virtual ~MouseMoveTask() {
- }
-
- virtual void Run() {
- ui_controls::SendMouseMoveNotifyWhenDone(x_, y_, next_task_);
- }
-
- private:
- // The task to execute when we are done.
- Task* next_task_;
+// This function sends a WindowDragResponse message with the appropriate routing
+// ID to the automation proxy.
+void SendWindowDragResponse(AutomationProvider* provider,
+ IPC::Message* reply_message) {
+ AutomationMsg_WindowDrag::WriteReplyParams(reply_message, true);
+ provider->Send(reply_message);
+}
- // Coordinates of the press.
- int x_;
- int y_;
+} // namespace
- DISALLOW_COPY_AND_ASSIGN(MouseMoveTask);
-};
+void AutomationProvider::PrintAsync(int tab_handle) {
+ NOTIMPLEMENTED();
+}
void AutomationProvider::WindowSimulateDrag(
int handle,
@@ -117,9 +51,14 @@ void AutomationProvider::WindowSimulateDrag(
gdk_window_get_position(GTK_WIDGET(window)->window, &x, &y);
// Create a nested stack of tasks to run.
- Task* next_task = new WindowDragResponseTask(this, reply_message);
- next_task = new MouseEventTask(next_task, ui_controls::UP);
- next_task = new MouseEventTask(next_task, ui_controls::UP);
+ base::Closure drag_response_cb = base::Bind(
+ &SendWindowDragResponse, make_scoped_refptr(this), reply_message);
+ base::Closure move_chain_cb = base::IgnoreReturn<bool>(
+ base::Bind(&ui_controls::SendMouseEventsNotifyWhenDone,
+ ui_controls::LEFT, ui_controls::UP, drag_response_cb));
+ move_chain_cb = base::IgnoreReturn<bool>(
+ base::Bind(&ui_controls::SendMouseEventsNotifyWhenDone,
+ ui_controls::LEFT, ui_controls::UP, move_chain_cb));
for (size_t i = drag_path.size() - 1; i > 0; --i) {
// Smooth out the mouse movements by adding intermediate points. This
// better simulates a real user drag.
@@ -128,14 +67,20 @@ void AutomationProvider::WindowSimulateDrag(
int half_step_x = (dest_x + drag_path[i - 1].x() + x) / 2;
int half_step_y = (dest_y + drag_path[i - 1].y() + y) / 2;
- next_task = new MouseMoveTask(next_task, dest_x, dest_y);
- next_task = new MouseMoveTask(next_task, half_step_x, half_step_y);
+ move_chain_cb = base::IgnoreReturn<bool>(
+ base::Bind(&ui_controls::SendMouseMoveNotifyWhenDone, dest_x, dest_y,
+ move_chain_cb));
+ move_chain_cb = base::IgnoreReturn<bool>(
+ base::Bind(&ui_controls::SendMouseMoveNotifyWhenDone, half_step_x,
+ half_step_y, move_chain_cb));
}
- next_task = new MouseEventTask(next_task, ui_controls::DOWN);
+ move_chain_cb = base::IgnoreReturn<bool>(
+ base::Bind(&ui_controls::SendMouseEventsNotifyWhenDone,
+ ui_controls::LEFT, ui_controls::DOWN, move_chain_cb));
ui_controls::SendMouseMoveNotifyWhenDone(x + drag_path[0].x(),
y + drag_path[0].y(),
- next_task);
+ move_chain_cb);
} else {
AutomationMsg_WindowDrag::WriteReplyParams(reply_message, false);
Send(reply_message);
diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc
index e624962..95e28ea 100644
--- a/chrome/browser/automation/automation_provider_win.cc
+++ b/chrome/browser/automation/automation_provider_win.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/automation/automation_provider.h"
+#include "base/callback.h"
#include "base/debug/trace_event.h"
#include "base/json/json_reader.h"
#include "base/utf_string_conversions.h"
@@ -211,7 +212,7 @@ void AutomationProvider::WindowSimulateDrag(
ui::EF_SHIFT_DOWN),
((flags & ui::EF_ALT_DOWN) == ui::EF_ALT_DOWN),
false,
- new MessageLoop::QuitTask());
+ MessageLoop::QuitClosure());
MessageLoopForUI* loop = MessageLoopForUI::current();
bool did_allow_task_nesting = loop->NestableTasksAllowed();
loop->SetNestableTasksAllowed(true);
diff --git a/chrome/browser/automation/automation_resource_message_filter.cc b/chrome/browser/automation/automation_resource_message_filter.cc
index 664efcf..9206d24 100644
--- a/chrome/browser/automation/automation_resource_message_filter.cc
+++ b/chrome/browser/automation/automation_resource_message_filter.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/automation/automation_resource_message_filter.h"
+#include "base/bind.h"
#include "base/path_service.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
@@ -64,8 +65,7 @@ AutomationResourceMessageFilter::AutomationResourceMessageFilter()
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(
- URLRequestAutomationJob::EnsureProtocolFactoryRegistered));
+ base::Bind(&URLRequestAutomationJob::EnsureProtocolFactoryRegistered));
}
AutomationResourceMessageFilter::~AutomationResourceMessageFilter() {
@@ -223,13 +223,9 @@ bool AutomationResourceMessageFilter::RegisterRenderView(
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(
- AutomationResourceMessageFilter::RegisterRenderViewInIOThread,
- renderer_pid,
- renderer_id,
- tab_handle,
- make_scoped_refptr(filter),
- pending_view));
+ base::Bind(&AutomationResourceMessageFilter::RegisterRenderViewInIOThread,
+ renderer_pid, renderer_id, tab_handle,
+ make_scoped_refptr(filter), pending_view));
return true;
}
@@ -237,8 +233,8 @@ void AutomationResourceMessageFilter::UnRegisterRenderView(
int renderer_pid, int renderer_id) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(
- AutomationResourceMessageFilter::UnRegisterRenderViewInIOThread,
+ base::Bind(
+ &AutomationResourceMessageFilter::UnRegisterRenderViewInIOThread,
renderer_pid, renderer_id));
}
@@ -252,12 +248,9 @@ bool AutomationResourceMessageFilter::ResumePendingRenderView(
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(
- AutomationResourceMessageFilter::ResumePendingRenderViewInIOThread,
- renderer_pid,
- renderer_id,
- tab_handle,
- make_scoped_refptr(filter)));
+ base::Bind(
+ &AutomationResourceMessageFilter::ResumePendingRenderViewInIOThread,
+ renderer_pid, renderer_id, tab_handle, make_scoped_refptr(filter)));
return true;
}
@@ -299,7 +292,7 @@ void AutomationResourceMessageFilter::UnRegisterRenderViewInIOThread(
}
// static
-bool AutomationResourceMessageFilter::ResumePendingRenderViewInIOThread(
+void AutomationResourceMessageFilter::ResumePendingRenderViewInIOThread(
int renderer_pid, int renderer_id, int tab_handle,
AutomationResourceMessageFilter* filter) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
@@ -314,7 +307,6 @@ bool AutomationResourceMessageFilter::ResumePendingRenderViewInIOThread(
<< renderer_pid
<< ", render view id:"
<< renderer_id;
- return false;
}
DCHECK(automation_details_iter->second.is_pending_render_view);
@@ -327,7 +319,6 @@ bool AutomationResourceMessageFilter::ResumePendingRenderViewInIOThread(
AutomationDetails(tab_handle, filter, false);
ResumeJobsForPendingView(tab_handle, old_filter, filter);
- return true;
}
bool AutomationResourceMessageFilter::LookupRegisteredRenderView(
diff --git a/chrome/browser/automation/automation_resource_message_filter.h b/chrome/browser/automation/automation_resource_message_filter.h
index c4b1f4d..d95886d 100644
--- a/chrome/browser/automation/automation_resource_message_filter.h
+++ b/chrome/browser/automation/automation_resource_message_filter.h
@@ -140,7 +140,7 @@ class AutomationResourceMessageFilter
bool pending_view);
static void UnRegisterRenderViewInIOThread(int renderer_pid, int renderer_id);
- static bool ResumePendingRenderViewInIOThread(
+ static void ResumePendingRenderViewInIOThread(
int renderer_pid, int renderer_id, int tab_handle,
AutomationResourceMessageFilter* filter);
diff --git a/chrome/browser/automation/automation_util.cc b/chrome/browser/automation/automation_util.cc
index 132ad14..8c91ce0 100644
--- a/chrome/browser/automation/automation_util.cc
+++ b/chrome/browser/automation/automation_util.cc
@@ -152,9 +152,8 @@ void GetCookies(const GURL& url,
base::WaitableEvent event(true /* manual reset */,
false /* not initially signaled */);
CHECK(BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&GetCookiesOnIOThread,
- url, context_getter, &event, value)));
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&GetCookiesOnIOThread, url, context_getter, &event, value)));
event.Wait();
*value_size = static_cast<int>(value->size());
@@ -174,10 +173,9 @@ void SetCookie(const GURL& url,
false /* not initially signaled */);
bool success = false;
CHECK(BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&SetCookieOnIOThread,
- url, value, context_getter, &event,
- &success)));
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&SetCookieOnIOThread, url, value, context_getter, &event,
+ &success)));
event.Wait();
if (success)
*response_value = 1;
@@ -195,9 +193,9 @@ void DeleteCookie(const GURL& url,
base::WaitableEvent event(true /* manual reset */,
false /* not initially signaled */);
CHECK(BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&DeleteCookieOnIOThread,
- url, cookie_name, context_getter, &event)));
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&DeleteCookieOnIOThread, url, cookie_name, context_getter,
+ &event)));
event.Wait();
*success = true;
}
@@ -220,9 +218,8 @@ void GetCookiesJSON(AutomationProvider* provider,
net::CookieList cookie_list;
base::WaitableEvent event(true /* manual reset */,
false /* not initially signaled */);
- Task* task = NewRunnableFunction(
- &GetCanonicalCookiesOnIOThread,
- GURL(url), context_getter, &event, &cookie_list);
+ base::Closure task = base::Bind(&GetCanonicalCookiesOnIOThread, GURL(url),
+ context_getter, &event, &cookie_list);
if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) {
reply.SendError("Couldn't post task to get the cookies");
return;
@@ -268,9 +265,8 @@ void DeleteCookieJSON(AutomationProvider* provider,
base::WaitableEvent event(true /* manual reset */,
false /* not initially signaled */);
- Task* task = NewRunnableFunction(
- &DeleteCookieOnIOThread,
- GURL(url), name, context_getter, &event);
+ base::Closure task = base::Bind(&DeleteCookieOnIOThread, GURL(url), name,
+ context_getter, &event);
if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) {
reply.SendError("Couldn't post task to delete the cookie");
return;
@@ -358,9 +354,9 @@ void SetCookieJSON(AutomationProvider* provider,
base::WaitableEvent event(true /* manual reset */,
false /* not initially signaled */);
bool success = false;
- Task* task = NewRunnableFunction(
- &SetCookieWithDetailsOnIOThread,
- GURL(url), *cookie.get(), domain, context_getter, &event, &success);
+ base::Closure task = base::Bind(
+ &SetCookieWithDetailsOnIOThread, GURL(url), *cookie.get(), domain,
+ context_getter, &event, &success);
if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) {
reply.SendError("Couldn't post task to set the cookie");
return;
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index ac2e654..58a0474 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -216,8 +216,9 @@ void TestingAutomationProvider::OnBrowserRemoved(const Browser* browser) {
switches::kKeepAliveForTest)) {
// If you change this, update Observer for chrome::SESSION_END
// below.
- MessageLoop::current()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&TestingAutomationProvider::OnRemoveProvider, this));
}
}
@@ -876,7 +877,7 @@ void TestingAutomationProvider::WindowSimulateClick(const IPC::Message& message,
if (window_tracker_->ContainsHandle(handle)) {
// TODO(phajdan.jr): This is flaky. We should wait for the final click.
ui_controls::SendMouseMoveNotifyWhenDone(
- click.x(), click.y(), NewRunnableFunction(&SendMouseClick, flags));
+ click.x(), click.y(), base::Bind(&SendMouseClick, flags));
}
}
@@ -5542,8 +5543,8 @@ void TestingAutomationProvider::SendOSLevelKeyEventToTab(
if (!ui_controls::SendKeyPressNotifyWhenDone(
window, static_cast<ui::KeyboardCode>(keycode),
control, shift, alt, meta,
- NewRunnableMethod(this,
- &TestingAutomationProvider::SendSuccessReply, reply_message))) {
+ base::Bind(&TestingAutomationProvider::SendSuccessReply, this,
+ reply_message))) {
AutomationJSONReply(this, reply_message)
.SendError("Could not send the native key event");
}
diff --git a/chrome/browser/automation/testing_automation_provider_views.cc b/chrome/browser/automation/testing_automation_provider_views.cc
index 40af25b..9a02bb0 100644
--- a/chrome/browser/automation/testing_automation_provider_views.cc
+++ b/chrome/browser/automation/testing_automation_provider_views.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/automation/testing_automation_provider.h"
+#include "base/bind.h"
+#include "base/memory/weak_ptr.h"
#include "base/compiler_specific.h"
#include "chrome/browser/automation/automation_browser_tracker.h"
#include "chrome/browser/automation/automation_window_tracker.h"
@@ -30,7 +32,7 @@ class ViewFocusChangeWaiter : public views::FocusChangeListener {
previous_view_id_(previous_view_id),
automation_(automation),
reply_message_(reply_message),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
focus_manager_->AddFocusChangeListener(this);
// Call the focus change notification once in case the focus has
// already changed.
@@ -48,10 +50,8 @@ class ViewFocusChangeWaiter : public views::FocusChangeListener {
// that will get run after focus changes.
MessageLoop::current()->PostTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &ViewFocusChangeWaiter::FocusChanged,
- focused_before,
- focused_now));
+ base::Bind(&ViewFocusChangeWaiter::FocusChanged,
+ weak_factory_.GetWeakPtr(), focused_before, focused_now));
}
private:
@@ -70,7 +70,7 @@ class ViewFocusChangeWaiter : public views::FocusChangeListener {
int previous_view_id_;
AutomationProvider* automation_;
IPC::Message* reply_message_;
- ScopedRunnableMethodFactory<ViewFocusChangeWaiter> method_factory_;
+ base::WeakPtrFactory<ViewFocusChangeWaiter> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ViewFocusChangeWaiter);
};
diff --git a/chrome/browser/automation/ui_controls.h b/chrome/browser/automation/ui_controls.h
index 7d7b0bf..210dfec 100644
--- a/chrome/browser/automation/ui_controls.h
+++ b/chrome/browser/automation/ui_controls.h
@@ -12,6 +12,7 @@
#include <wtypes.h>
#endif
+#include "base/callback.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/point.h"
@@ -22,16 +23,14 @@ class View;
}
#endif
-class Task;
-
namespace ui_controls {
-// Many of the functions in this class include a variant that takes a Task.
-// The version that takes a Task waits until the generated event is processed.
-// Once the generated event is processed the Task is Run (and deleted). Note
-// that this is a somewhat fragile process in that any event of the correct
-// type (key down, mouse click, etc.) will trigger the Task to be run. Hence
-// a usage such as
+// Many of the functions in this class include a variant that takes a Closure.
+// The version that takes a Closure waits until the generated event is
+// processed. Once the generated event is processed the Closure is Run (and
+// deleted). Note that this is a somewhat fragile process in that any event of
+// the correct type (key down, mouse click, etc.) will trigger the Closure to be
+// run. Hence a usage such as
//
// SendKeyPress(...);
// SendKeyPressNotifyWhenDone(..., task);
@@ -57,11 +56,11 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
bool shift,
bool alt,
bool command,
- Task* task);
+ const base::Closure& task);
// Simulate a mouse move. (x,y) are absolute screen coordinates.
bool SendMouseMove(long x, long y);
-bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task);
+bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task);
enum MouseButton {
LEFT = 0,
@@ -79,7 +78,8 @@ enum MouseButtonState {
// the cursor currently is, so be sure to move the cursor before calling this
// (and be sure the cursor has arrived!).
bool SendMouseEvents(MouseButton type, int state);
-bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task);
+bool SendMouseEventsNotifyWhenDone(MouseButton type, int state,
+ const base::Closure& task);
// Same as SendMouseEvents with UP | DOWN.
bool SendMouseClick(MouseButton type);
@@ -95,7 +95,7 @@ void MoveMouseToCenterAndPress(
#endif
MouseButton button,
int state,
- Task* task);
+ const base::Closure& task);
} // ui_controls
diff --git a/chrome/browser/automation/ui_controls_gtk.cc b/chrome/browser/automation/ui_controls_gtk.cc
index db52ea2..1505b73 100644
--- a/chrome/browser/automation/ui_controls_gtk.cc
+++ b/chrome/browser/automation/ui_controls_gtk.cc
@@ -7,6 +7,7 @@
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "chrome/browser/automation/ui_controls_internal.h"
@@ -31,7 +32,7 @@ guint32 XTimeNow() {
class EventWaiter : public MessageLoopForUI::Observer {
public:
- EventWaiter(Task* task, GdkEventType type, int count)
+ EventWaiter(const base::Closure& task, GdkEventType type, int count)
: task_(task),
type_(type),
count_(count) {
@@ -71,9 +72,7 @@ class EventWaiter : public MessageLoopForUI::Observer {
#endif
private:
- // We pass ownership of task_ to MessageLoop when the current event is
- // received.
- Task* task_;
+ base::Closure task_;
GdkEventType type_;
// The number of events of this type to wait for.
int count_;
@@ -161,7 +160,7 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
bool shift,
bool alt,
bool command,
- Task* task) {
+ const base::Closure& task) {
DCHECK(!command); // No command key on Linux
int release_count = 1;
if (control)
@@ -185,7 +184,7 @@ bool SendMouseMove(long x, long y) {
return true;
}
-bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
+bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task) {
bool rv = SendMouseMove(x, y);
new EventWaiter(task, GDK_MOTION_NOTIFY, 1);
return rv;
@@ -241,7 +240,8 @@ bool SendMouseEvents(MouseButton type, int state) {
return false;
}
-bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
+bool SendMouseEventsNotifyWhenDone(MouseButton type, int state,
+ const base::Closure& task) {
bool rv = SendMouseEvents(type, state);
GdkEventType wait_type;
if (state & UP) {
@@ -291,7 +291,7 @@ void SynchronizeWidgetSize(views::Widget* widget) {
#endif
void MoveMouseToCenterAndPress(views::View* view, MouseButton button,
- int state, Task* task) {
+ int state, const base::Closure& task) {
#if defined(OS_LINUX) && !defined(USE_AURA)
// X is asynchronous and we need to wait until the window gets
// resized to desired size.
@@ -300,18 +300,20 @@ void MoveMouseToCenterAndPress(views::View* view, MouseButton button,
gfx::Point view_center(view->width() / 2, view->height() / 2);
views::View::ConvertPointToScreen(view, &view_center);
- SendMouseMoveNotifyWhenDone(view_center.x(), view_center.y(),
- new ClickTask(button, state, task));
+ SendMouseMoveNotifyWhenDone(
+ view_center.x(), view_center.y(),
+ base::Bind(&ui_controls::ClickTask, button, state, task));
}
#else
void MoveMouseToCenterAndPress(GtkWidget* widget,
MouseButton button,
int state,
- Task* task) {
+ const base::Closure& task) {
gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget);
- SendMouseMoveNotifyWhenDone(bounds.x() + bounds.width() / 2,
- bounds.y() + bounds.height() / 2,
- new ClickTask(button, state, task));
+ SendMouseMoveNotifyWhenDone(
+ bounds.x() + bounds.width() / 2,
+ bounds.y() + bounds.height() / 2,
+ base::Bind(&ui_controls::ClickTask, button, state, task));
}
#endif
diff --git a/chrome/browser/automation/ui_controls_internal.cc b/chrome/browser/automation/ui_controls_internal.cc
index 25598e8..8cb5ec3 100644
--- a/chrome/browser/automation/ui_controls_internal.cc
+++ b/chrome/browser/automation/ui_controls_internal.cc
@@ -6,17 +6,11 @@
namespace ui_controls {
-ClickTask::ClickTask(MouseButton button, int state, Task* followup)
- : button_(button), state_(state), followup_(followup) {
-}
-
-ClickTask::~ClickTask() {}
-
-void ClickTask::Run() {
- if (followup_)
- SendMouseEventsNotifyWhenDone(button_, state_, followup_);
+void ClickTask(MouseButton button, int state, const base::Closure& followup) {
+ if (!followup.is_null())
+ SendMouseEventsNotifyWhenDone(button, state, followup);
else
- SendMouseEvents(button_, state_);
+ SendMouseEvents(button, state);
}
} // ui_controls
diff --git a/chrome/browser/automation/ui_controls_internal.h b/chrome/browser/automation/ui_controls_internal.h
index 5ec9a81..39d0c7df 100644
--- a/chrome/browser/automation/ui_controls_internal.h
+++ b/chrome/browser/automation/ui_controls_internal.h
@@ -5,26 +5,14 @@
#ifndef CHROME_BROWSER_AUTOMATION_UI_CONTROLS_INTERNAL_H_
#define CHROME_BROWSER_AUTOMATION_UI_CONTROLS_INTERNAL_H_
-#include "base/task.h"
+#include "base/callback.h"
#include "chrome/browser/automation/ui_controls.h"
namespace ui_controls {
-// A utility class to send a mouse click event in a task.
-// It's shared by ui_controls_linux.cc and ui_controls_mac.cc
-class ClickTask : public Task {
- public:
- // A |followup| Task can be specified to notify the caller when the mouse
- // click event is sent. If can be NULL if the caller does not care about it.
- ClickTask(MouseButton button, int state, Task* followup);
- virtual ~ClickTask();
- virtual void Run();
-
- private:
- MouseButton button_;
- int state_;
- Task* followup_;
-};
+// A utility function to send a mouse click event in a closure. It's shared by
+// ui_controls_linux.cc and ui_controls_mac.cc
+void ClickTask(MouseButton button, int state, const base::Closure& followup);
} // namespace ui_controls
diff --git a/chrome/browser/automation/ui_controls_mac.mm b/chrome/browser/automation/ui_controls_mac.mm
index 6e38ef7..4dd9918 100644
--- a/chrome/browser/automation/ui_controls_mac.mm
+++ b/chrome/browser/automation/ui_controls_mac.mm
@@ -8,6 +8,8 @@
#include <mach/mach_time.h>
#include <vector>
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/message_loop.h"
#include "chrome/browser/automation/ui_controls_internal.h"
#include "content/browser/browser_thread.h"
@@ -187,29 +189,22 @@ void SynthesizeKeyEventsSequence(NSWindow* window,
}
}
-// A task class to watch for the event queue. The specific task will be fired
-// when there is no more event in the queue.
-class EventQueueWatcher : public Task {
- public:
- EventQueueWatcher(Task* task) : task_(task) {}
-
- virtual ~EventQueueWatcher() {}
-
- virtual void Run() {
- NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
- untilDate:nil
- inMode:NSDefaultRunLoopMode
- dequeue:NO];
- // If there is still event in the queue, then we need to check again.
- if (event)
- MessageLoop::current()->PostTask(FROM_HERE, new EventQueueWatcher(task_));
- else
- MessageLoop::current()->PostTask(FROM_HERE, task_);
+// A helper function to watch for the event queue. The specific task will be
+// fired when there is no more event in the queue.
+void EventQueueWatcher(const base::Closure& task) {
+ NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
+ untilDate:nil
+ inMode:NSDefaultRunLoopMode
+ dequeue:NO];
+ // If there is still event in the queue, then we need to check again.
+ if (event) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&EventQueueWatcher, task));
+ } else {
+ MessageLoop::current()->PostTask(FROM_HERE, task);
}
-
- private:
- Task* task_;
-};
+}
// Stores the current mouse location on the screen. So that we can use it
// when firing keyboard and mouse click events.
@@ -217,7 +212,6 @@ NSPoint g_mouse_location = { 0, 0 };
} // anonymous namespace
-
namespace ui_controls {
bool SendKeyPress(gfx::NativeWindow window,
@@ -228,7 +222,7 @@ bool SendKeyPress(gfx::NativeWindow window,
bool command) {
return SendKeyPressNotifyWhenDone(window, key,
control, shift, alt, command,
- NULL);
+ base::Closure());
}
// Win and Linux implement a SendKeyPress() this as a
@@ -239,7 +233,7 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
bool shift,
bool alt,
bool command,
- Task* task) {
+ const base::Closure& task) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
std::vector<NSEvent*> events;
@@ -255,21 +249,23 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
iter != events.end(); ++iter)
[[NSApplication sharedApplication] sendEvent:*iter];
- if (task)
- MessageLoop::current()->PostTask(FROM_HERE, new EventQueueWatcher(task));
+ if (!task.is_null()) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&EventQueueWatcher, task));
+ }
return true;
}
bool SendMouseMove(long x, long y) {
- return SendMouseMoveNotifyWhenDone(x, y, NULL);
+ return SendMouseMoveNotifyWhenDone(x, y, base::Closure());
}
// Input position is in screen coordinates. However, NSMouseMoved
// events require them window-relative, so we adjust. We *DO* flip
// the coordinate space, so input events can be the same for all
// platforms. E.g. (0,0) is upper-left.
-bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
+bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task) {
NSWindow* window = [[NSApplication sharedApplication] keyWindow];
CGFloat screenHeight =
[[[NSScreen screens] objectAtIndex:0] frame].size.height;
@@ -291,21 +287,24 @@ bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
pressure:0.0];
[[NSApplication sharedApplication] postEvent:event atStart:NO];
- if (task)
- MessageLoop::current()->PostTask(FROM_HERE, new EventQueueWatcher(task));
+ if (!task.is_null()) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&EventQueueWatcher, task));
+ }
return true;
}
bool SendMouseEvents(MouseButton type, int state) {
- return SendMouseEventsNotifyWhenDone(type, state, NULL);
+ return SendMouseEventsNotifyWhenDone(type, state, base::Closure());
}
-bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
+bool SendMouseEventsNotifyWhenDone(MouseButton type, int state,
+ const base::Closure& task) {
// On windows it appears state can be (UP|DOWN). It is unclear if
// that'll happen here but prepare for it just in case.
if (state == (UP|DOWN)) {
- return (SendMouseEventsNotifyWhenDone(type, DOWN, NULL) &&
+ return (SendMouseEventsNotifyWhenDone(type, DOWN, base::Closure()) &&
SendMouseEventsNotifyWhenDone(type, UP, task));
}
NSEventType etype = 0;
@@ -347,21 +346,23 @@ bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
pressure:(state == DOWN ? 1.0 : 0.0 )];
[[NSApplication sharedApplication] postEvent:event atStart:NO];
- if (task)
- MessageLoop::current()->PostTask(FROM_HERE, new EventQueueWatcher(task));
+ if (!task.is_null()) {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&EventQueueWatcher, task));
+ }
return true;
}
bool SendMouseClick(MouseButton type) {
- return SendMouseEventsNotifyWhenDone(type, UP|DOWN, NULL);
+ return SendMouseEventsNotifyWhenDone(type, UP|DOWN, base::Closure());
}
void MoveMouseToCenterAndPress(
NSView* view,
MouseButton button,
int state,
- Task* task) {
+ const base::Closure& task) {
DCHECK(view);
NSWindow* window = [view window];
DCHECK(window);
@@ -376,8 +377,9 @@ void MoveMouseToCenterAndPress(
center = [window convertBaseToScreen:center];
center = NSMakePoint(center.x, [screen frame].size.height - center.y);
- SendMouseMoveNotifyWhenDone(center.x, center.y,
- new ClickTask(button, state, task));
+ SendMouseMoveNotifyWhenDone(
+ center.x, center.y,
+ base::Bind(&ui_controls::ClickTask, button, state, task));
}
} // ui_controls
diff --git a/chrome/browser/automation/ui_controls_win.cc b/chrome/browser/automation/ui_controls_win.cc
index 1cfcbaf..9385df5 100644
--- a/chrome/browser/automation/ui_controls_win.cc
+++ b/chrome/browser/automation/ui_controls_win.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/automation/ui_controls.h"
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
@@ -22,7 +24,7 @@ namespace {
// appropriate event is received the task is notified.
class InputDispatcher : public base::RefCounted<InputDispatcher> {
public:
- InputDispatcher(Task* task, WPARAM message_waiting_for);
+ InputDispatcher(const base::Closure& task, WPARAM message_waiting_for);
// Invoked from the hook. If mouse_message matches message_waiting_for_
// MatchingMessageFound is invoked.
@@ -41,7 +43,7 @@ class InputDispatcher : public base::RefCounted<InputDispatcher> {
void NotifyTask();
// The task we notify.
- scoped_ptr<Task> task_;
+ base::Closure task_;
// Message we're waiting for. Not used for keyboard events.
const WPARAM message_waiting_for_;
@@ -107,7 +109,8 @@ void UninstallHook(InputDispatcher* dispatcher) {
}
}
-InputDispatcher::InputDispatcher(Task* task, UINT message_waiting_for)
+InputDispatcher::InputDispatcher(const base::Closure& task,
+ UINT message_waiting_for)
: task_(task), message_waiting_for_(message_waiting_for) {
InstallHook(this, message_waiting_for == WM_KEYUP);
}
@@ -126,12 +129,12 @@ void InputDispatcher::MatchingMessageFound() {
UninstallHook(this);
// At the time we're invoked the event has not actually been processed.
// Use PostTask to make sure the event has been processed before notifying.
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE, NewRunnableMethod(this, &InputDispatcher::NotifyTask), 0);
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&InputDispatcher::NotifyTask, this));
}
void InputDispatcher::NotifyTask() {
- task_->Run();
+ task_.Run();
Release();
}
@@ -164,9 +167,9 @@ bool SendKeyEvent(ui::KeyboardCode key, bool up) {
bool SendKeyPressImpl(ui::KeyboardCode key,
bool control, bool shift, bool alt,
- Task* task) {
+ const base::Closure& task) {
scoped_refptr<InputDispatcher> dispatcher(
- task ? new InputDispatcher(task, WM_KEYUP) : NULL);
+ !task.is_null() ? new InputDispatcher(task, WM_KEYUP) : NULL);
// If a pop-up menu is open, it won't receive events sent using SendInput.
// Check for a pop-up menu using its window class (#32768) and if one
@@ -239,12 +242,12 @@ bool SendKeyPressImpl(ui::KeyboardCode key,
return true;
}
-bool SendMouseMoveImpl(long x, long y, Task* task) {
+bool SendMouseMoveImpl(long x, long y, const base::Closure& task) {
// First check if the mouse is already there.
POINT current_pos;
::GetCursorPos(&current_pos);
if (x == current_pos.x && y == current_pos.y) {
- if (task)
+ if (!task.is_null())
MessageLoop::current()->PostTask(FROM_HERE, task);
return true;
}
@@ -262,7 +265,7 @@ bool SendMouseMoveImpl(long x, long y, Task* task) {
input.mi.dy = pixel_y;
scoped_refptr<InputDispatcher> dispatcher(
- task ? new InputDispatcher(task, WM_MOUSEMOVE) : NULL);
+ !task.is_null() ? new InputDispatcher(task, WM_MOUSEMOVE) : NULL);
if (!::SendInput(1, &input, sizeof(INPUT)))
return false;
@@ -273,7 +276,8 @@ bool SendMouseMoveImpl(long x, long y, Task* task) {
return true;
}
-bool SendMouseEventsImpl(MouseButton type, int state, Task* task) {
+bool SendMouseEventsImpl(MouseButton type, int state,
+ const base::Closure& task) {
DWORD down_flags = MOUSEEVENTF_ABSOLUTE;
DWORD up_flags = MOUSEEVENTF_ABSOLUTE;
UINT last_event;
@@ -303,7 +307,7 @@ bool SendMouseEventsImpl(MouseButton type, int state, Task* task) {
}
scoped_refptr<InputDispatcher> dispatcher(
- task ? new InputDispatcher(task, last_event) : NULL);
+ !task.is_null() ? new InputDispatcher(task, last_event) : NULL);
INPUT input = { 0 };
input.type = INPUT_MOUSE;
@@ -332,7 +336,7 @@ bool SendKeyPress(gfx::NativeWindow window,
bool alt,
bool command) {
DCHECK(!command); // No command key on Windows
- return SendKeyPressImpl(key, control, shift, alt, NULL);
+ return SendKeyPressImpl(key, control, shift, alt, base::Closure());
}
bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
@@ -341,35 +345,36 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
bool shift,
bool alt,
bool command,
- Task* task) {
+ const base::Closure& task) {
DCHECK(!command); // No command key on Windows
return SendKeyPressImpl(key, control, shift, alt, task);
}
bool SendMouseMove(long x, long y) {
- return SendMouseMoveImpl(x, y, NULL);
+ return SendMouseMoveImpl(x, y, base::Closure());
}
-bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
+bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& task) {
return SendMouseMoveImpl(x, y, task);
}
bool SendMouseEvents(MouseButton type, int state) {
- return SendMouseEventsImpl(type, state, NULL);
+ return SendMouseEventsImpl(type, state, base::Closure());
}
-bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
+bool SendMouseEventsNotifyWhenDone(MouseButton type, int state,
+ const base::Closure& task) {
return SendMouseEventsImpl(type, state, task);
}
bool SendMouseClick(MouseButton type) {
- return SendMouseEventsImpl(type, UP | DOWN, NULL);
+ return SendMouseEventsImpl(type, UP | DOWN, base::Closure());
}
void MoveMouseToCenterAndPress(views::View* view,
MouseButton button,
int state,
- Task* task) {
+ const base::Closure& task) {
DCHECK(view);
DCHECK(view->GetWidget());
gfx::Point view_center(view->width() / 2, view->height() / 2);
diff --git a/chrome/browser/automation/url_request_automation_job.cc b/chrome/browser/automation/url_request_automation_job.cc
index 231b259..16dca92 100644
--- a/chrome/browser/automation/url_request_automation_job.cc
+++ b/chrome/browser/automation/url_request_automation_job.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/automation/url_request_automation_job.h"
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/time.h"
@@ -61,7 +62,7 @@ URLRequestAutomationJob::URLRequestAutomationJob(
redirect_status_(0),
request_id_(request_id),
is_pending_(is_pending),
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_;
DCHECK(message_filter_ != NULL);
@@ -76,7 +77,7 @@ URLRequestAutomationJob::~URLRequestAutomationJob() {
Cleanup();
}
-bool URLRequestAutomationJob::EnsureProtocolFactoryRegistered() {
+void URLRequestAutomationJob::EnsureProtocolFactoryRegistered() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!is_protocol_factory_registered_) {
@@ -88,8 +89,6 @@ bool URLRequestAutomationJob::EnsureProtocolFactoryRegistered() {
"https", &URLRequestAutomationJob::Factory);
is_protocol_factory_registered_ = true;
}
-
- return true;
}
net::URLRequestJob* URLRequestAutomationJob::Factory(
@@ -130,8 +129,8 @@ void URLRequestAutomationJob::Start() {
// callbacks happen as they would for network requests.
MessageLoop::current()->PostTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &URLRequestAutomationJob::StartAsync));
+ base::Bind(&URLRequestAutomationJob::StartAsync,
+ weak_factory_.GetWeakPtr()));
} else {
// If this is a pending job, then register it immediately with the message
// filter so it can be serviced later when we receive a request from the
@@ -169,8 +168,8 @@ bool URLRequestAutomationJob::ReadRawData(
} else {
MessageLoop::current()->PostTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &URLRequestAutomationJob::NotifyJobCompletionTask));
+ base::Bind(&URLRequestAutomationJob::NotifyJobCompletionTask,
+ weak_factory_.GetWeakPtr()));
}
return false;
}
diff --git a/chrome/browser/automation/url_request_automation_job.h b/chrome/browser/automation/url_request_automation_job.h
index e9dd127..096ce06 100644
--- a/chrome/browser/automation/url_request_automation_job.h
+++ b/chrome/browser/automation/url_request_automation_job.h
@@ -7,6 +7,7 @@
#define CHROME_BROWSER_AUTOMATION_URL_REQUEST_AUTOMATION_JOB_H_
#pragma once
+#include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "chrome/common/ref_counted_util.h"
#include "net/url_request/url_request.h"
@@ -34,7 +35,7 @@ class URLRequestAutomationJob : public net::URLRequestJob {
bool is_pending);
// Register our factory for HTTP/HTTPs requests.
- static bool EnsureProtocolFactoryRegistered();
+ static void EnsureProtocolFactoryRegistered();
static net::URLRequest::ProtocolFactory Factory;
@@ -128,7 +129,7 @@ class URLRequestAutomationJob : public net::URLRequestJob {
// Contains the ip address and port of the destination host.
net::HostPortPair socket_address_;
- ScopedRunnableMethodFactory<URLRequestAutomationJob> method_factory_;
+ base::WeakPtrFactory<URLRequestAutomationJob> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(URLRequestAutomationJob);
};
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc
index 02f5af4..917eaa2 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.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/compiler_specific.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
@@ -473,7 +475,8 @@ VIEW_TEST(BookmarkBarViewTest3, Submenus)
// the clipboard, which invokes the event loop.
class ContextMenuNotificationObserver : public NotificationObserver {
public:
- explicit ContextMenuNotificationObserver(Task* task) : task_(task) {
+ explicit ContextMenuNotificationObserver(const base::Closure& task)
+ : task_(task) {
registrar_.Add(this,
chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN,
NotificationService::AllSources());
@@ -486,11 +489,11 @@ class ContextMenuNotificationObserver : public NotificationObserver {
}
// Sets the task that is posted when the context menu is shown.
- void set_task(Task* task) { task_ = task; }
+ void set_task(const base::Closure& task) { task_ = task; }
private:
NotificationRegistrar registrar_;
- Task* task_;
+ base::Closure task_;
DISALLOW_COPY_AND_ASSIGN(ContextMenuNotificationObserver);
};
@@ -528,7 +531,7 @@ class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase {
// Right click on the first child to get its context menu.
ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
- ui_controls::DOWN | ui_controls::UP, NULL);
+ ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by ContextMenuNotificationObserver.
}
@@ -704,7 +707,7 @@ class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase {
// Start a drag.
ui_controls::SendMouseMoveNotifyWhenDone(loc.x() + 10, loc.y(),
- NewRunnableMethod(this, &BookmarkBarViewTest7::Step4));
+ base::Bind(&BookmarkBarViewTest7::Step4, this));
// See comment above this method as to why we do this.
ScheduleMouseMoveInBackground(loc.x(), loc.y());
@@ -777,7 +780,7 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
// Start a drag.
ui_controls::SendMouseMoveNotifyWhenDone(loc.x() + 10, loc.y(),
- NewRunnableMethod(this, &BookmarkBarViewTest8::Step4));
+ base::Bind(&BookmarkBarViewTest8::Step4, this));
// See comment above this method as to why we do this.
ScheduleMouseMoveInBackground(loc.x(), loc.y());
@@ -793,7 +796,7 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
gfx::Point loc(button->width() / 2, button->height() / 2);
views::View::ConvertPointToScreen(button, &loc);
ui_controls::SendMouseMoveNotifyWhenDone(loc.x(), loc.y(),
- NewRunnableMethod(this, &BookmarkBarViewTest8::Step5));
+ base::Bind(&BookmarkBarViewTest8::Step5, this));
}
void Step5() {
@@ -867,7 +870,7 @@ class BookmarkBarViewTest9 : public BookmarkBarViewEventTestBase {
void Step3() {
MessageLoop::current()->PostDelayedTask(FROM_HERE,
- NewRunnableMethod(this, &BookmarkBarViewTest9::Step4), 200);
+ base::Bind(&BookmarkBarViewTest9::Step4, this), 200);
}
void Step4() {
@@ -883,7 +886,7 @@ class BookmarkBarViewTest9 : public BookmarkBarViewEventTestBase {
// next execution loop.
MessageLoop::current()->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &ViewEventTestBase::Done));
+ base::Bind(&ViewEventTestBase::Done, this));
}
int start_y_;
@@ -1032,7 +1035,7 @@ class BookmarkBarViewTest11 : public BookmarkBarViewEventTestBase {
// Right click on the first child to get its context menu.
ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
- ui_controls::DOWN | ui_controls::UP, NULL);
+ ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by ContextMenuNotificationObserver.
}
@@ -1118,7 +1121,7 @@ class BookmarkBarViewTest12 : public BookmarkBarViewEventTestBase {
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
- ui_controls::DOWN | ui_controls::UP, NULL);
+ ui_controls::DOWN | ui_controls::UP, base::Closure());
// Delay until we send tab, otherwise the message box doesn't appear
// correctly.
@@ -1187,7 +1190,7 @@ class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase {
// Right click on the first child to get its context menu.
ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
- ui_controls::DOWN | ui_controls::UP, NULL);
+ ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by ContextMenuNotificationObserver.
}
@@ -1253,7 +1256,7 @@ class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase {
// right mouse button.
views::TextButton* button = GetBookmarkButton(0);
ui_controls::MoveMouseToCenterAndPress(button, ui_controls::RIGHT,
- ui_controls::DOWN | ui_controls::UP, NULL);
+ ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step2 will be invoked by ContextMenuNotificationObserver.
}
@@ -1312,7 +1315,7 @@ class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase {
// Right click on the second child to get its context menu.
ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
- ui_controls::DOWN | ui_controls::UP, NULL);
+ ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by ContextMenuNotificationObserver.
}
@@ -1421,7 +1424,7 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(2);
ASSERT_TRUE(child_menu != NULL);
ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
- ui_controls::DOWN | ui_controls::UP, NULL);
+ ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step3 will be invoked by ContextMenuNotificationObserver.
}
@@ -1441,7 +1444,7 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
observer_.set_task(CreateEventTask(this, &BookmarkBarViewTest17::Step4));
ui_controls::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
- ui_controls::DOWN | ui_controls::UP, NULL);
+ ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step4 will be invoked by ContextMenuNotificationObserver.
}
diff --git a/chrome/browser/ui/views/menu_item_view_test.cc b/chrome/browser/ui/views/menu_item_view_test.cc
index 1bba805..32df7a6 100644
--- a/chrome/browser/ui/views/menu_item_view_test.cc
+++ b/chrome/browser/ui/views/menu_item_view_test.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/callback.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/automation/ui_controls.h"
#include "chrome/test/base/view_event_test_base.h"
@@ -82,7 +83,7 @@ class MenuItemViewTestBase : public ViewEventTestBase,
protected:
// Generate a mouse click on the specified view and post a new task.
- virtual void Click(views::View* view, Task* next) {
+ virtual void Click(views::View* view, const base::Closure& next) {
ui_controls::MoveMouseToCenterAndPress(
view,
ui_controls::LEFT,
diff --git a/chrome/browser/ui/views/menu_model_adapter_test.cc b/chrome/browser/ui/views/menu_model_adapter_test.cc
index 112d42a..2a2f3fa 100644
--- a/chrome/browser/ui/views/menu_model_adapter_test.cc
+++ b/chrome/browser/ui/views/menu_model_adapter_test.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/callback.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/automation/ui_controls.h"
#include "chrome/test/base/view_event_test_base.h"
@@ -86,7 +87,7 @@ class TestViewsDelegate : public views::ViewsDelegate {
DISALLOW_COPY_AND_ASSIGN(TestViewsDelegate);
};
-// Implement most of the ui::MenuModel pure virtuals for subclasses
+// Implement most of the ui::MenuModel pure virtual methods for subclasses
//
// Exceptions:
// virtual int GetItemCount() const = 0;
@@ -351,7 +352,7 @@ class MenuModelAdapterTest : public ViewEventTestBase,
private:
// Generate a mouse click on the specified view and post a new task.
- virtual void Click(views::View* view, Task* next) {
+ virtual void Click(views::View* view, const base::Closure& next) {
ui_controls::MoveMouseToCenterAndPress(
view,
ui_controls::LEFT,
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
index d86fb62..d4dd7df 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -604,7 +604,7 @@ bool SendKeyPressSync(const Browser* browser,
if (!ui_controls::SendKeyPressNotifyWhenDone(
window, key, control, shift, alt, command,
- new MessageLoop::QuitTask())) {
+ MessageLoop::QuitClosure())) {
LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed";
return false;
}
diff --git a/chrome/test/base/ui_test_utils_gtk.cc b/chrome/test/base/ui_test_utils_gtk.cc
index f890d7d..91b2bd0 100644
--- a/chrome/test/base/ui_test_utils_gtk.cc
+++ b/chrome/test/base/ui_test_utils_gtk.cc
@@ -79,7 +79,7 @@ void ClickOnView(const Browser* browser, ViewID vid) {
view,
ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
+ MessageLoop::QuitClosure());
RunMessageLoop();
}
diff --git a/chrome/test/base/ui_test_utils_mac.mm b/chrome/test/base/ui_test_utils_mac.mm
index 48275dd..92beef1 100644
--- a/chrome/test/base/ui_test_utils_mac.mm
+++ b/chrome/test/base/ui_test_utils_mac.mm
@@ -47,7 +47,7 @@ void ClickOnView(const Browser* browser, ViewID vid) {
view,
ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
+ MessageLoop::QuitClosure());
RunMessageLoop();
}
diff --git a/chrome/test/base/ui_test_utils_win.cc b/chrome/test/base/ui_test_utils_win.cc
index e7abb26..c3c9fb1 100644
--- a/chrome/test/base/ui_test_utils_win.cc
+++ b/chrome/test/base/ui_test_utils_win.cc
@@ -36,7 +36,7 @@ void ClickOnView(const Browser* browser, ViewID vid) {
view,
ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
+ MessageLoop::QuitClosure());
RunMessageLoop();
}
diff --git a/chrome/test/base/view_event_test_base.cc b/chrome/test/base/view_event_test_base.cc
index f1d3abd..af68770 100644
--- a/chrome/test/base/view_event_test_base.cc
+++ b/chrome/test/base/view_event_test_base.cc
@@ -8,6 +8,8 @@
#include <ole2.h>
#endif
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
@@ -70,7 +72,7 @@ void ViewEventTestBase::Done() {
// If we're in a nested message loop, as is the case with menus, we need
// to quit twice. The second quit does that for us.
- MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
void ViewEventTestBase::SetUp() {
@@ -86,7 +88,7 @@ void ViewEventTestBase::TearDown() {
DestroyWindow(window_->GetNativeWindow());
#else
window_->Close();
- MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
+ MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
ui_test_utils::RunMessageLoop();
#endif
window_ = NULL;
@@ -138,7 +140,7 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() {
// run the message loop.
MessageLoop::current()->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &ViewEventTestBase::DoTestOnMessageLoop));
+ base::Bind(&ViewEventTestBase::DoTestOnMessageLoop, this));
MessageLoop::current()->Run();
}
@@ -153,7 +155,8 @@ void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) {
dnd_thread_->Start();
}
dnd_thread_->message_loop()->PostDelayedTask(
- FROM_HERE, NewRunnableFunction(&ui_controls::SendMouseMove, x, y),
+ FROM_HERE,
+ base::IgnoreReturn<bool>(base::Bind(&ui_controls::SendMouseMove, x, y)),
kMouseMoveDelayMS);
}
@@ -161,11 +164,10 @@ void ViewEventTestBase::StopBackgroundThread() {
dnd_thread_.reset(NULL);
}
-void ViewEventTestBase::RunTestMethod(Task* task) {
+void ViewEventTestBase::RunTestMethod(const base::Closure& task) {
StopBackgroundThread();
- scoped_ptr<Task> task_deleter(task);
- task->Run();
+ task.Run();
if (HasFatalFailure())
Done();
}
diff --git a/chrome/test/base/view_event_test_base.h b/chrome/test/base/view_event_test_base.h
index 86610ad..b4b0027 100644
--- a/chrome/test/base/view_event_test_base.h
+++ b/chrome/test/base/view_event_test_base.h
@@ -11,14 +11,13 @@
// This way if a test hangs the test launcher can reliably terminate it.
#if defined(HAS_OUT_OF_PROC_TEST_RUNNER)
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/message_loop.h"
-#include "base/task.h"
#include "base/threading/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "views/widget/widget_delegate.h"
-class Task;
-
namespace gfx {
class Size;
}
@@ -81,7 +80,7 @@ class ViewEventTestBase : public views::WidgetDelegate,
virtual const views::Widget* GetWidget() const OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
- // Overriden to do nothing so that this class can be used in runnable tasks.
+ // Overridden to do nothing so that this class can be used in runnable tasks.
void AddRef() {}
void Release() {}
static bool ImplementsThreadSafeReferenceCounting() { return false; }
@@ -108,9 +107,9 @@ class ViewEventTestBase : public views::WidgetDelegate,
// method is called in such a way that if there are any test failures
// Done is invoked.
template <class T, class Method>
- Task* CreateEventTask(T* target, Method method) {
- return NewRunnableMethod(this, &ViewEventTestBase::RunTestMethod,
- NewRunnableMethod(target, method));
+ base::Closure CreateEventTask(T* target, Method method) {
+ return base::Bind(&ViewEventTestBase::RunTestMethod, this,
+ base::Bind(method, target));
}
// Spawns a new thread posts a MouseMove in the background.
@@ -124,7 +123,7 @@ class ViewEventTestBase : public views::WidgetDelegate,
// Callback from CreateEventTask. Stops the background thread, runs the
// supplied task and if there are failures invokes Done.
- void RunTestMethod(Task* task);
+ void RunTestMethod(const base::Closure& task);
// The content of the Window.
views::View* content_view_;