summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-19 01:58:38 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-19 01:58:38 +0000
commitabe4811df1767cc8ebcbc6f819981ea5172caf7c (patch)
treeb58a4a79f842c79cb189ab009e158ed8a99950b6 /printing
parentcd8b4c7f2791bc845dfb0fb761be9306f2a0f82c (diff)
downloadchromium_src-abe4811df1767cc8ebcbc6f819981ea5172caf7c.zip
chromium_src-abe4811df1767cc8ebcbc6f819981ea5172caf7c.tar.gz
chromium_src-abe4811df1767cc8ebcbc6f819981ea5172caf7c.tar.bz2
base::Bind: Convert PrintingContext::PrintSettingsCallback.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8549031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110813 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/print_dialog_gtk_interface.h2
-rw-r--r--printing/printing_context.h6
-rw-r--r--printing/printing_context_gtk.cc2
-rw-r--r--printing/printing_context_gtk.h9
-rw-r--r--printing/printing_context_mac.h9
-rw-r--r--printing/printing_context_mac.mm13
-rw-r--r--printing/printing_context_no_system_dialog.cc4
-rw-r--r--printing/printing_context_no_system_dialog.h29
-rw-r--r--printing/printing_context_win.cc12
-rw-r--r--printing/printing_context_win.h29
-rw-r--r--printing/printing_context_win_unittest.cc11
11 files changed, 64 insertions, 62 deletions
diff --git a/printing/print_dialog_gtk_interface.h b/printing/print_dialog_gtk_interface.h
index 589ad71..b63076e 100644
--- a/printing/print_dialog_gtk_interface.h
+++ b/printing/print_dialog_gtk_interface.h
@@ -32,7 +32,7 @@ class PrintDialogGtkInterface {
// Shows the dialog and handles the response with |callback|. Only used when
// printing with the native print dialog.
virtual void ShowDialog(
- PrintingContextGtk::PrintSettingsCallback* callback) = 0;
+ const PrintingContextGtk::PrintSettingsCallback& callback) = 0;
// Prints the document named |document_name| contained in |metafile|.
// Called from the print worker thread. Once called, the
diff --git a/printing/printing_context.h b/printing/printing_context.h
index 5dbe70d..60ea0be 100644
--- a/printing/printing_context.h
+++ b/printing/printing_context.h
@@ -8,7 +8,7 @@
#include <string>
#include "base/basictypes.h"
-#include "base/callback_old.h"
+#include "base/callback.h"
#include "base/string16.h"
#include "printing/print_settings.h"
#include "ui/gfx/native_widget_types.h"
@@ -36,7 +36,7 @@ class PRINTING_EXPORT PrintingContext {
// Callback of AskUserForSettings, used to notify the PrintJobWorker when
// print settings are available.
- typedef Callback1<Result>::Type PrintSettingsCallback;
+ typedef base::Callback<void(Result)> PrintSettingsCallback;
// Asks the user what printer and format should be used to print. Updates the
// context with the select device settings. The result of the call is returned
@@ -45,7 +45,7 @@ class PRINTING_EXPORT PrintingContext {
virtual void AskUserForSettings(gfx::NativeView parent_view,
int max_pages,
bool has_selection,
- PrintSettingsCallback* callback) = 0;
+ const PrintSettingsCallback& callback) = 0;
// Selects the user's default printer and format. Updates the context with the
// default device settings.
diff --git a/printing/printing_context_gtk.cc b/printing/printing_context_gtk.cc
index 8d47e6a..fc534ea 100644
--- a/printing/printing_context_gtk.cc
+++ b/printing/printing_context_gtk.cc
@@ -59,7 +59,7 @@ void PrintingContextGtk::AskUserForSettings(
gfx::NativeView parent_view,
int max_pages,
bool has_selection,
- PrintSettingsCallback* callback) {
+ const PrintSettingsCallback& callback) {
print_dialog_->ShowDialog(callback);
}
diff --git a/printing/printing_context_gtk.h b/printing/printing_context_gtk.h
index dbb8941..8d671ae 100644
--- a/printing/printing_context_gtk.h
+++ b/printing/printing_context_gtk.h
@@ -32,10 +32,11 @@ class PRINTING_EXPORT PrintingContextGtk : public PrintingContext {
void PrintDocument(const Metafile* metafile);
// PrintingContext implementation.
- virtual void AskUserForSettings(gfx::NativeView parent_view,
- int max_pages,
- bool has_selection,
- PrintSettingsCallback* callback) OVERRIDE;
+ virtual void AskUserForSettings(
+ gfx::NativeView parent_view,
+ int max_pages,
+ bool has_selection,
+ const PrintSettingsCallback& callback) OVERRIDE;
virtual Result UseDefaultSettings() OVERRIDE;
virtual Result UpdatePrinterSettings(
const base::DictionaryValue& job_settings,
diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h
index e9cad8f..36fd6dff 100644
--- a/printing/printing_context_mac.h
+++ b/printing/printing_context_mac.h
@@ -25,10 +25,11 @@ class PRINTING_EXPORT PrintingContextMac : public PrintingContext {
virtual ~PrintingContextMac();
// PrintingContext implementation.
- virtual void AskUserForSettings(gfx::NativeView parent_view,
- int max_pages,
- bool has_selection,
- PrintSettingsCallback* callback) OVERRIDE;
+ virtual void AskUserForSettings(
+ gfx::NativeView parent_view,
+ int max_pages,
+ bool has_selection,
+ const PrintSettingsCallback& callback) OVERRIDE;
virtual Result UseDefaultSettings() OVERRIDE;
virtual Result UpdatePrinterSettings(
const base::DictionaryValue& job_settings,
diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm
index 9c56ace..36971c8 100644
--- a/printing/printing_context_mac.mm
+++ b/printing/printing_context_mac.mm
@@ -32,10 +32,11 @@ PrintingContextMac::~PrintingContextMac() {
ReleaseContext();
}
-void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view,
- int max_pages,
- bool has_selection,
- PrintSettingsCallback* callback) {
+void PrintingContextMac::AskUserForSettings(
+ gfx::NativeView parent_view,
+ int max_pages,
+ bool has_selection,
+ const PrintSettingsCallback& callback) {
// Third-party print drivers seem to be an area prone to raising exceptions.
// This will allow exceptions to be raised, but does not handle them. The
// NSPrintPanel appears to have appropriate NSException handlers.
@@ -80,9 +81,9 @@ void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view,
if (selection == NSOKButton) {
print_info_.reset([[panel printInfo] retain]);
InitPrintSettingsFromPrintInfo(GetPageRangesFromPrintInfo());
- callback->Run(OK);
+ callback.Run(OK);
} else {
- callback->Run(CANCEL);
+ callback.Run(CANCEL);
}
}
diff --git a/printing/printing_context_no_system_dialog.cc b/printing/printing_context_no_system_dialog.cc
index dac11d4..58ab76e 100644
--- a/printing/printing_context_no_system_dialog.cc
+++ b/printing/printing_context_no_system_dialog.cc
@@ -32,9 +32,9 @@ void PrintingContextNoSystemDialog::AskUserForSettings(
gfx::NativeView parent_view,
int max_pages,
bool has_selection,
- PrintSettingsCallback* callback) {
+ const PrintSettingsCallback& callback) {
// We don't want to bring up a dialog here. Ever. Just signal the callback.
- callback->Run(OK);
+ callback.Run(OK);
}
PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() {
diff --git a/printing/printing_context_no_system_dialog.h b/printing/printing_context_no_system_dialog.h
index 5200b8d..b88578b 100644
--- a/printing/printing_context_no_system_dialog.h
+++ b/printing/printing_context_no_system_dialog.h
@@ -21,22 +21,23 @@ class PRINTING_EXPORT PrintingContextNoSystemDialog : public PrintingContext {
virtual ~PrintingContextNoSystemDialog();
// PrintingContext implementation.
- virtual void AskUserForSettings(gfx::NativeView parent_view,
- int max_pages,
- bool has_selection,
- PrintSettingsCallback* callback);
- virtual Result UseDefaultSettings();
+ virtual void AskUserForSettings(
+ gfx::NativeView parent_view,
+ int max_pages,
+ bool has_selection,
+ const PrintSettingsCallback& callback) OVERRIDE;
+ virtual Result UseDefaultSettings() OVERRIDE;
virtual Result UpdatePrinterSettings(
const base::DictionaryValue& job_settings,
- const PageRanges& ranges);
- virtual Result InitWithSettings(const PrintSettings& settings);
- virtual Result NewDocument(const string16& document_name);
- virtual Result NewPage();
- virtual Result PageDone();
- virtual Result DocumentDone();
- virtual void Cancel();
- virtual void ReleaseContext();
- virtual gfx::NativeDrawingContext context() const;
+ const PageRanges& ranges) OVERRIDE;
+ virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
+ virtual Result NewDocument(const string16& document_name) OVERRIDE;
+ virtual Result NewPage() OVERRIDE;
+ virtual Result PageDone() OVERRIDE;
+ virtual Result DocumentDone() OVERRIDE;
+ virtual void Cancel() OVERRIDE;
+ virtual void ReleaseContext() OVERRIDE;
+ virtual gfx::NativeDrawingContext context() const OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(PrintingContextNoSystemDialog);
diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc
index 04b6481..46093e7 100644
--- a/printing/printing_context_win.cc
+++ b/printing/printing_context_win.cc
@@ -213,10 +213,9 @@ PrintingContextWin::~PrintingContextWin() {
ReleaseContext();
}
-void PrintingContextWin::AskUserForSettings(gfx::NativeView view,
- int max_pages,
- bool has_selection,
- PrintSettingsCallback* callback) {
+void PrintingContextWin::AskUserForSettings(
+ gfx::NativeView view, int max_pages, bool has_selection,
+ const PrintSettingsCallback& callback) {
#if !defined(USE_AURA)
DCHECK(!in_print_job_);
dialog_box_dismissed_ = false;
@@ -267,12 +266,11 @@ void PrintingContextWin::AskUserForSettings(gfx::NativeView view,
if ((*print_dialog_func_)(&dialog_options) != S_OK) {
ResetSettings();
- callback->Run(FAILED);
+ callback.Run(FAILED);
}
// TODO(maruel): Support PD_PRINTTOFILE.
- callback->Run(ParseDialogResultEx(dialog_options));
- delete callback;
+ callback.Run(ParseDialogResultEx(dialog_options));
#endif
}
diff --git a/printing/printing_context_win.h b/printing/printing_context_win.h
index feee8f6..b167a0a 100644
--- a/printing/printing_context_win.h
+++ b/printing/printing_context_win.h
@@ -23,22 +23,23 @@ class PRINTING_EXPORT PrintingContextWin : public PrintingContext {
~PrintingContextWin();
// PrintingContext implementation.
- virtual void AskUserForSettings(gfx::NativeView parent_view,
- int max_pages,
- bool has_selection,
- PrintSettingsCallback* callback);
- virtual Result UseDefaultSettings();
+ virtual void AskUserForSettings(
+ gfx::NativeView parent_view,
+ int max_pages,
+ bool has_selection,
+ const PrintSettingsCallback& callback) OVERRIDE;
+ virtual Result UseDefaultSettings() OVERRIDE;
virtual Result UpdatePrinterSettings(
const base::DictionaryValue& job_settings,
- const PageRanges& ranges);
- virtual Result InitWithSettings(const PrintSettings& settings);
- virtual Result NewDocument(const string16& document_name);
- virtual Result NewPage();
- virtual Result PageDone();
- virtual Result DocumentDone();
- virtual void Cancel();
- virtual void ReleaseContext();
- virtual gfx::NativeDrawingContext context() const;
+ const PageRanges& ranges) OVERRIDE;
+ virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
+ virtual Result NewDocument(const string16& document_name) OVERRIDE;
+ virtual Result NewPage() OVERRIDE;
+ virtual Result PageDone() OVERRIDE;
+ virtual Result DocumentDone() OVERRIDE;
+ virtual void Cancel() OVERRIDE;
+ virtual void ReleaseContext() OVERRIDE;
+ virtual gfx::NativeDrawingContext context() const OVERRIDE;
#if defined(UNIT_TEST) || defined(PRINTING_IMPLEMENTATION)
// Sets a fake PrintDlgEx function pointer in tests.
diff --git a/printing/printing_context_win_unittest.cc b/printing/printing_context_win_unittest.cc
index d811663..5917b65 100644
--- a/printing/printing_context_win_unittest.cc
+++ b/printing/printing_context_win_unittest.cc
@@ -7,6 +7,8 @@
#include <string>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/memory/scoped_ptr.h"
#include "printing/printing_test.h"
#include "printing/printing_context.h"
@@ -165,12 +167,9 @@ TEST_F(PrintingContextTest, PrintAll) {
printing::PrintingContextWin context(dummy_locale);
context.SetPrintDialog(&PrintDlgExMock);
context.AskUserForSettings(
- NULL,
- 123,
- false,
- NewCallback(static_cast<PrintingContextTest*>(this),
- &PrintingContextTest::PrintSettingsCallback));
- ASSERT_EQ(printing::PrintingContext::OK, result());
+ NULL, 123, false, base::Bind(&PrintingContextTest::PrintSettingsCallback,
+ base::Unretained(this)));
+ EXPECT_EQ(printing::PrintingContext::OK, result());
printing::PrintSettings settings = context.settings();
EXPECT_EQ(settings.ranges.size(), 0);
}