| Index: chrome/browser/printing/printer_query.cc
|
| ===================================================================
|
| --- chrome/browser/printing/printer_query.cc (revision 13415)
|
| +++ chrome/browser/printing/printer_query.cc (working copy)
|
| @@ -4,21 +4,20 @@
|
|
|
| #include "chrome/browser/printing/printer_query.h"
|
|
|
| +#include "base/compiler_specific.h"
|
| #include "base/message_loop.h"
|
| #include "chrome/browser/printing/print_job_worker.h"
|
|
|
| -#ifdef _MSC_VER
|
| -#pragma warning(disable:4355) // 'this' : used in base member initializer list
|
| -#endif
|
| -
|
| namespace printing {
|
|
|
| -PrinterQuery::PrinterQuery()
|
| - : ui_message_loop_(MessageLoop::current()),
|
| - worker_(new PrintJobWorker(this)),
|
| +PrinterQuery::PrinterQuery(MessageLoop* ui_message_loop)
|
| + : ui_message_loop_(ui_message_loop),
|
| + message_loop_(MessageLoop::current()),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(worker_(new PrintJobWorker(this))),
|
| is_print_dialog_box_shown_(false),
|
| last_status_(PrintingContext::FAILED),
|
| cookie_(PrintSettings::NewCookie()) {
|
| + DCHECK(ui_message_loop_);
|
| }
|
|
|
| PrinterQuery::~PrinterQuery() {
|
| @@ -31,7 +30,7 @@
|
| callback_->Cancel();
|
| }
|
| // It may get deleted in a different thread that the one that created it.
|
| - // That's fine so don't DCHECK_EQ(ui_message_loop_, MessageLoop::current());
|
| + // That's fine so don't DCHECK_EQ(message_loop_, MessageLoop::current());
|
| }
|
|
|
| void PrinterQuery::GetSettingsDone(const PrintSettings& new_settings,
|
| @@ -65,28 +64,41 @@
|
| HWND parent_window,
|
| int expected_page_count,
|
| CancelableTask* callback) {
|
| - DCHECK_EQ(ui_message_loop_, MessageLoop::current());
|
| + DCHECK_EQ(message_loop_, MessageLoop::current());
|
| DCHECK(!is_print_dialog_box_shown_);
|
| DCHECK(!callback_.get());
|
| DCHECK(worker_.get());
|
| if (!worker_.get())
|
| return;
|
| - // Lazy create the worker thread. There is one worker thread per print job.
|
| - if (!worker_->message_loop()) {
|
| - if (!worker_->Start()) {
|
| - if (callback) {
|
| - callback->Cancel();
|
| - delete callback;
|
| +
|
| + MessageLoop* message_loop;
|
| + if (ask_user_for_settings == DEFAULTS) {
|
| + // Lazy create the worker thread. There is one worker thread per print job.
|
| + if (!worker_->message_loop()) {
|
| + if (!worker_->Start()) {
|
| + if (callback) {
|
| + callback->Cancel();
|
| + delete callback;
|
| + }
|
| + callback_.reset(NULL);
|
| + NOTREACHED();
|
| + return;
|
| }
|
| - NOTREACHED();
|
| - return;
|
| }
|
| + message_loop = worker_->message_loop();
|
| + } else if (ask_user_for_settings == ASK_USER) {
|
| + // No need for a worker thread in that case.
|
| + message_loop = ui_message_loop_;
|
| + } else {
|
| + callback_.reset(NULL);
|
| + NOTREACHED();
|
| + return;
|
| }
|
| -
|
| + DCHECK(message_loop);
|
| + is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER;
|
| callback_.reset(callback);
|
| // Real work is done in PrintJobWorker::Init().
|
| - is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER;
|
| - worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
|
| + message_loop->PostTask(FROM_HERE, NewRunnableMethod(
|
| worker_.get(),
|
| &PrintJobWorker::GetSettings,
|
| is_print_dialog_box_shown_,
|
| @@ -113,4 +125,53 @@
|
| return worker_.get() != NULL;
|
| }
|
|
|
| +
|
| +DefaultSettingsPrinterQueryTask::DefaultSettingsPrinterQueryTask(
|
| + MessageLoop* reply_message_loop)
|
| + : reply_task_(new ReplyTask()),
|
| + reply_message_loop_(reply_message_loop) {
|
| + if (!reply_message_loop_)
|
| + reply_message_loop_ = MessageLoop::current();
|
| +}
|
| +
|
| +void DefaultSettingsPrinterQueryTask::Run() {
|
| + DCHECK(reply_task_);
|
| + // Run the lengthy operation:
|
| + reply_task_->result_.Run();
|
| +
|
| + // Post back the result.
|
| + reply_message_loop_->PostTask(FROM_HERE, reply_task_);
|
| + // |this| will be deleted upon return.
|
| +}
|
| +
|
| +void DefaultSettingsPrinterQueryTask::Cancel() {
|
| + reply_task_->Cancel();
|
| + // |this| will be deleted upon return.
|
| +}
|
| +
|
| +DefaultSettingsPrinterQueryTask::Result::Result()
|
| + : result(PrintingContext::FAILED) {
|
| +}
|
| +
|
| +void DefaultSettingsPrinterQueryTask::Result::Run() {
|
| + result = printing_context.UseDefaultSettings();
|
| +}
|
| +
|
| +DefaultSettingsPrinterQueryTask::ReplyTask::ReplyTask() {
|
| +}
|
| +
|
| +void DefaultSettingsPrinterQueryTask::ReplyTask::Run() {
|
| + DCHECK(reply_task_.get());
|
| + reply_task_->Run();
|
| + reply_task_.reset(NULL);
|
| + // |this| will be deleted upon return.
|
| +}
|
| +
|
| +void DefaultSettingsPrinterQueryTask::ReplyTask::Cancel() {
|
| + DCHECK(reply_task_.get());
|
| + reply_task_->Cancel();
|
| + reply_task_.reset(NULL);
|
| + // |this| will be deleted upon return.
|
| +}
|
| +
|
| } // namespace printing
|
|
|