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

Unified Diff: chrome/browser/printing/pwg_raster_converter.cc

Issue 2477283002: Convert printing IPCs to Mojo
Patch Set: Address sammc's review comments Created 3 years, 11 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
Index: chrome/browser/printing/pwg_raster_converter.cc
diff --git a/chrome/browser/printing/pwg_raster_converter.cc b/chrome/browser/printing/pwg_raster_converter.cc
index 1a7200fd986df6c20f085f17895a490f47878dd9..fdbf0fe3013ab0a0b3e452752547297ad0069819 100644
--- a/chrome/browser/printing/pwg_raster_converter.cc
+++ b/chrome/browser/printing/pwg_raster_converter.cc
@@ -20,10 +20,10 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/common/chrome_utility_messages.h"
-#include "chrome/common/chrome_utility_printing_messages.h"
#include "chrome/grit/generated_resources.h"
#include "components/cloud_devices/common/cloud_device_description.h"
#include "components/cloud_devices/common/printer_description.h"
+#include "components/printing/common/printing.mojom.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/utility_process_host.h"
@@ -31,6 +31,7 @@
#include "printing/pdf_render_settings.h"
#include "printing/pwg_raster_settings.h"
#include "printing/units.h"
+#include "services/service_manager/public/cpp/interface_provider.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
@@ -60,18 +61,14 @@ class FileHandlers {
return temp_dir_.GetPath().AppendASCII("input.pdf");
}
- IPC::PlatformFileForTransit GetPdfForProcess() {
+ base::File GetPdfForProcess() {
DCHECK(pdf_file_.IsValid());
- IPC::PlatformFileForTransit transit =
- IPC::TakePlatformFileForTransit(std::move(pdf_file_));
- return transit;
+ return pdf_file_.Duplicate();
Vitaly Buka (NO REVIEWS) 2017/01/12 19:57:59 does this guarantee that files will be deleted whe
tibell 2017/01/13 02:51:10 Done.
}
- IPC::PlatformFileForTransit GetPwgForProcess() {
+ base::File GetPwgForProcess() {
DCHECK(pwg_file_.IsValid());
- IPC::PlatformFileForTransit transit =
- IPC::TakePlatformFileForTransit(std::move(pwg_file_));
- return transit;
+ return pwg_file_.Duplicate();
}
private:
@@ -132,10 +129,6 @@ class PwgUtilityProcessHostClient : public content::UtilityProcessHostClient {
private:
~PwgUtilityProcessHostClient() override;
- // Message handlers.
- void OnSucceeded();
- void OnFailed();
-
void RunCallback(bool success);
void StartProcessOnIOThread();
@@ -147,6 +140,7 @@ class PwgUtilityProcessHostClient : public content::UtilityProcessHostClient {
PdfRenderSettings settings_;
PwgRasterSettings bitmap_settings_;
PWGRasterConverter::ResultCallback callback_;
+ mojom::PrintingPtr printing_;
DISALLOW_COPY_AND_ASSIGN(PwgUtilityProcessHostClient);
};
@@ -176,30 +170,12 @@ void PwgUtilityProcessHostClient::Convert(
}
void PwgUtilityProcessHostClient::OnProcessCrashed(int exit_code) {
- OnFailed();
+ RunCallback(false);
}
bool PwgUtilityProcessHostClient::OnMessageReceived(
const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(PwgUtilityProcessHostClient, message)
- IPC_MESSAGE_HANDLER(
- ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Succeeded, OnSucceeded)
- IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Failed,
- OnFailed)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-void PwgUtilityProcessHostClient::OnSucceeded() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- RunCallback(true);
-}
-
-void PwgUtilityProcessHostClient::OnFailed() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- RunCallback(false);
+ return false;
}
void PwgUtilityProcessHostClient::OnFilesReadyOnUIThread() {
@@ -217,17 +193,28 @@ void PwgUtilityProcessHostClient::OnFilesReadyOnUIThread() {
void PwgUtilityProcessHostClient::StartProcessOnIOThread() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ // TODO: Use UtilityProcessMojoClient to manage process lifetime instead.
Sam McNally 2017/01/12 04:49:53 TODO(...)
tibell 2017/01/13 02:51:10 Done.
content::UtilityProcessHost* utility_process_host =
content::UtilityProcessHost::Create(this,
base::ThreadTaskRunnerHandle::Get());
- utility_process_host->SetName(l10n_util::GetStringUTF16(
- IDS_UTILITY_PROCESS_PWG_RASTER_CONVERTOR_NAME));
- utility_process_host->Send(new ChromeUtilityMsg_RenderPDFPagesToPWGRaster(
+ utility_process_host->SetName(
+ l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PWG_RASTER_CONVERTOR_NAME));
+ utility_process_host->Start();
+
+ mojom::PrintingFactoryPtr printing_factory;
+ utility_process_host->GetRemoteInterfaces()->GetInterface(&printing_factory);
+ // We don't care about calls to FontPreCaching so we pass a null pointer for
+ // the second argument.
+ printing_factory->MakePrinting(mojo::MakeRequest(&printing_),
+ mojom::FontPreCachingPtr());
+ printing_->RenderPDFPagesToPWGRaster(
files_->GetPdfForProcess(), settings_, bitmap_settings_,
- files_->GetPwgForProcess()));
+ files_->GetPwgForProcess(),
+ base::Bind(&PwgUtilityProcessHostClient::RunCallback, this));
}
void PwgUtilityProcessHostClient::RunCallback(bool success) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&PwgUtilityProcessHostClient::RunCallbackOnUIThread, this,

Powered by Google App Engine
This is Rietveld 408576698