summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-03 18:18:14 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-03 18:18:14 +0000
commit2d31666a58e746b7a1d415c99e5f68ad9256d236 (patch)
tree144c99d4b80df0f0f9a3ded83f9d21a8b36f17cc /chrome/browser/printing
parent90d6958fe2374a00d3c8583cf4d3b8a509ae8e90 (diff)
downloadchromium_src-2d31666a58e746b7a1d415c99e5f68ad9256d236.zip
chromium_src-2d31666a58e746b7a1d415c99e5f68ad9256d236.tar.gz
chromium_src-2d31666a58e746b7a1d415c99e5f68ad9256d236.tar.bz2
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
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r--chrome/browser/printing/print_job.cc17
-rw-r--r--chrome/browser/printing/print_view_manager.cc15
-rw-r--r--chrome/browser/printing/printing_layout_uitest.cc46
3 files changed, 33 insertions, 45 deletions
diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc
index decd853..b1e2bdc 100644
--- a/chrome/browser/printing/print_job.cc
+++ b/chrome/browser/printing/print_job.cc
@@ -267,18 +267,14 @@ bool PrintJob::FlushJob(int timeout_ms) {
// Make sure the object outlive this message loop.
scoped_refptr<PrintJob> handle(this);
- MessageLoop::QuitTask timeout_task;
- scoped_ptr<Timer> timeout;
- if (timeout_ms) {
- timeout.reset(MessageLoop::current()->timer_manager()->StartTimer(
- timeout_ms,
- &timeout_task,
- false));
- }
-
// Stop() will eventually be called, which will get out of the inner message
// loop. But, don't take it for granted and set a timer in case something goes
// wrong.
+ base::OneShotTimer<MessageLoop> quit_task;
+ if (timeout_ms) {
+ quit_task.Start(TimeDelta::FromMilliseconds(timeout_ms),
+ MessageLoop::current(), &MessageLoop::Quit);
+ }
bool old_state = MessageLoop::current()->NestableTasksAllowed();
MessageLoop::current()->SetNestableTasksAllowed(true);
@@ -286,9 +282,6 @@ bool PrintJob::FlushJob(int timeout_ms) {
// Restore task state.
MessageLoop::current()->SetNestableTasksAllowed(old_state);
- if (timeout.get()) {
- MessageLoop::current()->timer_manager()->StopTimer(timeout.get());
- }
return true;
}
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index 39e3bda..1157d64 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -492,12 +492,12 @@ bool PrintViewManager::RunInnerMessageLoop() {
// be cpu bound, the page overly complex/large or the system just
// memory-bound.
static const int kPrinterSettingsTimeout = 60000;
- MessageLoop::QuitTask timeout_task;
- Timer* timeout = MessageLoop::current()->timer_manager()->StartTimer(
- kPrinterSettingsTimeout,
- &timeout_task,
- false);
+ base::OneShotTimer<MessageLoop> quit_timer;
+ quit_timer.Start(TimeDelta::FromMilliseconds(kPrinterSettingsTimeout),
+ MessageLoop::current(), &MessageLoop::Quit);
+
inside_inner_message_loop_ = true;
+
// Need to enable recursive task.
bool old_state = MessageLoop::current()->NestableTasksAllowed();
MessageLoop::current()->SetNestableTasksAllowed(true);
@@ -512,11 +512,6 @@ bool PrintViewManager::RunInnerMessageLoop() {
success = false;
}
- if (timeout) {
- MessageLoop::current()->timer_manager()->StopTimer(timeout);
- delete timeout;
- timeout = NULL;
- }
return success;
}
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<DismissTheWindow> {
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<DismissTheWindow> timer_;
Time start_time_;
};
@@ -562,14 +564,13 @@ TEST_F(PrintingLayoutTest, DISABLED_Delayed) {
scoped_ptr<base::Thread> worker(
new base::Thread("PrintingLayoutTest_worker"));
- DismissTheWindow dismiss_task(process_util::GetProcId(process()));
+ scoped_refptr<DismissTheWindow> 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> 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<base::Thread> worker(
new base::Thread("PrintingLayoutTest_worker"));
- DismissTheWindow dismiss_task(process_util::GetProcId(process()));
+ scoped_refptr<DismissTheWindow> 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> 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();