Commit a8135bc3 authored by jhawkins@chromium.org's avatar jhawkins@chromium.org

base::Bind: Convert (again) chrome/browser/printing.

BUG=none
TEST=none

R=csilv@chromium.org,thestig@chromium.org

Review URL: http://codereview.chromium.org/8662031

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111490 0039d316-1c4b-4281-b951-d872f2087c98
parent b4cad1b8
...@@ -33,36 +33,17 @@ void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner, ...@@ -33,36 +33,17 @@ void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner,
namespace printing { namespace printing {
class PrintJobWorker::NotificationTask : public Task { void NotificationCallback(PrintJobWorkerOwner* print_job,
public: JobEventDetails::Type detail_type,
NotificationTask() : print_job_(NULL), details_(NULL) {} PrintedDocument* document,
~NotificationTask() {} PrintedPage* page) {
JobEventDetails* details = new JobEventDetails(detail_type, document, page);
// Initializes the object. This object can't be initialized in the constructor content::NotificationService::current()->Notify(
// since it is not created directly. chrome::NOTIFICATION_PRINT_JOB_EVENT,
void Init(PrintJobWorkerOwner* print_job, // We know that is is a PrintJob object in this circumstance.
JobEventDetails::Type detail_type, content::Source<PrintJob>(static_cast<PrintJob*>(print_job)),
PrintedDocument* document, content::Details<JobEventDetails>(details));
PrintedPage* page) { }
DCHECK(!print_job_);
DCHECK(!details_);
print_job_ = print_job;
details_ = new JobEventDetails(detail_type, document, page);
}
virtual void Run() {
// Send the notification in the right thread.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PRINT_JOB_EVENT,
// We know that is is a PrintJob object in this circumstance.
content::Source<PrintJob>(static_cast<PrintJob*>(print_job_.get())),
content::Details<JobEventDetails>(details_));
}
// The job which originates this notification.
scoped_refptr<PrintJobWorkerOwner> print_job_;
scoped_refptr<JobEventDetails> details_;
};
PrintJobWorker::PrintJobWorker(PrintJobWorkerOwner* owner) PrintJobWorker::PrintJobWorker(PrintJobWorkerOwner* owner)
: Thread("Printing_Worker"), : Thread("Printing_Worker"),
...@@ -275,7 +256,7 @@ void PrintJobWorker::OnNewPage() { ...@@ -275,7 +256,7 @@ void PrintJobWorker::OnNewPage() {
break; break;
} }
// The page is there, print it. // The page is there, print it.
SpoolPage(*page); SpoolPage(page);
++page_number_; ++page_number_;
if (page_number_ == PageNumber::npos()) { if (page_number_ == PageNumber::npos()) {
OnDocumentDone(); OnDocumentDone();
...@@ -302,29 +283,24 @@ void PrintJobWorker::OnDocumentDone() { ...@@ -302,29 +283,24 @@ void PrintJobWorker::OnDocumentDone() {
return; return;
} }
// Tell everyone! owner_->message_loop()->PostTask(
NotificationTask* task = new NotificationTask(); FROM_HERE, base::Bind(NotificationCallback, make_scoped_refptr(owner_),
task->Init(owner_, JobEventDetails::DOC_DONE, document_,
JobEventDetails::DOC_DONE, scoped_refptr<PrintedPage>()));
document_.get(),
NULL);
owner_->message_loop()->PostTask(FROM_HERE, task);
// Makes sure the variables are reinitialized. // Makes sure the variables are reinitialized.
document_ = NULL; document_ = NULL;
} }
void PrintJobWorker::SpoolPage(PrintedPage& page) { void PrintJobWorker::SpoolPage(PrintedPage* page) {
DCHECK_EQ(message_loop(), MessageLoop::current()); DCHECK_EQ(message_loop(), MessageLoop::current());
DCHECK_NE(page_number_, PageNumber::npos()); DCHECK_NE(page_number_, PageNumber::npos());
// Signal everyone that the page is about to be printed. // Signal everyone that the page is about to be printed.
NotificationTask* task = new NotificationTask(); owner_->message_loop()->PostTask(
task->Init(owner_, FROM_HERE, base::Bind(NotificationCallback, make_scoped_refptr(owner_),
JobEventDetails::NEW_PAGE, JobEventDetails::NEW_PAGE, document_,
document_.get(), make_scoped_refptr(page)));
&page);
owner_->message_loop()->PostTask(FROM_HERE, task);
// Preprocess. // Preprocess.
if (printing_context_->NewPage() != PrintingContext::OK) { if (printing_context_->NewPage() != PrintingContext::OK) {
...@@ -334,9 +310,9 @@ void PrintJobWorker::SpoolPage(PrintedPage& page) { ...@@ -334,9 +310,9 @@ void PrintJobWorker::SpoolPage(PrintedPage& page) {
// Actual printing. // Actual printing.
#if defined(OS_WIN) || defined(OS_MACOSX) #if defined(OS_WIN) || defined(OS_MACOSX)
document_->RenderPrintedPage(page, printing_context_->context()); document_->RenderPrintedPage(*page, printing_context_->context());
#elif defined(OS_POSIX) #elif defined(OS_POSIX)
document_->RenderPrintedPage(page, printing_context_.get()); document_->RenderPrintedPage(*page, printing_context_.get());
#endif #endif
// Postprocess. // Postprocess.
...@@ -346,12 +322,11 @@ void PrintJobWorker::SpoolPage(PrintedPage& page) { ...@@ -346,12 +322,11 @@ void PrintJobWorker::SpoolPage(PrintedPage& page) {
} }
// Signal everyone that the page is printed. // Signal everyone that the page is printed.
task = new NotificationTask(); owner_->message_loop()->PostTask(
task->Init(owner_, FROM_HERE,
JobEventDetails::PAGE_DONE, base::Bind(NotificationCallback, make_scoped_refptr(owner_),
document_.get(), JobEventDetails::PAGE_DONE, document_,
&page); make_scoped_refptr(page)));
owner_->message_loop()->PostTask(FROM_HERE, task);
} }
void PrintJobWorker::OnFailure() { void PrintJobWorker::OnFailure() {
...@@ -360,12 +335,10 @@ void PrintJobWorker::OnFailure() { ...@@ -360,12 +335,10 @@ void PrintJobWorker::OnFailure() {
// We may loose our last reference by broadcasting the FAILED event. // We may loose our last reference by broadcasting the FAILED event.
scoped_refptr<PrintJobWorkerOwner> handle(owner_); scoped_refptr<PrintJobWorkerOwner> handle(owner_);
NotificationTask* task = new NotificationTask(); owner_->message_loop()->PostTask(
task->Init(owner_, FROM_HERE, base::Bind(NotificationCallback, make_scoped_refptr(owner_),
JobEventDetails::FAILED, JobEventDetails::FAILED, document_,
document_.get(), scoped_refptr<PrintedPage>()));
NULL);
owner_->message_loop()->PostTask(FROM_HERE, task);
Cancel(); Cancel();
// Makes sure the variables are reinitialized. // Makes sure the variables are reinitialized.
......
...@@ -80,7 +80,7 @@ class PrintJobWorker : public base::Thread { ...@@ -80,7 +80,7 @@ class PrintJobWorker : public base::Thread {
class NotificationTask; class NotificationTask;
// Renders a page in the printer. // Renders a page in the printer.
void SpoolPage(PrintedPage& page); void SpoolPage(PrintedPage* page);
// Closes the job since spooling is done. // Closes the job since spooling is done.
void OnDocumentDone(); void OnDocumentDone();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <windows.h> #include <windows.h>
#include <shellapi.h> #include <shellapi.h>
#include "base/bind.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
...@@ -14,30 +15,22 @@ ...@@ -14,30 +15,22 @@
namespace printing { namespace printing {
// A helper method that opens the printer management dialog. // A helper callback that opens the printer management dialog.
class OpenPrintersDialogTask : public Task { void OpenPrintersDialogCallback() {
public: FilePath sys_dir;
OpenPrintersDialogTask() {} PathService::Get(base::DIR_SYSTEM, &sys_dir);
FilePath rundll32 = sys_dir.AppendASCII("rundll32.exe");
virtual void Run() { FilePath shell32dll = sys_dir.AppendASCII("shell32.dll");
FilePath sys_dir;
PathService::Get(base::DIR_SYSTEM, &sys_dir); std::wstring args(shell32dll.value());
FilePath rundll32 = sys_dir.AppendASCII("rundll32.exe"); args.append(L",SHHelpShortcuts_RunDLL PrintersFolder");
FilePath shell32dll = sys_dir.AppendASCII("shell32.dll"); ShellExecute(NULL, L"open", rundll32.value().c_str(), args.c_str(), NULL,
SW_SHOWNORMAL);
std::wstring args(shell32dll.value()); }
args.append(L",SHHelpShortcuts_RunDLL PrintersFolder");
ShellExecute(NULL, L"open", rundll32.value().c_str(), args.c_str(), NULL,
SW_SHOWNORMAL);
}
private:
DISALLOW_COPY_AND_ASSIGN(OpenPrintersDialogTask);
};
void PrinterManagerDialog::ShowPrinterManagerDialog() { void PrinterManagerDialog::ShowPrinterManagerDialog() {
g_browser_process->file_thread()->message_loop()->PostTask( g_browser_process->file_thread()->message_loop()->PostTask(
FROM_HERE, new OpenPrintersDialogTask); FROM_HERE, base::Bind(OpenPrintersDialogCallback));
} }
} // namespace printing } // namespace printing
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment