Chromium Code Reviews| 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..6833cfeb797562b65da7350fe29de6db3982d189 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" |
|
Sam McNally
2017/01/05 06:23:15
Remove.
tibell
2017/01/12 03:30:14
Done.
|
| #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() { |
| + base::File GetPdfForProcess() { |
| DCHECK(pdf_file_.IsValid()); |
| - IPC::PlatformFileForTransit transit = |
| - IPC::TakePlatformFileForTransit(std::move(pdf_file_)); |
| - return transit; |
| + return pdf_file_.Duplicate(); |
| } |
| - 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 +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( |
|
Sam McNally
2017/01/05 06:23:15
I suspect this could also be simplified by using U
tibell
2017/01/12 03:30:14
Added TODO.
|
| + 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, |