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

Unified Diff: chrome/browser/printing/pdf_to_emf_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/pdf_to_emf_converter.cc
diff --git a/chrome/browser/printing/pdf_to_emf_converter.cc b/chrome/browser/printing/pdf_to_emf_converter.cc
index fb0be329e76d0325e4b0c20645adf832fb1d3303..1315697b64632ee2f91357515cc8bf48e719844a 100644
--- a/chrome/browser/printing/pdf_to_emf_converter.cc
+++ b/chrome/browser/printing/pdf_to_emf_converter.cc
@@ -20,14 +20,17 @@
#include "base/memory/ptr_util.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/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/bindings/binding.h"
+#include "mojo/public/cpp/system/platform_handle.h"
#include "printing/emf_win.h"
#include "printing/pdf_render_settings.h"
+#include "services/service_manager/public/cpp/interface_provider.h"
#include "ui/base/l10n/l10n_util.h"
namespace printing {
@@ -102,7 +105,8 @@ class LazyEmf : public MetafilePlayer {
// All these steps work sequentially, so no data should be accessed
// simultaneously by several threads.
class PdfToEmfUtilityProcessHostClient
Sam McNally 2016/12/12 06:09:20 Consider using UtilityProcessMojoClient to abstrac
tibell 2016/12/13 23:41:54 Done.
- : public content::UtilityProcessHostClient {
+ : public content::UtilityProcessHostClient,
+ public mojom::FontPreCaching {
public:
PdfToEmfUtilityProcessHostClient(
base::WeakPtr<PdfToEmfConverterImpl> converter,
@@ -117,10 +121,6 @@ class PdfToEmfUtilityProcessHostClient
void Stop();
- // Needs to be public to handle ChromeUtilityHostMsg_PreCacheFontCharacters
- // sync message replies.
- bool Send(IPC::Message* msg);
-
// UtilityProcessHostClient implementation.
void OnProcessCrashed(int exit_code) override;
void OnProcessLaunchFailed(int exit_code) override;
@@ -164,8 +164,12 @@ class PdfToEmfUtilityProcessHostClient
// Message handlers.
void OnPageCount(int page_count);
void OnPageDone(bool success, float scale_factor);
- void OnPreCacheFontCharacters(const LOGFONT& log_font,
- const base::string16& characters);
+
+ // mojom::FontPreCaching:
+ void PreCacheFontCharacters(
+ const LOGFONT& log_font,
+ const base::string16& characters,
+ const PreCacheFontCharactersCallback& callback) override;
void OnFailed();
void OnTempPdfReady(bool print_text_with_gdi, ScopedTempFile pdf);
@@ -189,6 +193,11 @@ class PdfToEmfUtilityProcessHostClient
typedef std::queue<GetPageCallbackData> GetPageCallbacks;
GetPageCallbacks get_page_callbacks_;
+ mojom::PrintingPtr printing_;
+
+ // Interface that receives font precaching requests.
+ mojo::Binding<mojom::FontPreCaching> binding_;
+
DISALLOW_COPY_AND_ASSIGN(PdfToEmfUtilityProcessHostClient);
};
@@ -297,8 +306,7 @@ bool LazyEmf::LoadEmf(Emf* emf) const {
PdfToEmfUtilityProcessHostClient::PdfToEmfUtilityProcessHostClient(
base::WeakPtr<PdfToEmfConverterImpl> converter,
const PdfRenderSettings& settings)
- : converter_(converter), settings_(settings) {
-}
+ : converter_(converter), settings_(settings), binding_(this) {}
PdfToEmfUtilityProcessHostClient::~PdfToEmfUtilityProcessHostClient() {
}
@@ -326,6 +334,12 @@ void PdfToEmfUtilityProcessHostClient::Start(
->AsWeakPtr();
utility_process_host_->SetName(l10n_util::GetStringUTF16(
IDS_UTILITY_PROCESS_EMF_CONVERTOR_NAME));
+ utility_process_host_->Start();
+
+ mojom::PrintingFactoryPtr printing_factory;
+ utility_process_host_->GetRemoteInterfaces()->GetInterface(&printing_factory);
+ printing_factory->MakePrinting(mojo::GetProxy(&printing_),
+ binding_.CreateInterfacePtrAndBind());
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::FILE, FROM_HERE,
@@ -339,10 +353,11 @@ void PdfToEmfUtilityProcessHostClient::OnTempPdfReady(bool print_text_with_gdi,
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!utility_process_host_ || !pdf)
return OnFailed();
- // Should reply with OnPageCount().
- Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles(
- IPC::GetPlatformFileForTransit(pdf->GetPlatformFile(), false), settings_,
- print_text_with_gdi));
+ printing_->RenderPDFPagesToMetafiles(
+ mojo::WrapPlatformFile(pdf->GetPlatformFile()), settings_,
+ print_text_with_gdi,
+ base::Bind(&PdfToEmfUtilityProcessHostClient::OnPageCount,
+ base::Unretained(this)));
}
void PdfToEmfUtilityProcessHostClient::OnPageCount(int page_count) {
@@ -392,12 +407,12 @@ void PdfToEmfUtilityProcessHostClient::OnTempEmfReady(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!utility_process_host_ || !emf)
return OnFailed();
- IPC::PlatformFileForTransit transit =
- IPC::GetPlatformFileForTransit(emf->GetPlatformFile(), false);
callback_data->set_emf(std::move(emf));
- // Should reply with OnPageDone().
- Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage(
- callback_data->page_number(), transit));
+ printing_->RenderPDFPagesToMetafilesGetPage(
+ callback_data->page_number(),
+ mojo::WrapPlatformFile(emf->GetPlatformFile()),
+ base::Bind(&PdfToEmfUtilityProcessHostClient::OnPageDone,
+ base::Unretained(this)));
}
void PdfToEmfUtilityProcessHostClient::OnPageDone(bool success,
@@ -426,9 +441,10 @@ void PdfToEmfUtilityProcessHostClient::OnPageDone(bool success,
get_page_callbacks_.pop();
}
-void PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters(
+void PdfToEmfUtilityProcessHostClient::PreCacheFontCharacters(
const LOGFONT& font,
- const base::string16& str) {
+ const base::string16& str,
+ const PreCacheFontCharactersCallback& callback) {
// TODO(scottmg): pdf/ppapi still require the renderer to be able to precache
// GDI fonts (http://crbug.com/383227), even when using DirectWrite.
// Eventually this shouldn't be added and should be moved to
@@ -456,6 +472,7 @@ void PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters(
if (metafile)
DeleteEnhMetaFile(metafile);
+ callback.Run();
}
void PdfToEmfUtilityProcessHostClient::Stop() {
@@ -466,7 +483,7 @@ void PdfToEmfUtilityProcessHostClient::Stop() {
base::Bind(&PdfToEmfUtilityProcessHostClient::Stop, this));
return;
}
- Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop());
+ printing_->RenderPDFPagesToMetafilesStop();
}
void PdfToEmfUtilityProcessHostClient::OnProcessCrashed(int exit_code) {
@@ -479,23 +496,6 @@ void PdfToEmfUtilityProcessHostClient::OnProcessLaunchFailed(int exit_code) {
bool PdfToEmfUtilityProcessHostClient::OnMessageReceived(
const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(PdfToEmfUtilityProcessHostClient, message)
- IPC_MESSAGE_HANDLER(
- ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, OnPageCount)
- IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone,
- OnPageDone)
- IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PreCacheFontCharacters,
- OnPreCacheFontCharacters)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-bool PdfToEmfUtilityProcessHostClient::Send(IPC::Message* msg) {
- if (utility_process_host_)
- return utility_process_host_->Send(msg);
- delete msg;
return false;
}

Powered by Google App Engine
This is Rietveld 408576698