| Index: chrome/browser/printing/printer_query.h
|
| ===================================================================
|
| --- chrome/browser/printing/printer_query.h (revision 13415)
|
| +++ chrome/browser/printing/printer_query.h (working copy)
|
| @@ -6,7 +6,7 @@
|
| #define CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_
|
|
|
| #include "base/scoped_ptr.h"
|
| -#include "base/ref_counted.h"
|
| +#include "base/task.h"
|
| #include "chrome/browser/printing/print_job_worker_owner.h"
|
|
|
| class CancelableTask;
|
| @@ -20,7 +20,8 @@
|
|
|
| class PrintJobWorker;
|
|
|
| -// Query the printer for settings.
|
| +// Query the printer for settings in a worker thread for default settings and
|
| +// in |ui_message_loop| for ASK_USER request.
|
| class PrinterQuery : public base::RefCountedThreadSafe<PrinterQuery>,
|
| public PrintJobWorkerOwner {
|
| public:
|
| @@ -30,7 +31,7 @@
|
| ASK_USER,
|
| };
|
|
|
| - PrinterQuery();
|
| + PrinterQuery(MessageLoop* ui_message_loop);
|
| virtual ~PrinterQuery();
|
|
|
| // PrintJobWorkerOwner
|
| @@ -44,7 +45,7 @@
|
| PrintingContext::Result result);
|
| virtual PrintJobWorker* DetachWorker(PrintJobWorkerOwner* new_owner);
|
| virtual MessageLoop* message_loop() {
|
| - return ui_message_loop_;
|
| + return message_loop_;
|
| }
|
| virtual const PrintSettings& settings() const { return settings_; }
|
|
|
| @@ -74,9 +75,12 @@
|
| bool is_valid() const;
|
|
|
| private:
|
| + // Main UI thread for displaying the Print... Dialog.
|
| + MessageLoop* ui_message_loop_;
|
| +
|
| // Main message loop reference. Used to send notifications in the right
|
| // thread.
|
| - MessageLoop* const ui_message_loop_;
|
| + MessageLoop* const message_loop_;
|
|
|
| // All the UI is done in a worker thread because many Win32 print functions
|
| // are blocking and enters a message loop without your consent. There is one
|
| @@ -101,6 +105,64 @@
|
| DISALLOW_COPY_AND_ASSIGN(PrinterQuery);
|
| };
|
|
|
| +// A single-use printer query task for default settings. Makes it easy to defer
|
| +// the task to a worker thread (like WorkerPool) and executes the callbacks in
|
| +// the caller's thread..
|
| +// TODO(maruel): Extract common functionality in a template?
|
| +class DefaultSettingsPrinterQueryTask : public Task {
|
| + public:
|
| + // Information about the printer setting.
|
| + struct Result {
|
| + Result();
|
| +
|
| + void Run();
|
| +
|
| + PrintingContext printing_context;
|
| + PrintingContext::Result result;
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(Result);
|
| + };
|
| +
|
| + // |reply_message_loop| is optional and is equivalent to
|
| + // MessageLoop::current() if NULL.
|
| + DefaultSettingsPrinterQueryTask(MessageLoop* reply_message_loop);
|
| + virtual ~DefaultSettingsPrinterQueryTask() { }
|
| +
|
| + virtual void Run();
|
| + virtual void Cancel();
|
| +
|
| + // The reply task will be posted to reply_message_loop specified in the
|
| + // constructor. Takes ownership.
|
| + // TODO(maruel): We could get away by using UnboundMethod<> instead.
|
| + void set_reply_task(CancelableTask* reply_task) {
|
| + reply_task_->reply_task_.reset(reply_task);
|
| + }
|
| + // Retrieves the results. Mainly useful while creating the NewRunnableMethod()
|
| + // to specify to set_reply_task().
|
| + Result* result() { return &reply_task_->result_; }
|
| +
|
| + private:
|
| + class ReplyTask : public CancelableTask {
|
| + public:
|
| + ReplyTask();
|
| + virtual ~ReplyTask() { }
|
| +
|
| + virtual void Run();
|
| + virtual void Cancel();
|
| +
|
| + scoped_ptr<CancelableTask> reply_task_;
|
| + Result result_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ReplyTask);
|
| + };
|
| +
|
| + ReplyTask* reply_task_;
|
| + MessageLoop* reply_message_loop_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DefaultSettingsPrinterQueryTask);
|
| +};
|
| +
|
| } // namespace printing
|
|
|
| #endif // CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_
|
|
|