summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 00:47:38 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 00:47:38 +0000
commita51b060edcd1695b240c96b0b7d3d4a25995303e (patch)
tree696e20c9828b370cf926c447402799e3bb89fd6d
parent767e9978a48a0d0f2c82988f146e8ff62c6941a3 (diff)
downloadchromium_src-a51b060edcd1695b240c96b0b7d3d4a25995303e.zip
chromium_src-a51b060edcd1695b240c96b0b7d3d4a25995303e.tar.gz
chromium_src-a51b060edcd1695b240c96b0b7d3d4a25995303e.tar.bz2
Linux Printing: Move file open operation to file thread.
Also delete the temp file when we're done with it (usually). BUG=22097 TEST=printing still works Review URL: http://codereview.chromium.org/215015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26531 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/printing/print_dialog_gtk.cc3
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc4
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h4
-rw-r--r--chrome/browser/renderer_host/resource_message_filter_gtk.cc98
4 files changed, 63 insertions, 46 deletions
diff --git a/chrome/browser/printing/print_dialog_gtk.cc b/chrome/browser/printing/print_dialog_gtk.cc
index 81171a6..77d2e9b 100644
--- a/chrome/browser/printing/print_dialog_gtk.cc
+++ b/chrome/browser/printing/print_dialog_gtk.cc
@@ -8,6 +8,7 @@
#include <gtk/gtkprintunixdialog.h>
#include <gtk/gtkpagesetupunixdialog.h>
+#include "base/file_util.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "chrome/browser/browser_list.h"
@@ -134,5 +135,7 @@ void PrintDialogGtk::OnJobCompleted(GtkPrintJob* job, GError* error) {
if (job)
g_object_unref(job);
+ file_util::Delete(path_to_pdf_, false);
+
delete this;
}
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 4a5de3a..781543e 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -339,8 +339,8 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection)
#endif
#if defined(OS_LINUX)
- IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateTempFileForPrinting,
- OnAllocateTempFileForPrinting)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_AllocateTempFileForPrinting,
+ OnAllocateTempFileForPrinting)
IPC_MESSAGE_HANDLER(ViewHostMsg_TempFileForPrintingWritten,
OnTempFileForPrintingWritten)
#endif
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index dceaa3d..00c3b13 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -209,8 +209,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
#if defined(OS_LINUX)
// Used to ask the browser allocate a temporary file for the renderer
// to fill in resulting PDF in renderer.
- void OnAllocateTempFileForPrinting(base::FileDescriptor* temp_file_fd,
- int* fd_in_browser);
+ void OnAllocateTempFileForPrinting(IPC::Message* reply_msg);
void OnTempFileForPrintingWritten(int fd_in_browser);
#endif
@@ -270,6 +269,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void DoOnClipboardReadAsciiText(Clipboard::Buffer buffer,
IPC::Message* reply_msg);
void DoOnClipboardReadHTML(Clipboard::Buffer buffer, IPC::Message* reply_msg);
+ void DoOnAllocateTempFileForPrinting(IPC::Message* reply_msg);
#endif
bool CheckBenchmarkingEnabled();
diff --git a/chrome/browser/renderer_host/resource_message_filter_gtk.cc b/chrome/browser/renderer_host/resource_message_filter_gtk.cc
index 3ae5343..d6fb45e 100644
--- a/chrome/browser/renderer_host/resource_message_filter_gtk.cc
+++ b/chrome/browser/renderer_host/resource_message_filter_gtk.cc
@@ -56,7 +56,7 @@ void ResourceMessageFilter::DoOnGetScreenInfo(gfx::NativeViewId view,
ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
+ this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
}
// Called on the BACKGROUND_X11 thread.
@@ -80,7 +80,7 @@ void ResourceMessageFilter::DoOnGetWindowRect(gfx::NativeViewId view,
ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
+ this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
}
// Return the top-level parent of the given window. Called on the
@@ -119,7 +119,7 @@ void ResourceMessageFilter::DoOnGetRootWindowRect(gfx::NativeViewId view,
ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
+ this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
}
// Called on the UI thread.
@@ -132,7 +132,7 @@ void ResourceMessageFilter::DoOnClipboardIsFormatAvailable(
ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
+ this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
}
// Called on the UI thread.
@@ -145,7 +145,7 @@ void ResourceMessageFilter::DoOnClipboardReadText(Clipboard::Buffer buffer,
ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
+ this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
}
// Called on the UI thread.
@@ -158,7 +158,7 @@ void ResourceMessageFilter::DoOnClipboardReadAsciiText(
ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
+ this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
}
// Called on the UI thread.
@@ -173,7 +173,39 @@ void ResourceMessageFilter::DoOnClipboardReadHTML(Clipboard::Buffer buffer,
ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
+ this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
+}
+
+// Called on the FILE thread.
+void ResourceMessageFilter::DoOnAllocateTempFileForPrinting(
+ IPC::Message* reply_msg) {
+ base::FileDescriptor temp_file_fd;
+ int fd_in_browser;
+ temp_file_fd.fd = fd_in_browser = -1;
+ temp_file_fd.auto_close = false;
+
+ FilePath path;
+ if (file_util::CreateTemporaryFile(&path)) {
+ int fd = open(path.value().c_str(), O_WRONLY);
+ if (fd >= 0) {
+ FdMap* map = &Singleton<PrintingFileDescriptorMap>::get()->map;
+ FdMap::iterator it = map->find(fd);
+ if (it != map->end()) {
+ NOTREACHED() << "The file descriptor is in use. fd=" << fd;
+ } else {
+ (*map)[fd] = path;
+ temp_file_fd.fd = fd_in_browser = fd;
+ temp_file_fd.auto_close = true;
+ }
+ }
+ }
+
+ ViewHostMsg_AllocateTempFileForPrinting::WriteReplyParams(
+ reply_msg, temp_file_fd, fd_in_browser);
+
+ ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(
+ FROM_HERE, NewRunnableMethod(
+ this, &ResourceMessageFilter::SendDelayedReply, reply_msg));
}
// Called on the IO thread.
@@ -181,7 +213,7 @@ void ResourceMessageFilter::OnGetScreenInfo(gfx::NativeViewId view,
IPC::Message* reply_msg) {
ChromeThread::GetMessageLoop(ChromeThread::BACKGROUND_X11)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnGetScreenInfo, view, reply_msg));
+ this, &ResourceMessageFilter::DoOnGetScreenInfo, view, reply_msg));
}
// Called on the IO thread.
@@ -189,7 +221,7 @@ void ResourceMessageFilter::OnGetWindowRect(gfx::NativeViewId view,
IPC::Message* reply_msg) {
ChromeThread::GetMessageLoop(ChromeThread::BACKGROUND_X11)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnGetWindowRect, view, reply_msg));
+ this, &ResourceMessageFilter::DoOnGetWindowRect, view, reply_msg));
}
// Called on the IO thread.
@@ -197,7 +229,8 @@ void ResourceMessageFilter::OnGetRootWindowRect(gfx::NativeViewId view,
IPC::Message* reply_msg) {
ChromeThread::GetMessageLoop(ChromeThread::BACKGROUND_X11)->PostTask(
FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnGetRootWindowRect, view, reply_msg));
+ this, &ResourceMessageFilter::DoOnGetRootWindowRect, view,
+ reply_msg));
}
// Called on the IO thread.
@@ -205,60 +238,41 @@ void ResourceMessageFilter::OnClipboardIsFormatAvailable(
Clipboard::FormatType format, Clipboard::Buffer buffer,
IPC::Message* reply_msg) {
ui_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnClipboardIsFormatAvailable, format,
- buffer, reply_msg));
+ this, &ResourceMessageFilter::DoOnClipboardIsFormatAvailable, format,
+ buffer, reply_msg));
}
// Called on the IO thread.
void ResourceMessageFilter::OnClipboardReadText(Clipboard::Buffer buffer,
IPC::Message* reply_msg) {
ui_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnClipboardReadText, buffer,
- reply_msg));
+ this, &ResourceMessageFilter::DoOnClipboardReadText, buffer,
+ reply_msg));
}
// Called on the IO thread.
void ResourceMessageFilter::OnClipboardReadAsciiText(Clipboard::Buffer buffer,
IPC::Message* reply_msg) {
ui_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnClipboardReadAsciiText, buffer,
- reply_msg));
+ this, &ResourceMessageFilter::DoOnClipboardReadAsciiText, buffer,
+ reply_msg));
}
// Called on the IO thread.
void ResourceMessageFilter::OnClipboardReadHTML(Clipboard::Buffer buffer,
IPC::Message* reply_msg) {
ui_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnClipboardReadHTML, buffer,
- reply_msg));
+ this, &ResourceMessageFilter::DoOnClipboardReadHTML, buffer,
+ reply_msg));
}
// Called on the IO thread.
void ResourceMessageFilter::OnAllocateTempFileForPrinting(
- base::FileDescriptor* temp_file_fd, int* fd_in_browser) {
- temp_file_fd->fd = *fd_in_browser = -1;
-
- FilePath path;
- if (!file_util::CreateTemporaryFile(&path))
- return;
-
- int fd = open(path.value().c_str(), O_WRONLY);
- if (fd < 0)
- return;
-
- // We need to remember the FilePath of the temporary file because we need
- // it when we want to rename/move it, and more importantly, to print it
- // when we print by using gtk_print_job_set_source_file().
- FdMap* map = &Singleton<PrintingFileDescriptorMap>::get()->map;
- FdMap::iterator it = map->find(fd);
- if (it != map->end()) {
- NOTREACHED() << "The file descriptor is in use. fd=" << fd;
- return;
- }
-
- (*map)[fd] = path;
- temp_file_fd->fd = *fd_in_browser = fd;
- temp_file_fd->auto_close = true;
+ IPC::Message* reply_msg) {
+ ChromeThread::GetMessageLoop(ChromeThread::FILE)->PostTask(
+ FROM_HERE, NewRunnableMethod(
+ this, &ResourceMessageFilter::DoOnAllocateTempFileForPrinting,
+ reply_msg));
}
// Called on the IO thread.