Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4210)

Unified Diff: chrome/browser/automation/ui_controls_mac.mm

Issue 8212006: base::Bind: Cleanup in automation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/automation/ui_controls_mac.mm
diff --git a/chrome/browser/automation/ui_controls_mac.mm b/chrome/browser/automation/ui_controls_mac.mm
index 6e38ef7ac8d081a870e08e62b9c36d32c931471a..a0268c3e91d5c3faf0527b79c2f43e6c239b1165 100644
--- a/chrome/browser/automation/ui_controls_mac.mm
+++ b/chrome/browser/automation/ui_controls_mac.mm
@@ -8,6 +8,7 @@
#include <mach/mach_time.h>
#include <vector>
+#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 +188,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 +211,6 @@ NSPoint g_mouse_location = { 0, 0 };
} // anonymous namespace
-
namespace ui_controls {
bool SendKeyPress(gfx::NativeWindow window,
@@ -228,7 +221,7 @@ bool SendKeyPress(gfx::NativeWindow window,
bool command) {
return SendKeyPressNotifyWhenDone(window, key,
control, shift, alt, command,
- NULL);
+ MessageLoop::QuitClosure());
}
// Win and Linux implement a SendKeyPress() this as a
@@ -239,7 +232,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,8 +248,10 @@ 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;
}
@@ -291,8 +286,10 @@ 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;
}
@@ -347,8 +344,10 @@ 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;
}
@@ -361,7 +360,7 @@ void MoveMouseToCenterAndPress(
NSView* view,
MouseButton button,
int state,
- Task* task) {
+ const base::Closure& task) {
DCHECK(view);
NSWindow* window = [view window];
DCHECK(window);
@@ -377,7 +376,7 @@ void MoveMouseToCenterAndPress(
center = NSMakePoint(center.x, [screen frame].size.height - center.y);
SendMouseMoveNotifyWhenDone(center.x, center.y,
- new ClickTask(button, state, task));
+ ClickTask(button, state, task));
csilv 2011/10/11 21:48:00 ClickTask(button, state, task) ->base::Bind(&ui_co
James Hawkins 2011/10/11 21:54:20 Done.
}
} // ui_controls

Powered by Google App Engine
This is Rietveld 408576698