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

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

Issue 2477283002: Convert printing IPCs to Mojo
Patch Set: git cl format Created 4 years 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..7b4e4e81ed4b99cd10d271991e2599784d5d23e5 100644
--- a/chrome/browser/printing/pwg_raster_converter.cc
+++ b/chrome/browser/printing/pwg_raster_converter.cc
@@ -20,17 +20,19 @@
#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"
#include "content/public/browser/utility_process_host_client.h"
+#include "mojo/public/cpp/system/platform_handle.h"
#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 +62,14 @@ class FileHandlers {
return temp_dir_.GetPath().AppendASCII("input.pdf");
}
- IPC::PlatformFileForTransit GetPdfForProcess() {
+ mojo::ScopedHandle GetPdfForProcess() {
DCHECK(pdf_file_.IsValid());
- IPC::PlatformFileForTransit transit =
- IPC::TakePlatformFileForTransit(std::move(pdf_file_));
- return transit;
+ return mojo::WrapPlatformFile(pdf_file_.TakePlatformFile());
}
- IPC::PlatformFileForTransit GetPwgForProcess() {
+ mojo::ScopedHandle GetPwgForProcess() {
DCHECK(pwg_file_.IsValid());
- IPC::PlatformFileForTransit transit =
- IPC::TakePlatformFileForTransit(std::move(pwg_file_));
- return transit;
+ return mojo::WrapPlatformFile(pwg_file_.TakePlatformFile());
}
private:
@@ -132,10 +130,6 @@ class PwgUtilityProcessHostClient : public content::UtilityProcessHostClient {
private:
~PwgUtilityProcessHostClient() override;
- // Message handlers.
- void OnSucceeded();
- void OnFailed();
-
void RunCallback(bool success);
void StartProcessOnIOThread();
@@ -147,6 +141,7 @@ class PwgUtilityProcessHostClient : public content::UtilityProcessHostClient {
PdfRenderSettings settings_;
PwgRasterSettings bitmap_settings_;
PWGRasterConverter::ResultCallback callback_;
+ mojom::PrintingPtr printing_;
DISALLOW_COPY_AND_ASSIGN(PwgUtilityProcessHostClient);
};
@@ -176,30 +171,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() {
@@ -220,14 +197,24 @@ void PwgUtilityProcessHostClient::StartProcessOnIOThread() {
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::GetProxy(&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