| 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..eaa4822dedc25881d221ec642f3d86d8de762955 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 std::move(pdf_file_);
|
| }
|
|
|
| - IPC::PlatformFileForTransit GetPwgForProcess() {
|
| + base::File GetPwgForProcess() {
|
| DCHECK(pwg_file_.IsValid());
|
| - IPC::PlatformFileForTransit transit =
|
| - IPC::TakePlatformFileForTransit(std::move(pwg_file_));
|
| - return transit;
|
| + return std::move(pwg_file_);
|
| }
|
|
|
| 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,29 @@ void PwgUtilityProcessHostClient::OnFilesReadyOnUIThread() {
|
| void PwgUtilityProcessHostClient::StartProcessOnIOThread() {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|
| + // TODO(tibell): Use UtilityProcessMojoClient to manage process lifetime
|
| + // instead.
|
| 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,
|
|
|