summaryrefslogtreecommitdiffstats
path: root/chrome/service/cloud_print
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-19 03:25:11 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-19 03:25:11 +0000
commitbf3c4ed4e36b38aaac543f36e05db28d22fe86e3 (patch)
tree6274e88063433c0ca3040b02c74f42567d4e1491 /chrome/service/cloud_print
parentcdf56ee038ae1c7a31fa0bf4aeb7d2316d0b969c (diff)
downloadchromium_src-bf3c4ed4e36b38aaac543f36e05db28d22fe86e3.zip
chromium_src-bf3c4ed4e36b38aaac543f36e05db28d22fe86e3.tar.gz
chromium_src-bf3c4ed4e36b38aaac543f36e05db28d22fe86e3.tar.bz2
base::Bind: Convert chrome/service/cloud_print.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8600007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110827 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service/cloud_print')
-rw-r--r--chrome/service/cloud_print/cloud_print_auth.cc4
-rw-r--r--chrome/service/cloud_print/cloud_print_connector.cc20
-rw-r--r--chrome/service/cloud_print/print_system.h13
-rw-r--r--chrome/service/cloud_print/print_system_cups.cc63
-rw-r--r--chrome/service/cloud_print/print_system_win.cc131
-rw-r--r--chrome/service/cloud_print/printer_job_handler.cc12
6 files changed, 129 insertions, 114 deletions
diff --git a/chrome/service/cloud_print/cloud_print_auth.cc b/chrome/service/cloud_print/cloud_print_auth.cc
index 4e7b056..ec8d772 100644
--- a/chrome/service/cloud_print/cloud_print_auth.cc
+++ b/chrome/service/cloud_print/cloud_print_auth.cc
@@ -4,6 +4,7 @@
#include "chrome/service/cloud_print/cloud_print_auth.h"
+#include "base/bind.h"
#include "base/string_util.h"
#include "chrome/common/net/gaia/gaia_urls.h"
#include "chrome/service/cloud_print/cloud_print_consts.h"
@@ -139,8 +140,7 @@ void CloudPrintAuth::OnRefreshTokenResponse(const std::string& access_token,
int64 refresh_delay =
(expires_in_seconds - kTokenRefreshGracePeriodSecs)*1000;
MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- NewRunnableMethod(this, &CloudPrintAuth::RefreshAccessToken),
+ FROM_HERE, base::Bind(&CloudPrintAuth::RefreshAccessToken, this),
refresh_delay);
}
diff --git a/chrome/service/cloud_print/cloud_print_connector.cc b/chrome/service/cloud_print/cloud_print_connector.cc
index a167579..a2b5f81 100644
--- a/chrome/service/cloud_print/cloud_print_connector.cc
+++ b/chrome/service/cloud_print/cloud_print_connector.cc
@@ -4,6 +4,8 @@
#include "chrome/service/cloud_print/cloud_print_connector.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/md5.h"
#include "base/rand_util.h"
#include "base/string_number_conversions.h"
@@ -380,8 +382,7 @@ void CloudPrintConnector::AddPendingTask(const PendingTask& task) {
// If this is the only pending task, we need to start the process.
if (pending_tasks_.size() == 1) {
MessageLoop::current()->PostTask(
- FROM_HERE, NewRunnableMethod(
- this, &CloudPrintConnector::ProcessPendingTask));
+ FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this));
}
}
@@ -428,12 +429,12 @@ void CloudPrintConnector::OnPrinterRegister(
}
}
- cloud_print::PrintSystem::PrinterCapsAndDefaultsCallback* callback =
- NewCallback(this, &CloudPrintConnector::OnReceivePrinterCaps);
- // Asnchronously fetch the printer caps and defaults. The story will
+ // Asynchronously fetch the printer caps and defaults. The story will
// continue in OnReceivePrinterCaps.
print_system_->GetPrinterCapsAndDefaults(
- info.printer_name.c_str(), callback);
+ info.printer_name.c_str(),
+ base::Bind(&CloudPrintConnector::OnReceivePrinterCaps,
+ base::Unretained(this)));
}
void CloudPrintConnector::OnPrinterDelete(const std::string& printer_id) {
@@ -456,14 +457,13 @@ void CloudPrintConnector::OnPrinterDelete(const std::string& printer_id) {
void CloudPrintConnector::ContinuePendingTaskProcessing() {
if (pending_tasks_.size() == 0)
- return; // No peding tasks.
+ return; // No pending tasks.
- // Delete current task and repost if we have more task avaialble.
+ // Delete current task and repost if we have more task available.
pending_tasks_.pop_front();
if (pending_tasks_.size() != 0) {
MessageLoop::current()->PostTask(
- FROM_HERE, NewRunnableMethod(
- this, &CloudPrintConnector::ProcessPendingTask));
+ FROM_HERE, base::Bind(&CloudPrintConnector::ProcessPendingTask, this));
}
}
diff --git a/chrome/service/cloud_print/print_system.h b/chrome/service/cloud_print/print_system.h
index 4a343d8..f1ba324 100644
--- a/chrome/service/cloud_print/print_system.h
+++ b/chrome/service/cloud_print/print_system.h
@@ -10,7 +10,7 @@
#include <string>
#include <vector>
-#include "base/callback_old.h"
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "printing/backend/print_backend.h"
@@ -147,11 +147,10 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {
PrintSystemResult() { }
};
- typedef Callback3<
- bool,
- const std::string&,
- const printing::PrinterCapsAndDefaults&>::Type
- PrinterCapsAndDefaultsCallback;
+ typedef base::Callback<void(bool,
+ const std::string&,
+ const printing::PrinterCapsAndDefaults&)>
+ PrinterCapsAndDefaultsCallback;
virtual ~PrintSystem();
@@ -166,7 +165,7 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {
// Gets the capabilities and defaults for a specific printer asynchronously.
virtual void GetPrinterCapsAndDefaults(
const std::string& printer_name,
- PrinterCapsAndDefaultsCallback* callback) = 0;
+ const PrinterCapsAndDefaultsCallback& callback) = 0;
// Returns true if printer_name points to a valid printer.
virtual bool IsValidPrinter(const std::string& printer_name) = 0;
diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc
index 528da8a..41485d3 100644
--- a/chrome/service/cloud_print/print_system_cups.cc
+++ b/chrome/service/cloud_print/print_system_cups.cc
@@ -78,29 +78,24 @@ class PrintSystemCUPS : public PrintSystem {
explicit PrintSystemCUPS(const DictionaryValue* print_system_settings);
// PrintSystem implementation.
- virtual PrintSystemResult Init();
-
+ virtual PrintSystemResult Init() OVERRIDE;
virtual PrintSystem::PrintSystemResult EnumeratePrinters(
- printing::PrinterList* printer_list);
-
+ printing::PrinterList* printer_list) OVERRIDE;
virtual void GetPrinterCapsAndDefaults(
const std::string& printer_name,
- PrinterCapsAndDefaultsCallback* callback);
-
- virtual bool IsValidPrinter(const std::string& printer_name);
-
- virtual bool ValidatePrintTicket(const std::string& printer_name,
- const std::string& print_ticket_data);
-
+ const PrinterCapsAndDefaultsCallback& callback) OVERRIDE;
+ virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE;
+ virtual bool ValidatePrintTicket(
+ const std::string& printer_name,
+ const std::string& print_ticket_data) OVERRIDE;
virtual bool GetJobDetails(const std::string& printer_name,
PlatformJobId job_id,
- PrintJobDetails *job_details);
-
- virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher();
+ PrintJobDetails *job_details) OVERRIDE;
+ virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher() OVERRIDE;
virtual PrintSystem::PrinterWatcher* CreatePrinterWatcher(
- const std::string& printer_name);
- virtual PrintSystem::JobSpooler* CreateJobSpooler();
- virtual std::string GetSupportedMimeTypes();
+ const std::string& printer_name) OVERRIDE;
+ virtual PrintSystem::JobSpooler* CreateJobSpooler() OVERRIDE;
+ virtual std::string GetSupportedMimeTypes() OVERRIDE;
// Helper functions.
PlatformJobId SpoolPrintJob(const std::string& print_ticket,
@@ -154,7 +149,7 @@ class PrintSystemCUPS : public PrintSystem {
// Helper method to invoke a PrinterCapsAndDefaultsCallback.
static void RunCapsCallback(
- PrinterCapsAndDefaultsCallback* callback,
+ const PrinterCapsAndDefaultsCallback& callback,
bool succeeded,
const std::string& printer_name,
const printing::PrinterCapsAndDefaults& printer_info);
@@ -181,9 +176,9 @@ class PrintServerWatcherCUPS
StopWatching();
}
- // PrintSystem::PrintServerWatcher interface
+ // PrintSystem::PrintServerWatcher implementation.
virtual bool StartWatching(
- PrintSystem::PrintServerWatcher::Delegate* delegate) {
+ PrintSystem::PrintServerWatcher::Delegate* delegate) OVERRIDE {
delegate_ = delegate;
printers_hash_ = GetPrintersHash();
MessageLoop::current()->PostDelayedTask(
@@ -192,7 +187,8 @@ class PrintServerWatcherCUPS
print_system_->GetUpdateTimeoutMs());
return true;
}
- virtual bool StopWatching() {
+
+ virtual bool StopWatching() OVERRIDE {
delegate_ = NULL;
return true;
}
@@ -211,6 +207,7 @@ class PrintServerWatcherCUPS
base::Bind(&PrintServerWatcherCUPS::CheckForUpdates, this),
print_system_->GetUpdateTimeoutMs());
}
+
private:
std::string GetPrintersHash() {
printing::PrinterList printer_list;
@@ -233,6 +230,7 @@ class PrintServerWatcherCUPS
scoped_refptr<PrintSystemCUPS> print_system_;
PrintSystem::PrintServerWatcher::Delegate* delegate_;
std::string printers_hash_;
+
DISALLOW_COPY_AND_ASSIGN(PrintServerWatcherCUPS);
};
@@ -245,13 +243,14 @@ class PrinterWatcherCUPS
delegate_(NULL),
print_system_(print_system) {
}
+
~PrinterWatcherCUPS() {
StopWatching();
}
- // PrintSystem::PrinterWatcher interface
+ // PrintSystem::PrinterWatcher implementation.
virtual bool StartWatching(
- PrintSystem::PrinterWatcher::Delegate* delegate) {
+ PrintSystem::PrinterWatcher::Delegate* delegate) OVERRIDE{
if (delegate_ != NULL)
StopWatching();
delegate_ = delegate;
@@ -269,10 +268,12 @@ class PrinterWatcherCUPS
print_system_->GetUpdateTimeoutMs());
return true;
}
- virtual bool StopWatching() {
+
+ virtual bool StopWatching() OVERRIDE{
delegate_ = NULL;
return true;
}
+
bool GetCurrentPrinterInfo(printing::PrinterBasicInfo* printer_info) {
DCHECK(printer_info);
return print_system_->GetPrinterInfo(printer_name_, printer_info);
@@ -313,6 +314,7 @@ class PrinterWatcherCUPS
base::Bind(&PrinterWatcherCUPS::PrinterUpdate, this),
print_system_->GetUpdateTimeoutMs());
}
+
private:
std::string GetSettingsHash() {
printing::PrinterBasicInfo info;
@@ -343,6 +345,7 @@ class PrinterWatcherCUPS
PrintSystem::PrinterWatcher::Delegate* delegate_;
scoped_refptr<PrintSystemCUPS> print_system_;
std::string settings_hash_;
+
DISALLOW_COPY_AND_ASSIGN(PrinterWatcherCUPS);
};
@@ -352,6 +355,7 @@ class JobSpoolerCUPS : public PrintSystem::JobSpooler {
: print_system_(print_system) {
DCHECK(print_system_.get());
}
+
// PrintSystem::JobSpooler implementation.
virtual bool Spool(const std::string& print_ticket,
const FilePath& print_data_file_path,
@@ -359,7 +363,7 @@ class JobSpoolerCUPS : public PrintSystem::JobSpooler {
const std::string& printer_name,
const std::string& job_title,
const std::vector<std::string>& tags,
- JobSpooler::Delegate* delegate) {
+ JobSpooler::Delegate* delegate) OVERRIDE{
DCHECK(delegate);
bool dry_run = false;
int job_id = print_system_->SpoolPrintJob(
@@ -378,8 +382,10 @@ class JobSpoolerCUPS : public PrintSystem::JobSpooler {
else
delegate->OnJobSpoolFailed();
}
+
private:
scoped_refptr<PrintSystemCUPS> print_system_;
+
DISALLOW_COPY_AND_ASSIGN(JobSpoolerCUPS);
};
@@ -483,7 +489,7 @@ PrintSystem::PrintSystemResult PrintSystemCUPS::EnumeratePrinters(
void PrintSystemCUPS::GetPrinterCapsAndDefaults(
const std::string& printer_name,
- PrinterCapsAndDefaultsCallback* callback) {
+ const PrinterCapsAndDefaultsCallback& callback) {
printing::PrinterCapsAndDefaults printer_info;
bool succeeded = GetPrinterCapsAndDefaults(printer_name, &printer_info);
MessageLoop::current()->PostTask(
@@ -810,12 +816,11 @@ PrintServerInfoCUPS* PrintSystemCUPS::FindServerByFullName(
}
void PrintSystemCUPS::RunCapsCallback(
- PrinterCapsAndDefaultsCallback* callback,
+ const PrinterCapsAndDefaultsCallback& callback,
bool succeeded,
const std::string& printer_name,
const printing::PrinterCapsAndDefaults& printer_info) {
- callback->Run(succeeded, printer_name, printer_info);
- delete callback;
+ callback.Run(succeeded, printer_name, printer_info);
}
} // namespace cloud_print
diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc
index e61fda2..d3bfc03 100644
--- a/chrome/service/cloud_print/print_system_win.cc
+++ b/chrome/service/cloud_print/print_system_win.cc
@@ -251,23 +251,19 @@ class PrintSystemWin : public PrintSystem {
PrintSystemWin();
// PrintSystem implementation.
- virtual PrintSystemResult Init();
-
+ virtual PrintSystemResult Init() OVERRIDE;
virtual PrintSystem::PrintSystemResult EnumeratePrinters(
- printing::PrinterList* printer_list);
-
+ printing::PrinterList* printer_list) OVERRIDE;
virtual void GetPrinterCapsAndDefaults(
const std::string& printer_name,
- PrinterCapsAndDefaultsCallback* callback);
-
- virtual bool IsValidPrinter(const std::string& printer_name);
-
- virtual bool ValidatePrintTicket(const std::string& printer_name,
- const std::string& print_ticket_data);
-
+ const PrinterCapsAndDefaultsCallback& callback) OVERRIDE;
+ virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE;
+ virtual bool ValidatePrintTicket(
+ const std::string& printer_name,
+ const std::string& print_ticket_data) OVERRIDE;
virtual bool GetJobDetails(const std::string& printer_name,
PlatformJobId job_id,
- PrintJobDetails *job_details);
+ PrintJobDetails *job_details) OVERRIDE;
class PrintServerWatcherWin
: public PrintSystem::PrintServerWatcher,
@@ -275,32 +271,31 @@ class PrintSystemWin : public PrintSystem {
public:
PrintServerWatcherWin() : delegate_(NULL) {}
- // PrintSystem::PrintServerWatcher interface
+ // PrintSystem::PrintServerWatcher implementation.
virtual bool StartWatching(
- PrintSystem::PrintServerWatcher::Delegate* delegate) {
+ PrintSystem::PrintServerWatcher::Delegate* delegate) OVERRIDE{
delegate_ = delegate;
return watcher_.Start(std::string(), this);
}
- virtual bool StopWatching() {
+
+ virtual bool StopWatching() OVERRIDE{
bool ret = watcher_.Stop();
delegate_ = NULL;
return ret;
}
- // PrintSystemWatcherWin::Delegate interface
- virtual void OnPrinterAdded() {
+ // PrintSystemWatcherWin::Delegate implementation.
+ virtual void OnPrinterAdded() OVERRIDE {
delegate_->OnPrinterAdded();
}
- virtual void OnPrinterDeleted() {
- }
- virtual void OnPrinterChanged() {
- }
- virtual void OnJobChanged() {
- }
+ virtual void OnPrinterDeleted() OVERRIDE {}
+ virtual void OnPrinterChanged() OVERRIDE {}
+ virtual void OnJobChanged() OVERRIDE {}
private:
PrintSystem::PrintServerWatcher::Delegate* delegate_;
PrintSystemWatcherWin watcher_;
+
DISALLOW_COPY_AND_ASSIGN(PrintServerWatcherWin);
};
@@ -313,33 +308,35 @@ class PrintSystemWin : public PrintSystem {
delegate_(NULL) {
}
- // PrintSystem::PrinterWatcher interface
+ // PrintSystem::PrinterWatcher implementation.
virtual bool StartWatching(
- PrintSystem::PrinterWatcher::Delegate* delegate) {
+ PrintSystem::PrinterWatcher::Delegate* delegate) OVERRIDE {
delegate_ = delegate;
return watcher_.Start(printer_name_, this);
}
- virtual bool StopWatching() {
+
+ virtual bool StopWatching() OVERRIDE {
bool ret = watcher_.Stop();
delegate_ = NULL;
return ret;
}
+
virtual bool GetCurrentPrinterInfo(
- printing::PrinterBasicInfo* printer_info) {
+ printing::PrinterBasicInfo* printer_info) OVERRIDE {
return watcher_.GetCurrentPrinterInfo(printer_info);
}
- // PrintSystemWatcherWin::Delegate interface
- virtual void OnPrinterAdded() {
+ // PrintSystemWatcherWin::Delegate implementation.
+ virtual void OnPrinterAdded() OVERRIDE {
NOTREACHED();
}
- virtual void OnPrinterDeleted() {
+ virtual void OnPrinterDeleted() OVERRIDE {
delegate_->OnPrinterDeleted();
}
- virtual void OnPrinterChanged() {
+ virtual void OnPrinterChanged() OVERRIDE {
delegate_->OnPrinterChanged();
}
- virtual void OnJobChanged() {
+ virtual void OnJobChanged() OVERRIDE {
delegate_->OnJobChanged();
}
@@ -347,12 +344,14 @@ class PrintSystemWin : public PrintSystem {
std::string printer_name_;
PrintSystem::PrinterWatcher::Delegate* delegate_;
PrintSystemWatcherWin watcher_;
+
DISALLOW_COPY_AND_ASSIGN(PrinterWatcherWin);
};
class JobSpoolerWin : public PrintSystem::JobSpooler {
public:
JobSpoolerWin() : core_(new Core) {}
+
// PrintSystem::JobSpooler implementation.
virtual bool Spool(const std::string& print_ticket,
const FilePath& print_data_file_path,
@@ -360,7 +359,7 @@ class PrintSystemWin : public PrintSystem {
const std::string& printer_name,
const std::string& job_title,
const std::vector<std::string>& tags,
- JobSpooler::Delegate* delegate) {
+ JobSpooler::Delegate* delegate) OVERRIDE {
// TODO(gene): add tags handling.
return core_->Spool(print_ticket, print_data_file_path,
print_data_mime_type, printer_name, job_title,
@@ -380,8 +379,9 @@ class PrintSystemWin : public PrintSystem {
saved_dc_(0),
should_couninit_(false) {
}
- ~Core() {
- }
+
+ ~Core() {}
+
bool Spool(const std::string& print_ticket,
const FilePath& print_data_file_path,
const std::string& print_data_mime_type,
@@ -457,7 +457,7 @@ class PrintSystemWin : public PrintSystem {
// ServiceUtilityProcessHost::Client implementation.
virtual void OnRenderPDFPagesToMetafileSucceeded(
const printing::Emf& metafile,
- int highest_rendered_page_number) {
+ int highest_rendered_page_number) OVERRIDE {
metafile.SafePlayback(printer_dc_.Get());
bool done_printing = (highest_rendered_page_number !=
last_page_printed_ + kPageCountPerBatch);
@@ -468,8 +468,8 @@ class PrintSystemWin : public PrintSystem {
RenderNextPDFPages();
}
- // base::win::ObjectWatcher::Delegate inplementation.
- virtual void OnObjectSignaled(HANDLE object) {
+ // base::win::ObjectWatcher::Delegate implementation.
+ virtual void OnObjectSignaled(HANDLE object) OVERRIDE {
DCHECK(xps_print_job_);
DCHECK(object == job_progress_event_.Get());
ResetEvent(job_progress_event_.Get());
@@ -499,12 +499,14 @@ class PrintSystemWin : public PrintSystem {
}
}
- virtual void OnRenderPDFPagesToMetafileFailed() {
+ virtual void OnRenderPDFPagesToMetafileFailed() OVERRIDE {
PrintJobDone();
}
- virtual void OnChildDied() {
+
+ virtual void OnChildDied() OVERRIDE {
PrintJobDone();
}
+
private:
void PrintJobDone() {
// If there is no delegate, then there is nothing pending to process.
@@ -519,6 +521,7 @@ class PrintSystemWin : public PrintSystem {
}
delegate_ = NULL;
}
+
void RenderNextPDFPages() {
printing::PageRange range;
// Render 10 pages at a time.
@@ -537,6 +540,7 @@ class PrintSystemWin : public PrintSystem {
print_data_file_path_, render_area, printer_dpi,
page_ranges, base::MessageLoopProxy::current()));
}
+
// Called on the service process IO thread.
void RenderPDFPagesInSandbox(
const FilePath& pdf_path, const gfx::Rect& render_area,
@@ -560,6 +564,7 @@ class PrintSystemWin : public PrintSystem {
utility_host.release();
}
}
+
bool PrintXPSDocument(const std::string& printer_name,
const std::string& job_title,
const FilePath& print_data_file_path,
@@ -637,9 +642,11 @@ class PrintSystemWin : public PrintSystem {
base::win::ObjectWatcher job_progress_watcher_;
base::win::ScopedComPtr<IXpsPrintJob> xps_print_job_;
bool should_couninit_;
+
DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin::Core);
};
scoped_refptr<Core> core_;
+
DISALLOW_COPY_AND_ASSIGN(JobSpoolerWin);
};
@@ -649,35 +656,38 @@ class PrintSystemWin : public PrintSystem {
public:
PrinterCapsHandler(
const std::string& printer_name,
- PrinterCapsAndDefaultsCallback* callback)
+ const PrinterCapsAndDefaultsCallback& callback)
: printer_name_(printer_name), callback_(callback) {
}
- virtual void Start() {
- g_service_process->io_thread()->message_loop_proxy()->PostTask(
- FROM_HERE,
- base::Bind(&PrinterCapsHandler::GetPrinterCapsAndDefaultsImpl, this,
- base::MessageLoopProxy::current()));
- }
- virtual void OnChildDied() {
+ // ServiceUtilityProcessHost::Client implementation.
+ virtual void OnChildDied() OVERRIDE {
OnGetPrinterCapsAndDefaultsFailed(printer_name_);
}
+
virtual void OnGetPrinterCapsAndDefaultsSucceeded(
const std::string& printer_name,
- const printing::PrinterCapsAndDefaults& caps_and_defaults) {
- callback_->Run(true, printer_name, caps_and_defaults);
- callback_.reset();
+ const printing::PrinterCapsAndDefaults& caps_and_defaults) OVERRIDE {
+ callback_.Run(true, printer_name, caps_and_defaults);
+ callback_.Reset();
Release();
}
virtual void OnGetPrinterCapsAndDefaultsFailed(
- const std::string& printer_name) {
+ const std::string& printer_name) OVERRIDE {
printing::PrinterCapsAndDefaults caps_and_defaults;
- callback_->Run(false, printer_name, caps_and_defaults);
- callback_.reset();
+ callback_.Run(false, printer_name, caps_and_defaults);
+ callback_.Reset();
Release();
}
+ void Start() {
+ g_service_process->io_thread()->message_loop_proxy()->PostTask(
+ FROM_HERE,
+ base::Bind(&PrinterCapsHandler::GetPrinterCapsAndDefaultsImpl, this,
+ base::MessageLoopProxy::current()));
+ }
+
private:
// Called on the service process IO thread.
void GetPrinterCapsAndDefaultsImpl(
@@ -699,16 +709,15 @@ class PrintSystemWin : public PrintSystem {
}
std::string printer_name_;
- scoped_ptr<PrinterCapsAndDefaultsCallback> callback_;
+ PrinterCapsAndDefaultsCallback callback_;
};
- virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher();
+ virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher() OVERRIDE;
virtual PrintSystem::PrinterWatcher* CreatePrinterWatcher(
- const std::string& printer_name);
- virtual PrintSystem::JobSpooler* CreateJobSpooler();
- virtual std::string GetSupportedMimeTypes();
-
+ const std::string& printer_name) OVERRIDE;
+ virtual PrintSystem::JobSpooler* CreateJobSpooler() OVERRIDE;
+ virtual std::string GetSupportedMimeTypes() OVERRIDE;
private:
scoped_refptr<printing::PrintBackend> print_backend_;
@@ -735,7 +744,7 @@ PrintSystem::PrintSystemResult PrintSystemWin::EnumeratePrinters(
void PrintSystemWin::GetPrinterCapsAndDefaults(
const std::string& printer_name,
- PrinterCapsAndDefaultsCallback* callback) {
+ const PrinterCapsAndDefaultsCallback& callback) {
// Launch as child process to retrieve the capabilities and defaults because
// this involves invoking a printer driver DLL and crashes have been known to
// occur.
diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc
index 5a231c8..2c05e29 100644
--- a/chrome/service/cloud_print/printer_job_handler.cc
+++ b/chrome/service/cloud_print/printer_job_handler.cc
@@ -5,6 +5,7 @@
#include "chrome/service/cloud_print/printer_job_handler.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/file_util.h"
#include "base/json/json_reader.h"
#include "base/md5.h"
@@ -161,13 +162,14 @@ bool PrinterJobHandler::UpdatePrinterInfo() {
// First asynchronously fetch the capabilities.
printing::PrinterBasicInfo printer_info;
printer_watcher_->GetCurrentPrinterInfo(&printer_info);
- cloud_print::PrintSystem::PrinterCapsAndDefaultsCallback* callback =
- NewCallback(this,
- &PrinterJobHandler::OnReceivePrinterCaps);
- // Asnchronously fetch the printer caps and defaults. The story will
+
+ // Asynchronously fetch the printer caps and defaults. The story will
// continue in OnReceivePrinterCaps.
print_system_->GetPrinterCapsAndDefaults(
- printer_info.printer_name.c_str(), callback);
+ printer_info.printer_name.c_str(),
+ base::Bind(&PrinterJobHandler::OnReceivePrinterCaps,
+ base::Unretained(this)));
+
// While we are waiting for the data, pretend we have work to do and return
// true.
return true;