Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4390)

Unified Diff: chrome/service/service_utility_process_host.cc

Issue 255543006: Printing on Windows via PDF (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove ref to internal_pdf and rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/service/service_utility_process_host.h ('k') | chrome/utility/chrome_content_utility_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/service/service_utility_process_host.cc
diff --git a/chrome/service/service_utility_process_host.cc b/chrome/service/service_utility_process_host.cc
index 3054adc3e16abb5408f5639f08c2e5214a6da03d..d8be0b1f2fed605b246308fcbb5888b541780a20 100644
--- a/chrome/service/service_utility_process_host.cc
+++ b/chrome/service/service_utility_process_host.cc
@@ -107,35 +107,18 @@ bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile(
scratch_metafile_dir_.reset(new base::ScopedTempDir);
if (!scratch_metafile_dir_->CreateUniqueTempDir())
return false;
- if (!base::CreateTemporaryFileInDir(scratch_metafile_dir_->path(),
- &metafile_path_)) {
- return false;
- }
-
+ metafile_path_ = scratch_metafile_dir_->path().AppendASCII("output.emf");
if (!StartProcess(false, scratch_metafile_dir_->path()))
return false;
- base::win::ScopedHandle pdf_file(
- ::CreateFile(pdf_path.value().c_str(),
- GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL));
- if (pdf_file == INVALID_HANDLE_VALUE)
- return false;
- HANDLE pdf_file_in_utility_process = NULL;
- ::DuplicateHandle(::GetCurrentProcess(), pdf_file, handle(),
- &pdf_file_in_utility_process, 0, false,
- DUPLICATE_SAME_ACCESS);
- if (!pdf_file_in_utility_process)
- return false;
+ base::File pdf_file(
+ pdf_path,
+ base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE);
DCHECK(!waiting_for_reply_);
waiting_for_reply_ = true;
return child_process_host_->Send(
- new ChromeUtilityMsg_RenderPDFPagesToMetafile(
- pdf_file_in_utility_process,
+ new ChromeUtilityMsg_RenderPDFPagesToMetafiles(
+ IPC::TakeFileHandleForProcess(pdf_file.Pass(), handle()),
metafile_path_,
render_settings,
page_ranges));
@@ -248,8 +231,8 @@ bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message)
IPC_MESSAGE_HANDLER(
- ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded,
- OnRenderPDFPagesToMetafileSucceeded)
+ ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_Succeeded,
+ OnRenderPDFPagesToMetafilesSucceeded)
IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed,
OnRenderPDFPagesToMetafileFailed)
IPC_MESSAGE_HANDLER(
@@ -272,8 +255,8 @@ base::ProcessHandle ServiceUtilityProcessHost::GetHandle() const {
return handle_;
}
-void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileSucceeded(
- int highest_rendered_page_number,
+void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesSucceeded(
+ const std::vector<printing::PageRange>& page_ranges,
double scale_factor) {
UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceUtilityProcessHostEvent",
SERVICE_UTILITY_METAFILE_SUCCEEDED,
@@ -286,10 +269,21 @@ void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileSucceeded(
// scratch metafile directory. The client will delete it when it is done with
// metafile.
scratch_metafile_dir_->Take();
+
+ // TODO(vitalybuka|scottmg): http://crbug.com/170859: Currently, only one
+ // page is printed at a time. This would need to be refactored to change
+ // this.
+ CHECK_EQ(1u, page_ranges.size());
+ CHECK_EQ(page_ranges[0].from, page_ranges[0].to);
+ int page_number = page_ranges[0].from;
client_message_loop_proxy_->PostTask(
FROM_HERE,
- base::Bind(&Client::MetafileAvailable, client_.get(), metafile_path_,
- highest_rendered_page_number, scale_factor));
+ base::Bind(&Client::MetafileAvailable,
+ client_.get(),
+ metafile_path_.InsertBeforeExtensionASCII(
+ base::StringPrintf(".%d", page_number)),
+ page_number,
+ scale_factor));
}
void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileFailed() {
« no previous file with comments | « chrome/service/service_utility_process_host.h ('k') | chrome/utility/chrome_content_utility_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698