From 2d31666a58e746b7a1d415c99e5f68ad9256d236 Mon Sep 17 00:00:00 2001 From: "darin@google.com" Date: Wed, 3 Sep 2008 18:18:14 +0000 Subject: Minor cleanup to OneShotTimer and RepeatingTimer: moves more of the member variables into the Task subclass. Also included in this change: deprecate MessageLoop::timer_manager(), and change consumers over to use OneShotTimer or RepeatingTimer. R=beng BUG=1346553 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1684 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/printing/printing_layout_uitest.cc | 46 +++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'chrome/browser/printing/printing_layout_uitest.cc') diff --git a/chrome/browser/printing/printing_layout_uitest.cc b/chrome/browser/printing/printing_layout_uitest.cc index a55e246..943aeb6 100644 --- a/chrome/browser/printing/printing_layout_uitest.cc +++ b/chrome/browser/printing/printing_layout_uitest.cc @@ -399,23 +399,29 @@ class PrintingLayoutTextTest : public PrintingLayoutTest { // Dismiss the first dialog box child of owner_window by "executing" the // default button. -class DismissTheWindow : public Task { +class DismissTheWindow : public base::RefCountedThreadSafe { public: DismissTheWindow(DWORD owner_process) : owner_process_(owner_process), dialog_was_found_(false), dialog_window_(NULL), other_thread_(MessageLoop::current()), - timer_(NULL), start_time_(Time::Now()) { } - virtual void Run() { + + void Start() { + timer_.Start(TimeDelta::FromMilliseconds(250), this, + &DismissTheWindow::DoTimeout); + } + + private: + void DoTimeout() { // A bit twisted code that runs in 2 passes or more. First it tries to find // a dialog box, if it finds it, it will execute the default action. If it // still works, it will loop again but then it will try to *not* find the // window. Once this is right, it will stop the timer and unlock the // other_thread_ message loop. - if (!timer_) + if (!timer_.IsRunning()) return; if (!dialog_window_) { @@ -464,8 +470,7 @@ class DismissTheWindow : public Task { // Now verify that it indeed closed itself. if (!IsWindow(dialog_window_)) { - MessageLoop::current()->timer_manager()->StopTimer(timer_); - timer_ = NULL; + timer_.Stop(); // Unlock the other thread. other_thread_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); } else { @@ -473,15 +478,12 @@ class DismissTheWindow : public Task { dialog_window_ = NULL; } } - void SetTimer(Timer* timer) { - timer_ = timer; - } - private: + DWORD owner_process_; bool dialog_was_found_; HWND dialog_window_; MessageLoop* other_thread_; - Timer* timer_; + base::RepeatingTimer timer_; Time start_time_; }; @@ -562,14 +564,13 @@ TEST_F(PrintingLayoutTest, DISABLED_Delayed) { scoped_ptr worker( new base::Thread("PrintingLayoutTest_worker")); - DismissTheWindow dismiss_task(process_util::GetProcId(process())); + scoped_refptr dismiss_task = + new DismissTheWindow(process_util::GetProcId(process())); // We need to start the thread to be able to set the timer. worker->Start(); - scoped_ptr timer(worker->message_loop()->timer_manager()->StartTimer( - 250, - &dismiss_task, - true)); - dismiss_task.SetTimer(timer.get()); + worker->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(dismiss_task.get(), &DismissTheWindow::Start)); + MessageLoop::current()->Run(); worker->Stop(); @@ -601,14 +602,13 @@ TEST_F(PrintingLayoutTest, DISABLED_IFrame) { scoped_ptr worker( new base::Thread("PrintingLayoutTest_worker")); - DismissTheWindow dismiss_task(process_util::GetProcId(process())); + scoped_refptr dismiss_task = + new DismissTheWindow(process_util::GetProcId(process())); // We need to start the thread to be able to set the timer. worker->Start(); - scoped_ptr timer(worker->message_loop()->timer_manager()->StartTimer( - 250, - &dismiss_task, - true)); - dismiss_task.SetTimer(timer.get()); + worker->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(dismiss_task.get(), &DismissTheWindow::Start)); + MessageLoop::current()->Run(); worker->Stop(); -- cgit v1.1