summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-16 00:29:22 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-16 00:29:22 +0000
commitfbea02332ae95f590c8a84019b582fa35e788a7c (patch)
treeeeff857a083663f3d5556fcff304b5fd05e32eb2 /printing
parent0018067c7afbdf516d1845b35a3a245d96910f66 (diff)
downloadchromium_src-fbea02332ae95f590c8a84019b582fa35e788a7c.zip
chromium_src-fbea02332ae95f590c8a84019b582fa35e788a7c.tar.gz
chromium_src-fbea02332ae95f590c8a84019b582fa35e788a7c.tar.bz2
Linux: print page to file rather than using shared memory to send it to the browser.
BUG=9847 adapted from patch by <minyu.huang [at] gmail> Review URL: http://codereview.chromium.org/203062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26308 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/pdf_ps_metafile_linux.cc22
-rw-r--r--printing/pdf_ps_metafile_linux.h10
-rw-r--r--printing/pdf_ps_metafile_linux_unittest.cc17
3 files changed, 35 insertions, 14 deletions
diff --git a/printing/pdf_ps_metafile_linux.cc b/printing/pdf_ps_metafile_linux.cc
index d55795c..d5fe5fb 100644
--- a/printing/pdf_ps_metafile_linux.cc
+++ b/printing/pdf_ps_metafile_linux.cc
@@ -16,6 +16,8 @@
#include <map>
+#include "base/eintr_wrapper.h"
+#include "base/file_descriptor_posix.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/singleton.h"
@@ -471,7 +473,7 @@ bool PdfPsMetafile::GetData(void* dst_buffer, size_t dst_buffer_size) const {
return true;
}
-bool PdfPsMetafile::SaveTo(const FilePath& filename) const {
+bool PdfPsMetafile::SaveTo(const base::FileDescriptor& fd) const {
// We need to check at least these two members to ensure that either Init()
// has been called to initialize |all_pages_|, or metafile has been closed.
// Passing these two checks also implies that surface_, page_surface_, and
@@ -479,15 +481,21 @@ bool PdfPsMetafile::SaveTo(const FilePath& filename) const {
DCHECK(!context_);
DCHECK(!all_pages_.empty());
- const unsigned int data_size = GetDataSize();
- const unsigned int bytes_written =
- file_util::WriteFile(filename, all_pages_.data(), data_size);
- if (bytes_written != data_size) {
- DLOG(ERROR) << "Failed to save file: " << filename.value();
+ if (fd.fd < 0) {
+ DLOG(ERROR) << "Invalid file descriptor!";
return false;
}
- return true;
+ bool success = true;
+ if (file_util::WriteFileDescriptor(fd.fd, all_pages_.data(),
+ GetDataSize()) < 0) {
+ DLOG(ERROR) << "Failed to save file with fd " << fd.fd;
+ success = false;
+ }
+
+ if (fd.auto_close)
+ HANDLE_EINTR(close(fd.fd));
+ return success;
}
void PdfPsMetafile::CleanUpAll() {
diff --git a/printing/pdf_ps_metafile_linux.h b/printing/pdf_ps_metafile_linux.h
index 04b0ca1e..faf6ab7 100644
--- a/printing/pdf_ps_metafile_linux.h
+++ b/printing/pdf_ps_metafile_linux.h
@@ -12,6 +12,10 @@
typedef struct _cairo_surface cairo_surface_t;
typedef struct _cairo cairo_t;
+namespace base {
+class FileDescriptor;
+}
+
class FilePath;
namespace printing {
@@ -77,10 +81,10 @@ class PdfPsMetafile {
// Returns true only when success.
bool GetData(void* dst_buffer, size_t dst_buffer_size) const;
- // Saves PDF/PS contents stored in buffer |all_pages_| into |filename| on
- // the disk.
+ // Saves PDF/PS contents stored in buffer |all_pages_| into the file
+ // associated with |fd|.
// This function should ONLY be called after PDF/PS file is closed.
- bool SaveTo(const FilePath& filename) const;
+ bool SaveTo(const base::FileDescriptor& fd) const;
private:
// Cleans up all resources.
diff --git a/printing/pdf_ps_metafile_linux_unittest.cc b/printing/pdf_ps_metafile_linux_unittest.cc
index 7339559..e852b37 100644
--- a/printing/pdf_ps_metafile_linux_unittest.cc
+++ b/printing/pdf_ps_metafile_linux_unittest.cc
@@ -4,15 +4,24 @@
#include "printing/pdf_ps_metafile_linux.h"
+#include <fcntl.h>
#include <string>
#include <vector>
+#include "base/file_descriptor_posix.h"
#include "base/file_util.h"
#include "testing/gtest/include/gtest/gtest.h"
typedef struct _cairo cairo_t;
-TEST(PdfTest, ThreePages) {
+class PdfPsTest : public testing::Test {
+ protected:
+ base::FileDescriptor DevNullFD() {
+ return base::FileDescriptor(open("/dev/null", O_WRONLY), true);
+ }
+};
+
+TEST_F(PdfPsTest, Pdf) {
// Tests in-renderer constructor.
printing::PdfPsMetafile pdf(printing::PdfPsMetafile::PDF);
EXPECT_TRUE(pdf.Init());
@@ -53,10 +62,10 @@ TEST(PdfTest, ThreePages) {
EXPECT_EQ(header.find("%PDF", 0), 0u);
// Tests if we can save data.
- EXPECT_TRUE(pdf.SaveTo(FilePath("/dev/null")));
+ EXPECT_TRUE(pdf.SaveTo(DevNullFD()));
}
-TEST(PsTest, TwoPages) {
+TEST_F(PdfPsTest, Ps) {
// Tests in-renderer constructor.
printing::PdfPsMetafile ps(printing::PdfPsMetafile::PS);
EXPECT_TRUE(ps.Init());
@@ -97,5 +106,5 @@ TEST(PsTest, TwoPages) {
EXPECT_EQ(header.find("%!PS", 0), 0u);
// Tests if we can save data.
- EXPECT_TRUE(ps.SaveTo(FilePath("/dev/null")));
+ EXPECT_TRUE(ps.SaveTo(DevNullFD()));
}