summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorfinnur <finnur@chromium.org>2014-08-25 03:08:15 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-25 10:09:09 +0000
commitc921afdcc249a89bd9e8cc1cc898e4c320cc5d03 (patch)
treed3a070f77fb354815c81dcd1d993783d298deab0 /printing
parentbb1bd87a4fad403340fe8e3168552a933954a535 (diff)
downloadchromium_src-c921afdcc249a89bd9e8cc1cc898e4c320cc5d03.zip
chromium_src-c921afdcc249a89bd9e8cc1cc898e4c320cc5d03.tar.gz
chromium_src-c921afdcc249a89bd9e8cc1cc898e4c320cc5d03.tar.bz2
Revert of Added PrintingContext::Delegate to get parent view handle and application locale. (patchset #13 of https://codereview.chromium.org/478183005/)
Reason for revert: PrintJobTest.SimplePrint leaking on Linux ASAN bots since this was checked in: http://build.chromium.org/p/chromium.memory/builders/Linux%20ASan%20LSan%20Tests%20%282%29?numbuilds=100 This CL looks like the likeliest culprit. Original issue's description: > Added PrintingContext::Delegate to get parent view handle and application locale. > > BUG=374321 > > Committed: https://chromium.googlesource.com/chromium/src/+/ee8f4e4029c09ba77e7dbb8fddd85186642b3de8 TBR=noamsml@chromium.org,inferno@chromium.org,yzshen@chromium.org,thestig@chromium.org,jschuh@chromium.org,vitalybuka@chromium.org NOTREECHECKS=true NOTRY=true BUG=374321 Review URL: https://codereview.chromium.org/504763002 Cr-Commit-Position: refs/heads/master@{#291654}
Diffstat (limited to 'printing')
-rw-r--r--printing/emf_win_unittest.cc12
-rw-r--r--printing/printing_context.cc9
-rw-r--r--printing/printing_context.h29
-rw-r--r--printing/printing_context_android.cc12
-rw-r--r--printing/printing_context_android.h3
-rw-r--r--printing/printing_context_linux.cc13
-rw-r--r--printing/printing_context_linux.h3
-rw-r--r--printing/printing_context_mac.h3
-rw-r--r--printing/printing_context_mac.mm10
-rw-r--r--printing/printing_context_no_system_dialog.cc14
-rw-r--r--printing/printing_context_no_system_dialog.h3
-rw-r--r--printing/printing_context_win.cc14
-rw-r--r--printing/printing_context_win.h5
-rw-r--r--printing/printing_context_win_unittest.cc19
14 files changed, 65 insertions, 84 deletions
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc
index ec65c28..8a5daaf 100644
--- a/printing/emf_win_unittest.cc
+++ b/printing/emf_win_unittest.cc
@@ -22,13 +22,11 @@
#include "ui/gfx/point.h"
#include "ui/gfx/size.h"
-namespace printing {
-
namespace {
// This test is automatically disabled if no printer named "UnitTest Printer" is
// available.
-class EmfPrintingTest : public testing::Test, public PrintingContext::Delegate {
+class EmfPrintingTest : public testing::Test {
public:
typedef testing::Test Parent;
static bool IsTestCaseDisabled() {
@@ -39,16 +37,14 @@ class EmfPrintingTest : public testing::Test, public PrintingContext::Delegate {
DeleteDC(hdc);
return false;
}
-
- // PrintingContext::Delegate methods.
- virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; }
- virtual std::string GetAppLocale() OVERRIDE { return std::string(); }
};
const uint32 EMF_HEADER_SIZE = 128;
} // namespace
+namespace printing {
+
TEST(EmfTest, DC) {
// Simplest use case.
uint32 size;
@@ -87,7 +83,7 @@ TEST_F(EmfPrintingTest, Enumerate) {
settings.set_device_name(L"UnitTest Printer");
// Initialize it.
- scoped_ptr<PrintingContext> context(PrintingContext::Create(this));
+ scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string()));
EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK);
base::FilePath emf_file;
diff --git a/printing/printing_context.cc b/printing/printing_context.cc
index d2b1e68..c7f22a5 100644
--- a/printing/printing_context.cc
+++ b/printing/printing_context.cc
@@ -18,12 +18,11 @@ namespace {
const float kCloudPrintMarginInch = 0.25;
}
-PrintingContext::PrintingContext(Delegate* delegate)
- : delegate_(delegate),
- dialog_box_dismissed_(false),
+PrintingContext::PrintingContext(const std::string& app_locale)
+ : dialog_box_dismissed_(false),
in_print_job_(false),
- abort_printing_(false) {
- CHECK(delegate_);
+ abort_printing_(false),
+ app_locale_(app_locale) {
}
PrintingContext::~PrintingContext() {
diff --git a/printing/printing_context.h b/printing/printing_context.h
index 875c070..823a5af 100644
--- a/printing/printing_context.h
+++ b/printing/printing_context.h
@@ -25,19 +25,6 @@ namespace printing {
// printer and manage the document and page breaks.
class PRINTING_EXPORT PrintingContext {
public:
- // Printing context delegate.
- class Delegate {
- public:
- Delegate() {};
- virtual ~Delegate() {};
-
- // Returns parent view to use for modal dialogs.
- virtual gfx::NativeView GetParentView() = 0;
-
- // Returns application locale.
- virtual std::string GetAppLocale() = 0;
- };
-
// Tri-state result for user behavior-dependent functions.
enum Result {
OK,
@@ -55,7 +42,8 @@ class PRINTING_EXPORT PrintingContext {
// context with the select device settings. The result of the call is returned
// in the callback. This is necessary for Linux, which only has an
// asynchronous printing API.
- virtual void AskUserForSettings(int max_pages,
+ virtual void AskUserForSettings(gfx::NativeView parent_view,
+ int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) = 0;
@@ -110,8 +98,9 @@ class PRINTING_EXPORT PrintingContext {
virtual gfx::NativeDrawingContext context() const = 0;
// Creates an instance of this object. Implementers of this interface should
- // implement this method to create an object of their implementation.
- static scoped_ptr<PrintingContext> Create(Delegate* delegate);
+ // implement this method to create an object of their implementation. The
+ // caller owns the returned object.
+ static PrintingContext* Create(const std::string& app_locale);
void set_margin_type(MarginType type);
@@ -120,7 +109,7 @@ class PRINTING_EXPORT PrintingContext {
}
protected:
- explicit PrintingContext(Delegate* delegate);
+ explicit PrintingContext(const std::string& app_locale);
// Reinitializes the settings for object reuse.
void ResetSettings();
@@ -131,9 +120,6 @@ class PRINTING_EXPORT PrintingContext {
// Complete print context settings.
PrintSettings settings_;
- // Printing context delegate.
- Delegate* delegate_;
-
// The dialog box has been dismissed.
volatile bool dialog_box_dismissed_;
@@ -143,6 +129,9 @@ class PRINTING_EXPORT PrintingContext {
// Did the user cancel the print job.
volatile bool abort_printing_;
+ // The application locale.
+ std::string app_locale_;
+
private:
DISALLOW_COPY_AND_ASSIGN(PrintingContext);
};
diff --git a/printing/printing_context_android.cc b/printing/printing_context_android.cc
index 39f1c6d..5729267 100644
--- a/printing/printing_context_android.cc
+++ b/printing/printing_context_android.cc
@@ -61,8 +61,8 @@ void GetPageRanges(JNIEnv* env,
namespace printing {
// static
-scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) {
- return make_scoped_ptr<PrintingContext>(new PrintingContextAndroid(delegate));
+PrintingContext* PrintingContext::Create(const std::string& app_locale) {
+ return new PrintingContextAndroid(app_locale);
}
// static
@@ -71,8 +71,8 @@ void PrintingContextAndroid::PdfWritingDone(int fd, bool success) {
Java_PrintingContext_pdfWritingDone(env, fd, success);
}
-PrintingContextAndroid::PrintingContextAndroid(Delegate* delegate)
- : PrintingContext(delegate) {
+PrintingContextAndroid::PrintingContextAndroid(const std::string& app_locale)
+ : PrintingContext(app_locale) {
// The constructor is run in the IO thread.
}
@@ -80,6 +80,7 @@ PrintingContextAndroid::~PrintingContextAndroid() {
}
void PrintingContextAndroid::AskUserForSettings(
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) {
@@ -148,8 +149,7 @@ gfx::Size PrintingContextAndroid::GetPdfPaperSizeDeviceUnits() {
int32_t width = 0;
int32_t height = 0;
UErrorCode error = U_ZERO_ERROR;
- ulocdata_getPaperSize(
- delegate_->GetAppLocale().c_str(), &height, &width, &error);
+ ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error);
if (error > U_ZERO_ERROR) {
// If the call failed, assume a paper size of 8.5 x 11 inches.
LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
diff --git a/printing/printing_context_android.h b/printing/printing_context_android.h
index 56068a1..b198e7b 100644
--- a/printing/printing_context_android.h
+++ b/printing/printing_context_android.h
@@ -19,7 +19,7 @@ namespace printing {
// Java side through JNI.
class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext {
public:
- explicit PrintingContextAndroid(Delegate* delegate);
+ explicit PrintingContextAndroid(const std::string& app_locale);
virtual ~PrintingContextAndroid();
// Called when the page is successfully written to a PDF using the file
@@ -32,6 +32,7 @@ class PRINTING_EXPORT PrintingContextAndroid : public PrintingContext {
// PrintingContext implementation.
virtual void AskUserForSettings(
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) OVERRIDE;
diff --git a/printing/printing_context_linux.cc b/printing/printing_context_linux.cc
index c267478..3b6d2ee 100644
--- a/printing/printing_context_linux.cc
+++ b/printing/printing_context_linux.cc
@@ -27,12 +27,13 @@ gfx::Size (*get_pdf_paper_size_)(
namespace printing {
// static
-scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) {
- return make_scoped_ptr<PrintingContext>(new PrintingContextLinux(delegate));
+PrintingContext* PrintingContext::Create(const std::string& app_locale) {
+ return static_cast<PrintingContext*>(new PrintingContextLinux(app_locale));
}
-PrintingContextLinux::PrintingContextLinux(Delegate* delegate)
- : PrintingContext(delegate), print_dialog_(NULL) {
+PrintingContextLinux::PrintingContextLinux(const std::string& app_locale)
+ : PrintingContext(app_locale),
+ print_dialog_(NULL) {
}
PrintingContextLinux::~PrintingContextLinux() {
@@ -66,6 +67,7 @@ void PrintingContextLinux::PrintDocument(const Metafile* metafile) {
}
void PrintingContextLinux::AskUserForSettings(
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) {
@@ -77,8 +79,7 @@ void PrintingContextLinux::AskUserForSettings(
return;
}
- print_dialog_->ShowDialog(
- delegate_->GetParentView(), has_selection, callback);
+ print_dialog_->ShowDialog(parent_view, has_selection, callback);
}
PrintingContext::Result PrintingContextLinux::UseDefaultSettings() {
diff --git a/printing/printing_context_linux.h b/printing/printing_context_linux.h
index 984d7dc..3076014 100644
--- a/printing/printing_context_linux.h
+++ b/printing/printing_context_linux.h
@@ -21,7 +21,7 @@ class PrintDialogGtkInterface;
// PrintingContext with optional native UI for print dialog and pdf_paper_size.
class PRINTING_EXPORT PrintingContextLinux : public PrintingContext {
public:
- explicit PrintingContextLinux(Delegate* delegate);
+ explicit PrintingContextLinux(const std::string& app_locale);
virtual ~PrintingContextLinux();
// Sets the function that creates the print dialog.
@@ -38,6 +38,7 @@ class PRINTING_EXPORT PrintingContextLinux : public PrintingContext {
// PrintingContext implementation.
virtual void AskUserForSettings(
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) OVERRIDE;
diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h
index 9eb924a..f16ef54 100644
--- a/printing/printing_context_mac.h
+++ b/printing/printing_context_mac.h
@@ -21,11 +21,12 @@ namespace printing {
class PRINTING_EXPORT PrintingContextMac : public PrintingContext {
public:
- explicit PrintingContextMac(Delegate* delegate);
+ explicit PrintingContextMac(const std::string& app_locale);
virtual ~PrintingContextMac();
// PrintingContext implementation.
virtual void AskUserForSettings(
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) OVERRIDE;
diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm
index fa907b5..9bbe5ac1 100644
--- a/printing/printing_context_mac.mm
+++ b/printing/printing_context_mac.mm
@@ -68,12 +68,12 @@ PMPaper MatchPaper(CFArrayRef paper_list,
} // namespace
// static
-scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) {
- return make_scoped_ptr<PrintingContext>(new PrintingContextMac(delegate));
+PrintingContext* PrintingContext::Create(const std::string& app_locale) {
+ return static_cast<PrintingContext*>(new PrintingContextMac(app_locale));
}
-PrintingContextMac::PrintingContextMac(Delegate* delegate)
- : PrintingContext(delegate),
+PrintingContextMac::PrintingContextMac(const std::string& app_locale)
+ : PrintingContext(app_locale),
print_info_([[NSPrintInfo sharedPrintInfo] copy]),
context_(NULL) {
}
@@ -83,6 +83,7 @@ PrintingContextMac::~PrintingContextMac() {
}
void PrintingContextMac::AskUserForSettings(
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) {
@@ -114,7 +115,6 @@ void PrintingContextMac::AskUserForSettings(
[panel setOptions:options];
// Set the print job title text.
- gfx::NativeView parent_view = delegate_->GetParentView();
if (parent_view) {
NSString* job_title = [[parent_view window] title];
if (job_title) {
diff --git a/printing/printing_context_no_system_dialog.cc b/printing/printing_context_no_system_dialog.cc
index fd6e166..4768e4d 100644
--- a/printing/printing_context_no_system_dialog.cc
+++ b/printing/printing_context_no_system_dialog.cc
@@ -15,13 +15,13 @@
namespace printing {
// static
-scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) {
- return make_scoped_ptr<PrintingContext>(
- new PrintingContextNoSystemDialog(delegate));
+PrintingContext* PrintingContext::Create(const std::string& app_locale) {
+ return static_cast<PrintingContext*>(
+ new PrintingContextNoSystemDialog(app_locale));
}
-PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate)
- : PrintingContext(delegate) {
+PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(
+ const std::string& app_locale) : PrintingContext(app_locale) {
}
PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
@@ -29,6 +29,7 @@ PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
}
void PrintingContextNoSystemDialog::AskUserForSettings(
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) {
@@ -53,8 +54,7 @@ gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
int32_t width = 0;
int32_t height = 0;
UErrorCode error = U_ZERO_ERROR;
- ulocdata_getPaperSize(
- delegate_->GetAppLocale().c_str(), &height, &width, &error);
+ ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error);
if (error > U_ZERO_ERROR) {
// If the call failed, assume a paper size of 8.5 x 11 inches.
LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
diff --git a/printing/printing_context_no_system_dialog.h b/printing/printing_context_no_system_dialog.h
index fbc69aa..5472a81 100644
--- a/printing/printing_context_no_system_dialog.h
+++ b/printing/printing_context_no_system_dialog.h
@@ -17,11 +17,12 @@ namespace printing {
class PRINTING_EXPORT PrintingContextNoSystemDialog : public PrintingContext {
public:
- explicit PrintingContextNoSystemDialog(Delegate* delegate);
+ explicit PrintingContextNoSystemDialog(const std::string& app_locale);
virtual ~PrintingContextNoSystemDialog();
// PrintingContext implementation.
virtual void AskUserForSettings(
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) OVERRIDE;
diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc
index dd0e2c4..b0a9644 100644
--- a/printing/printing_context_win.cc
+++ b/printing/printing_context_win.cc
@@ -45,26 +45,24 @@ HWND GetRootWindow(gfx::NativeView view) {
namespace printing {
// static
-scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) {
- return make_scoped_ptr<PrintingContext>(new PrintingContextWin(delegate));
+PrintingContext* PrintingContext::Create(const std::string& app_locale) {
+ return static_cast<PrintingContext*>(new PrintingContextWin(app_locale));
}
-PrintingContextWin::PrintingContextWin(Delegate* delegate)
- : PrintingContext(delegate), context_(NULL), dialog_box_(NULL) {
-}
+PrintingContextWin::PrintingContextWin(const std::string& app_locale)
+ : PrintingContext(app_locale), context_(NULL), dialog_box_(NULL) {}
PrintingContextWin::~PrintingContextWin() {
ReleaseContext();
}
void PrintingContextWin::AskUserForSettings(
- int max_pages,
- bool has_selection,
+ gfx::NativeView view, int max_pages, bool has_selection,
const PrintSettingsCallback& callback) {
DCHECK(!in_print_job_);
dialog_box_dismissed_ = false;
- HWND window = GetRootWindow(delegate_->GetParentView());
+ HWND window = GetRootWindow(view);
DCHECK(window);
// Show the OS-dependent dialog box.
diff --git a/printing/printing_context_win.h b/printing/printing_context_win.h
index 94fd041..6c1e420 100644
--- a/printing/printing_context_win.h
+++ b/printing/printing_context_win.h
@@ -19,11 +19,12 @@ namespace printing {
class PRINTING_EXPORT PrintingContextWin : public PrintingContext {
public:
- explicit PrintingContextWin(Delegate* delegate);
- virtual ~PrintingContextWin();
+ explicit PrintingContextWin(const std::string& app_locale);
+ ~PrintingContextWin();
// PrintingContext implementation.
virtual void AskUserForSettings(
+ gfx::NativeView parent_view,
int max_pages,
bool has_selection,
const PrintSettingsCallback& callback) OVERRIDE;
diff --git a/printing/printing_context_win_unittest.cc b/printing/printing_context_win_unittest.cc
index 1d27935..c9facc9 100644
--- a/printing/printing_context_win_unittest.cc
+++ b/printing/printing_context_win_unittest.cc
@@ -22,17 +22,12 @@
namespace printing {
// This test is automatically disabled if no printer is available.
-class PrintingContextTest : public PrintingTest<testing::Test>,
- public PrintingContext::Delegate {
+class PrintingContextTest : public PrintingTest<testing::Test> {
public:
void PrintSettingsCallback(PrintingContext::Result result) {
result_ = result;
}
- // PrintingContext::Delegate methods.
- virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; }
- virtual std::string GetAppLocale() OVERRIDE { return std::string(); }
-
protected:
PrintingContext::Result result() const { return result_; }
@@ -42,7 +37,7 @@ class PrintingContextTest : public PrintingTest<testing::Test>,
class MockPrintingContextWin : public PrintingContextWin {
public:
- MockPrintingContextWin(Delegate* delegate) : PrintingContextWin(delegate) {}
+ MockPrintingContextWin() : PrintingContextWin("") {}
protected:
// This is a fake PrintDlgEx implementation that sets the right fields in
@@ -164,7 +159,7 @@ TEST_F(PrintingContextTest, Base) {
PrintSettings settings;
settings.set_device_name(GetDefaultPrinter());
// Initialize it.
- scoped_ptr<PrintingContext> context(PrintingContext::Create(this));
+ scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string()));
EXPECT_EQ(PrintingContext::OK, context->InitWithSettings(settings));
// The print may lie to use and may not support world transformation.
@@ -179,12 +174,10 @@ TEST_F(PrintingContextTest, PrintAll) {
if (IsTestCaseDisabled())
return;
- MockPrintingContextWin context(this);
+ MockPrintingContextWin context;
context.AskUserForSettings(
- 123,
- false,
- base::Bind(&PrintingContextTest::PrintSettingsCallback,
- base::Unretained(this)));
+ NULL, 123, false, base::Bind(&PrintingContextTest::PrintSettingsCallback,
+ base::Unretained(this)));
EXPECT_EQ(PrintingContext::OK, result());
PrintSettings settings = context.settings();
EXPECT_EQ(settings.ranges().size(), 0);