Commit 6c35041e authored by Jay Civelli's avatar Jay Civelli Committed by Commit Bot

Servicifying PdfToEmfConverter.

Moving the PdfToEmfConverter interface to the printing service.
As a result, simplified the client of that interface in
chrome/browser/printing/pdf_to_emf_converter.cc:
- merging PdfConverterUtilityProcessHostClient and PdfConverterImpl.
- calls on the service can now happen on the UI thread instead of the
  IO thread

Renamed the mojom::PdfToEmfConverter implementation from
PdfToEmfConverterImpl to PdfToEmfConverter as is now preferred naming
style for Mojo interface implementation.

Bug: 766451
Change-Id: Ic748547f56bb193a558210f97558640ef8d6e44b
Reviewed-on: https://chromium-review.googlesource.com/826308Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Jay Civelli <jcivelli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524534}
parent a834c680
...@@ -3271,6 +3271,7 @@ split_static_library("browser") { ...@@ -3271,6 +3271,7 @@ split_static_library("browser") {
"printing/pdf_to_emf_converter.cc", "printing/pdf_to_emf_converter.cc",
"printing/pdf_to_emf_converter.h", "printing/pdf_to_emf_converter.h",
] ]
deps += [ "//chrome/services/printing/public/interfaces" ]
} }
if (enable_print_preview) { if (enable_print_preview) {
# Full printing on top of the above. # Full printing on top of the above.
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/callback.h"
#include "base/containers/queue.h" #include "base/containers/queue.h"
#include "base/files/file.h" #include "base/files/file.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
...@@ -24,18 +25,16 @@ ...@@ -24,18 +25,16 @@
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/common/chrome_utility_printing_messages.h" #include "chrome/services/printing/public/interfaces/constants.mojom.h"
#include "chrome/common/printing/pdf_to_emf_converter.mojom.h" #include "chrome/services/printing/public/interfaces/pdf_to_emf_converter.mojom.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h" #include "content/public/browser/child_process_data.h"
#include "content/public/browser/utility_process_host.h" #include "content/public/common/service_manager_connection.h"
#include "content/public/browser/utility_process_host_client.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/system/platform_handle.h" #include "mojo/public/cpp/system/platform_handle.h"
#include "printing/emf_win.h" #include "printing/emf_win.h"
#include "printing/pdf_render_settings.h" #include "printing/pdf_render_settings.h"
#include "ui/base/l10n/l10n_util.h" #include "services/service_manager/public/cpp/connector.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -43,8 +42,6 @@ namespace printing { ...@@ -43,8 +42,6 @@ namespace printing {
namespace { namespace {
class PdfConverterImpl;
void CloseFileOnBlockingTaskRunner(base::File temp_file) { void CloseFileOnBlockingTaskRunner(base::File temp_file) {
base::AssertBlockingAllowed(); base::AssertBlockingAllowed();
temp_file.Close(); temp_file.Close();
...@@ -194,36 +191,25 @@ class PostScriptMetaFile : public LazyEmf { ...@@ -194,36 +191,25 @@ class PostScriptMetaFile : public LazyEmf {
}; };
// Class for converting PDF to another format for printing (Emf, Postscript). // Class for converting PDF to another format for printing (Emf, Postscript).
// Class uses UI thread, IO thread and |blocking_task_runner_|. // Class uses UI thread and |blocking_task_runner_|.
// Internal workflow is following: // Internal workflow is following:
// 1. Create instance on the UI thread. (files_, settings_,) // 1. Create instance on the UI thread. (files_, settings_,)
// 2. Create pdf file on |blocking_task_runner_|. // 2. Create pdf file on |blocking_task_runner_|.
// 3. Start utility process and start conversion on the IO thread. // 3. Bind to printing service and start conversion on the UI thread (mojo
// 4. Utility process returns page count. // actually makes that happen transparently on the IO thread).
// 4. Printing service returns page count.
// 5. For each page: // 5. For each page:
// 1. Clients requests page with file handle to a temp file. // 1. Clients requests page with file handle to a temp file.
// 2. Utility converts the page, save it to the file and reply. // 2. Utility converts the page, save it to the file and reply.
// //
// All these steps work sequentially, so no data should be accessed // All these steps work sequentially, so no data should be accessed
// simultaneously by several threads. // simultaneously by several threads.
class PdfConverterUtilityProcessHostClient class PdfConverterImpl : public PdfConverter {
: public content::UtilityProcessHostClient {
public: public:
PdfConverterUtilityProcessHostClient( PdfConverterImpl(const scoped_refptr<base::RefCountedMemory>& data,
base::WeakPtr<PdfConverterImpl> converter, const PdfRenderSettings& conversion_settings,
const PdfRenderSettings& settings); StartCallback start_callback);
~PdfConverterImpl() override;
void Start(const scoped_refptr<base::RefCountedMemory>& data,
PdfConverter::StartCallback start_callback);
void GetPage(int page_number,
const PdfConverter::GetPageCallback& get_page_callback);
void Stop();
// UtilityProcessHostClient implementation.
void OnProcessCrashed(int exit_code) override;
void OnProcessLaunchFailed(int exit_code) override;
private: private:
class GetPageCallbackData { class GetPageCallbackData {
...@@ -243,8 +229,11 @@ class PdfConverterUtilityProcessHostClient ...@@ -243,8 +229,11 @@ class PdfConverterUtilityProcessHostClient
} }
int page_number() const { return page_number_; } int page_number() const { return page_number_; }
const PdfConverter::GetPageCallback& callback() const { return callback_; } const PdfConverter::GetPageCallback& callback() const { return callback_; }
ScopedTempFile TakeFile() { return std::move(file_); } ScopedTempFile TakeFile() { return std::move(file_); }
void set_file(ScopedTempFile file) { file_ = std::move(file); } void set_file(ScopedTempFile file) { file_ = std::move(file); }
private: private:
...@@ -256,20 +245,16 @@ class PdfConverterUtilityProcessHostClient ...@@ -256,20 +245,16 @@ class PdfConverterUtilityProcessHostClient
DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData); DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData);
}; };
~PdfConverterUtilityProcessHostClient() override; void GetPage(int page_number,
const PdfConverter::GetPageCallback& get_page_callback) override;
bool OnMessageReceived(const IPC::Message& message) override; void Stop();
// Helper functions: must be overridden by subclasses // Helper functions: must be overridden by subclasses
// Set the process name
base::string16 GetName() const;
// Create a metafileplayer subclass file from a temporary file. // Create a metafileplayer subclass file from a temporary file.
std::unique_ptr<MetafilePlayer> GetFileFromTemp(ScopedTempFile temp_file); std::unique_ptr<MetafilePlayer> GetFileFromTemp(ScopedTempFile temp_file);
// Message handlers: void OnPageCount(mojom::PdfToEmfConverterPtr converter, uint32_t page_count);
void OnPageCount(mojom::PdfToEmfConverterFactoryPtr factory_keep_alive,
mojom::PdfToEmfConverterPtr converter,
uint32_t page_count);
void OnPageDone(bool success, float scale_factor); void OnPageDone(bool success, float scale_factor);
void OnFailed(const std::string& error_message); void OnFailed(const std::string& error_message);
...@@ -283,16 +268,11 @@ class PdfConverterUtilityProcessHostClient ...@@ -283,16 +268,11 @@ class PdfConverterUtilityProcessHostClient
scoped_refptr<RefCountedTempDir> temp_dir_; scoped_refptr<RefCountedTempDir> temp_dir_;
// Used to suppress callbacks after PdfConverter is deleted.
base::WeakPtr<PdfConverterImpl> converter_;
PdfRenderSettings settings_; PdfRenderSettings settings_;
// Document loaded callback. // Document loaded callback.
PdfConverter::StartCallback start_callback_; PdfConverter::StartCallback start_callback_;
// Process host for IPC.
base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
// Queue of callbacks for GetPage() requests. Utility process should reply // Queue of callbacks for GetPage() requests. Utility process should reply
// with PageDone in the same order as requests were received. // with PageDone in the same order as requests were received.
// Use containers that keeps element pointers valid after push() and pop(). // Use containers that keeps element pointers valid after push() and pop().
...@@ -306,54 +286,24 @@ class PdfConverterUtilityProcessHostClient ...@@ -306,54 +286,24 @@ class PdfConverterUtilityProcessHostClient
mojom::PdfToEmfConverterPtr pdf_to_emf_converter_; mojom::PdfToEmfConverterPtr pdf_to_emf_converter_;
DISALLOW_COPY_AND_ASSIGN(PdfConverterUtilityProcessHostClient); mojom::PdfToEmfConverterFactoryPtr pdf_to_emf_converter_factory_;
base::WeakPtrFactory<PdfConverterImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PdfConverterImpl);
}; };
std::unique_ptr<MetafilePlayer> std::unique_ptr<MetafilePlayer> PdfConverterImpl::GetFileFromTemp(
PdfConverterUtilityProcessHostClient::GetFileFromTemp(
ScopedTempFile temp_file) { ScopedTempFile temp_file) {
if (settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 || if (settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 ||
settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3 || settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3 ||
settings_.mode == PdfRenderSettings::Mode::TEXTONLY) { settings_.mode == PdfRenderSettings::Mode::TEXTONLY) {
return base::MakeUnique<PostScriptMetaFile>(temp_dir_, return std::make_unique<PostScriptMetaFile>(temp_dir_,
std::move(temp_file)); std::move(temp_file));
} }
return base::MakeUnique<LazyEmf>(temp_dir_, std::move(temp_file)); return std::make_unique<LazyEmf>(temp_dir_, std::move(temp_file));
} }
class PdfConverterImpl : public PdfConverter {
public:
PdfConverterImpl();
~PdfConverterImpl() override;
base::WeakPtr<PdfConverterImpl> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
void Start(const scoped_refptr<base::RefCountedMemory>& data,
const PdfRenderSettings& conversion_settings,
StartCallback start_callback);
void GetPage(int page_number,
const GetPageCallback& get_page_callback) override;
// Helps to cancel callbacks if this object is destroyed.
void RunCallback(base::OnceClosure callback);
void Start(
const scoped_refptr<PdfConverterUtilityProcessHostClient>& utility_client,
const scoped_refptr<base::RefCountedMemory>& data,
StartCallback start_callback);
private:
scoped_refptr<PdfConverterUtilityProcessHostClient> utility_client_;
base::WeakPtrFactory<PdfConverterImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PdfConverterImpl);
};
ScopedTempFile CreateTempFile(scoped_refptr<RefCountedTempDir>* temp_dir) { ScopedTempFile CreateTempFile(scoped_refptr<RefCountedTempDir>* temp_dir) {
if (!temp_dir->get()) if (!temp_dir->get())
*temp_dir = base::MakeRefCounted<RefCountedTempDir>(); *temp_dir = base::MakeRefCounted<RefCountedTempDir>();
...@@ -366,7 +316,7 @@ ScopedTempFile CreateTempFile(scoped_refptr<RefCountedTempDir>* temp_dir) { ...@@ -366,7 +316,7 @@ ScopedTempFile CreateTempFile(scoped_refptr<RefCountedTempDir>* temp_dir) {
<< (*temp_dir)->GetPath().value(); << (*temp_dir)->GetPath().value();
return file; return file;
} }
file = base::MakeUnique<TempFile>(base::File( file = std::make_unique<TempFile>(base::File(
path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
base::File::FLAG_READ | base::File::FLAG_DELETE_ON_CLOSE | base::File::FLAG_READ | base::File::FLAG_DELETE_ON_CLOSE |
base::File::FLAG_TEMPORARY)); base::File::FLAG_TEMPORARY));
...@@ -462,59 +412,39 @@ bool PostScriptMetaFile::SafePlayback(HDC hdc) const { ...@@ -462,59 +412,39 @@ bool PostScriptMetaFile::SafePlayback(HDC hdc) const {
return true; return true;
} }
PdfConverterUtilityProcessHostClient::PdfConverterUtilityProcessHostClient( PdfConverterImpl::PdfConverterImpl(
base::WeakPtr<PdfConverterImpl> converter, const scoped_refptr<base::RefCountedMemory>& data,
const PdfRenderSettings& settings) const PdfRenderSettings& settings,
: converter_(converter), StartCallback start_callback)
settings_(settings), : settings_(settings),
start_callback_(std::move(start_callback)),
blocking_task_runner_(base::CreateSequencedTaskRunnerWithTraits( blocking_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN})) {} base::TaskShutdownBehavior::BLOCK_SHUTDOWN})),
weak_ptr_factory_(this) {
PdfConverterUtilityProcessHostClient::~PdfConverterUtilityProcessHostClient() {} DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(start_callback_);
void PdfConverterUtilityProcessHostClient::Start(
const scoped_refptr<base::RefCountedMemory>& data,
PdfConverter::StartCallback start_callback) {
if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&PdfConverterUtilityProcessHostClient::Start, this, data,
std::move(start_callback)));
return;
}
// Store callback before any OnFailed() call to make it called on failure.
DCHECK(start_callback);
start_callback_ = std::move(start_callback);
// NOTE: This process _must_ be sandboxed, otherwise the pdf dll will load
// gdiplus.dll, change how rendering happens, and not be able to correctly
// generate when sent to a metafile DC.
utility_process_host_ = content::UtilityProcessHost::Create(
this, base::ThreadTaskRunnerHandle::Get())
->AsWeakPtr();
utility_process_host_->SetName(GetName());
utility_process_host_->Start();
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(), FROM_HERE, blocking_task_runner_.get(), FROM_HERE,
base::Bind(&CreateTempPdfFile, data, &temp_dir_), base::BindOnce(&CreateTempPdfFile, data, &temp_dir_),
base::Bind(&PdfConverterUtilityProcessHostClient::OnTempPdfReady, this)); base::BindOnce(&PdfConverterImpl::OnTempPdfReady,
weak_ptr_factory_.GetWeakPtr()));
} }
void PdfConverterUtilityProcessHostClient::OnTempPdfReady(ScopedTempFile pdf) { PdfConverterImpl::~PdfConverterImpl() {}
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!utility_process_host_ || !pdf)
return OnFailed(std::string("Failed to create temporary PDF file."));
mojom::PdfToEmfConverterFactoryPtr pdf_to_emf_converter_factory_ptr; void PdfConverterImpl::OnTempPdfReady(ScopedTempFile pdf) {
utility_process_host_->BindInterface( DCHECK_CURRENTLY_ON(BrowserThread::UI);
mojom::PdfToEmfConverterFactory::Name_, if (!pdf)
mojo::MakeRequest(&pdf_to_emf_converter_factory_ptr).PassMessagePipe()); return OnFailed(std::string("Failed to create temporary PDF file."));
pdf_to_emf_converter_factory_ptr.set_connection_error_handler(base::BindOnce( content::ServiceManagerConnection::GetForProcess()
&PdfConverterUtilityProcessHostClient::OnFailed, this, ->GetConnector()
->BindInterface(printing::mojom::kChromePrintingServiceName,
&pdf_to_emf_converter_factory_);
pdf_to_emf_converter_factory_.set_connection_error_handler(base::BindOnce(
&PdfConverterImpl::OnFailed, weak_ptr_factory_.GetWeakPtr(),
std::string("Connection to PdfToEmfConverterFactory error."))); std::string("Connection to PdfToEmfConverterFactory error.")));
mojom::PdfToEmfConverterClientPtr pdf_to_emf_converter_client_ptr; mojom::PdfToEmfConverterClientPtr pdf_to_emf_converter_client_ptr;
...@@ -522,59 +452,49 @@ void PdfConverterUtilityProcessHostClient::OnTempPdfReady(ScopedTempFile pdf) { ...@@ -522,59 +452,49 @@ void PdfConverterUtilityProcessHostClient::OnTempPdfReady(ScopedTempFile pdf) {
std::make_unique<PdfToEmfConverterClientImpl>( std::make_unique<PdfToEmfConverterClientImpl>(
mojo::MakeRequest(&pdf_to_emf_converter_client_ptr)); mojo::MakeRequest(&pdf_to_emf_converter_client_ptr));
pdf_to_emf_converter_factory_ptr->CreateConverter( pdf_to_emf_converter_factory_->CreateConverter(
mojo::WrapPlatformFile(pdf->file().TakePlatformFile()), settings_, mojo::WrapPlatformFile(pdf->file().TakePlatformFile()), settings_,
std::move(pdf_to_emf_converter_client_ptr), std::move(pdf_to_emf_converter_client_ptr),
base::BindOnce(&PdfConverterUtilityProcessHostClient::OnPageCount, this, base::BindOnce(&PdfConverterImpl::OnPageCount,
std::move(pdf_to_emf_converter_factory_ptr))); weak_ptr_factory_.GetWeakPtr()));
} }
void PdfConverterUtilityProcessHostClient::OnPageCount( void PdfConverterImpl::OnPageCount(mojom::PdfToEmfConverterPtr converter,
mojom::PdfToEmfConverterFactoryPtr factory_keep_alive,
mojom::PdfToEmfConverterPtr converter,
uint32_t page_count) { uint32_t page_count) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!pdf_to_emf_converter_.is_bound()); DCHECK(!pdf_to_emf_converter_.is_bound());
pdf_to_emf_converter_ = std::move(converter); pdf_to_emf_converter_ = std::move(converter);
pdf_to_emf_converter_.set_connection_error_handler(base::BindOnce(
BrowserThread::PostTask( &PdfConverterImpl::OnFailed, weak_ptr_factory_.GetWeakPtr(),
BrowserThread::UI, FROM_HERE, std::string("Connection to PdfToEmfConverter error.")));
base::BindOnce(&PdfConverterImpl::RunCallback, converter_, std::move(start_callback_).Run(page_count);
base::BindOnce(std::move(start_callback_), page_count)));
} }
void PdfConverterUtilityProcessHostClient::GetPage( void PdfConverterImpl::GetPage(
int page_number, int page_number,
const PdfConverter::GetPageCallback& get_page_callback) { const PdfConverter::GetPageCallback& get_page_callback) {
if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&PdfConverterUtilityProcessHostClient::GetPage, this,
page_number, get_page_callback));
return;
}
// Store callback before any OnFailed() call to make it called on failure. // Store callback before any OnFailed() call to make it called on failure.
get_page_callbacks_.push(GetPageCallbackData(page_number, get_page_callback)); get_page_callbacks_.push(GetPageCallbackData(page_number, get_page_callback));
if (!utility_process_host_) if (!pdf_to_emf_converter_)
return OnFailed(std::string("No process utility host.")); return OnFailed(std::string("No PdfToEmfConverter."));
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
blocking_task_runner_.get(), FROM_HERE, blocking_task_runner_.get(), FROM_HERE,
base::Bind(&CreateTempFile, &temp_dir_), base::BindOnce(&CreateTempFile, &temp_dir_),
base::Bind(&PdfConverterUtilityProcessHostClient::OnTempFileReady, this, base::BindOnce(&PdfConverterImpl::OnTempFileReady,
weak_ptr_factory_.GetWeakPtr(),
&get_page_callbacks_.back())); &get_page_callbacks_.back()));
} }
void PdfConverterUtilityProcessHostClient::OnTempFileReady( void PdfConverterImpl::OnTempFileReady(GetPageCallbackData* callback_data,
GetPageCallbackData* callback_data,
ScopedTempFile temp_file) { ScopedTempFile temp_file) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(pdf_to_emf_converter_.is_bound()); DCHECK(pdf_to_emf_converter_.is_bound());
if (!utility_process_host_ || !temp_file) if (!pdf_to_emf_converter_ || !temp_file)
return OnFailed(std::string("Error creating utility process host")); return OnFailed(std::string("Error connecting to printing service."));
// We need to dup the file as mojo::WrapPlatformFile takes ownership of the // We need to dup the file as mojo::WrapPlatformFile takes ownership of the
// passed file. // passed file.
...@@ -582,13 +502,13 @@ void PdfConverterUtilityProcessHostClient::OnTempFileReady( ...@@ -582,13 +502,13 @@ void PdfConverterUtilityProcessHostClient::OnTempFileReady(
pdf_to_emf_converter_->ConvertPage( pdf_to_emf_converter_->ConvertPage(
callback_data->page_number(), callback_data->page_number(),
mojo::WrapPlatformFile(temp_file_copy.TakePlatformFile()), mojo::WrapPlatformFile(temp_file_copy.TakePlatformFile()),
base::BindOnce(&PdfConverterUtilityProcessHostClient::OnPageDone, this)); base::BindOnce(&PdfConverterImpl::OnPageDone,
weak_ptr_factory_.GetWeakPtr()));
callback_data->set_file(std::move(temp_file)); callback_data->set_file(std::move(temp_file));
} }
void PdfConverterUtilityProcessHostClient::OnPageDone(bool success, void PdfConverterImpl::OnPageDone(bool success, float scale_factor) {
float scale_factor) { DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (get_page_callbacks_.empty()) if (get_page_callbacks_.empty())
return OnFailed(std::string("No get_page callbacks.")); return OnFailed(std::string("No get_page callbacks."));
GetPageCallbackData& data = get_page_callbacks_.front(); GetPageCallbackData& data = get_page_callbacks_.front();
...@@ -596,61 +516,34 @@ void PdfConverterUtilityProcessHostClient::OnPageDone(bool success, ...@@ -596,61 +516,34 @@ void PdfConverterUtilityProcessHostClient::OnPageDone(bool success,
if (success) { if (success) {
ScopedTempFile temp_file = data.TakeFile(); ScopedTempFile temp_file = data.TakeFile();
if (!temp_file) // Unexpected message from utility process. if (!temp_file) // Unexpected message from printing service.
return OnFailed("No temp file."); return OnFailed("No temp file.");
file = GetFileFromTemp(std::move(temp_file)); file = GetFileFromTemp(std::move(temp_file));
} }
BrowserThread::PostTask( data.callback().Run(data.page_number(), scale_factor, std::move(file));
BrowserThread::UI, FROM_HERE,
base::Bind(&PdfConverterImpl::RunCallback, converter_,
base::BindRepeating(data.callback(), data.page_number(),
scale_factor, base::Passed(&file))));
get_page_callbacks_.pop(); get_page_callbacks_.pop();
} }
void PdfConverterUtilityProcessHostClient::Stop() { void PdfConverterImpl::Stop() {
if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask( // Disconnect interface ptrs so that the printing service process stop.
BrowserThread::IO, FROM_HERE, pdf_to_emf_converter_factory_.reset();
base::Bind(&PdfConverterUtilityProcessHostClient::Stop, this));
return;
}
pdf_to_emf_converter_.reset(); pdf_to_emf_converter_.reset();
// Once this becomes a Mojo service, simply disconnecting
// pdf_to_emf_converter_ above will lead to the utility process stopping.
// In the meantime we need to explictly terminate it.
if (utility_process_host_) {
utility_process_host_->Send(
new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop());
}
}
void PdfConverterUtilityProcessHostClient::OnProcessCrashed(int exit_code) {
OnFailed("Utility process host crashed.");
} }
void PdfConverterUtilityProcessHostClient::OnProcessLaunchFailed( void PdfConverterImpl::OnFailed(const std::string& error_message) {
int exit_code) { DCHECK_CURRENTLY_ON(BrowserThread::UI);
OnFailed("Process launch failed");
}
void PdfConverterUtilityProcessHostClient::OnFailed(
const std::string& error_message) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
LOG(ERROR) << "Failed to convert PDF: " << error_message; LOG(ERROR) << "Failed to convert PDF: " << error_message;
if (!start_callback_.is_null()) { if (!start_callback_.is_null()) {
OnPageCount(mojom::PdfToEmfConverterFactoryPtr(), OnPageCount(mojom::PdfToEmfConverterPtr(), 0);
mojom::PdfToEmfConverterPtr(), 0);
} }
while (!get_page_callbacks_.empty()) while (!get_page_callbacks_.empty())
OnPageDone(false, 0.0f); OnPageDone(false, 0.0f);
utility_process_host_.reset(); Stop();
} }
void PdfConverterImpl::OnPreCacheFontCharacters(const LOGFONT& font,
void PdfConverterUtilityProcessHostClient::OnPreCacheFontCharacters(
const LOGFONT& font,
const base::string16& str) { const base::string16& str) {
// TODO(scottmg): pdf/ppapi still require the renderer to be able to precache // TODO(scottmg): pdf/ppapi still require the renderer to be able to precache
// GDI fonts (http://crbug.com/383227), even when using DirectWrite. // GDI fonts (http://crbug.com/383227), even when using DirectWrite.
...@@ -681,57 +574,17 @@ void PdfConverterUtilityProcessHostClient::OnPreCacheFontCharacters( ...@@ -681,57 +574,17 @@ void PdfConverterUtilityProcessHostClient::OnPreCacheFontCharacters(
DeleteEnhMetaFile(metafile); DeleteEnhMetaFile(metafile);
} }
bool PdfConverterUtilityProcessHostClient::OnMessageReceived(
const IPC::Message& message) {
return false;
}
base::string16 PdfConverterUtilityProcessHostClient::GetName() const {
return l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PDF_CONVERTOR_NAME);
}
// Pdf Converter Impl and subclasses
PdfConverterImpl::PdfConverterImpl() : weak_ptr_factory_(this) {}
PdfConverterImpl::~PdfConverterImpl() {
if (utility_client_.get())
utility_client_->Stop();
}
void PdfConverterImpl::Start(
const scoped_refptr<PdfConverterUtilityProcessHostClient>& utility_client,
const scoped_refptr<base::RefCountedMemory>& data,
StartCallback start_callback) {
DCHECK(!utility_client_);
utility_client_ = utility_client;
utility_client_->Start(data, std::move(start_callback));
}
void PdfConverterImpl::GetPage(int page_number,
const GetPageCallback& get_page_callback) {
utility_client_->GetPage(page_number, get_page_callback);
}
void PdfConverterImpl::RunCallback(base::OnceClosure callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::move(callback).Run();
}
} // namespace } // namespace
PdfConverter::~PdfConverter() {} PdfConverter::~PdfConverter() = default;
// static // static
std::unique_ptr<PdfConverter> PdfConverter::StartPdfConverter( std::unique_ptr<PdfConverter> PdfConverter::StartPdfConverter(
const scoped_refptr<base::RefCountedMemory>& data, const scoped_refptr<base::RefCountedMemory>& data,
const PdfRenderSettings& conversion_settings, const PdfRenderSettings& conversion_settings,
StartCallback start_callback) { StartCallback start_callback) {
std::unique_ptr<PdfConverterImpl> converter = return std::make_unique<PdfConverterImpl>(data, conversion_settings,
base::MakeUnique<PdfConverterImpl>(); std::move(start_callback));
converter->Start(new PdfConverterUtilityProcessHostClient(
converter->GetWeakPtr(), conversion_settings),
data, std::move(start_callback));
return std::move(converter);
} }
} // namespace printing } // namespace printing
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <memory> #include <memory>
#include "base/callback.h" #include "base/callback_forward.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
namespace printing { namespace printing {
......
...@@ -275,7 +275,7 @@ void PrintJob::StartPdfToEmfConversion( ...@@ -275,7 +275,7 @@ void PrintJob::StartPdfToEmfConversion(
print_text_with_gdi ? PdfRenderSettings::Mode::GDI_TEXT print_text_with_gdi ? PdfRenderSettings::Mode::GDI_TEXT
: PdfRenderSettings::Mode::NORMAL); : PdfRenderSettings::Mode::NORMAL);
pdf_conversion_state_->Start( pdf_conversion_state_->Start(
bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); bytes, settings, base::BindOnce(&PrintJob::OnPdfConversionStarted, this));
} }
void PrintJob::OnPdfConversionStarted(int page_count) { void PrintJob::OnPdfConversionStarted(int page_count) {
...@@ -321,7 +321,7 @@ void PrintJob::StartPdfToTextConversion( ...@@ -321,7 +321,7 @@ void PrintJob::StartPdfToTextConversion(
/*autorotate=*/true, /*autorotate=*/true,
PdfRenderSettings::Mode::TEXTONLY); PdfRenderSettings::Mode::TEXTONLY);
pdf_conversion_state_->Start( pdf_conversion_state_->Start(
bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); bytes, settings, base::BindOnce(&PrintJob::OnPdfConversionStarted, this));
} }
void PrintJob::StartPdfToPostScriptConversion( void PrintJob::StartPdfToPostScriptConversion(
...@@ -338,7 +338,7 @@ void PrintJob::StartPdfToPostScriptConversion( ...@@ -338,7 +338,7 @@ void PrintJob::StartPdfToPostScriptConversion(
ps_level2 ? PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 ps_level2 ? PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2
: PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3); : PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3);
pdf_conversion_state_->Start( pdf_conversion_state_->Start(
bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); bytes, settings, base::BindOnce(&PrintJob::OnPdfConversionStarted, this));
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
......
...@@ -213,7 +213,6 @@ static_library("common") { ...@@ -213,7 +213,6 @@ static_library("common") {
"//chrome/app/theme:theme_resources", "//chrome/app/theme:theme_resources",
"//chrome/common:constants", "//chrome/common:constants",
"//chrome/common/net", "//chrome/common/net",
"//chrome/common/printing:interfaces",
"//chrome/common/profiling", "//chrome/common/profiling",
"//chrome/installer/util:with_no_strings", "//chrome/installer/util:with_no_strings",
"//components/cast_certificate", "//components/cast_certificate",
......
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
"pdf_to_emf_converter.mojom",
]
deps = [
"//chrome/services/printing/public/interfaces",
"//mojo/common:common_custom_types",
"//ui/gfx/geometry/mojo",
]
}
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
...@@ -22,6 +22,17 @@ source_set("lib") { ...@@ -22,6 +22,17 @@ source_set("lib") {
"//chrome/services/printing/public/interfaces", "//chrome/services/printing/public/interfaces",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
] ]
if (is_win) {
sources += [
"pdf_to_emf_converter.cc",
"pdf_to_emf_converter.h",
"pdf_to_emf_converter_factory.cc",
"pdf_to_emf_converter_factory.h",
]
deps += [ "//skia" ]
}
} }
service_manifest("manifest") { service_manifest("manifest") {
......
{ {
"name": "chrome_printing", "name": "chrome_printing",
"display_name": "Printing", "display_name": "Printing",
"sandbox_type": "utility",
"interface_provider_specs": { "interface_provider_specs": {
"service_manager:connector": { "service_manager:connector": {
"provides": { "provides": {
"converter": [ "printing::mojom::PdfToPwgRasterConverter" ] "converter": [
"printing::mojom::PdfToEmfConverterFactory",
"printing::mojom::PdfToPwgRasterConverter" ]
}, },
"requires": { "requires": {
"service_manager": [ "service_manager:all_users" ] "service_manager": [ "service_manager:all_users" ]
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/utility/printing/pdf_to_emf_converter_impl.h" #include "chrome/services/printing/pdf_to_emf_converter.h"
#include <algorithm> #include <algorithm>
...@@ -61,7 +61,7 @@ void RegisterConverterClient(mojom::PdfToEmfConverterClientPtr client) { ...@@ -61,7 +61,7 @@ void RegisterConverterClient(mojom::PdfToEmfConverterClientPtr client) {
} // namespace } // namespace
PdfToEmfConverterImpl::PdfToEmfConverterImpl( PdfToEmfConverter::PdfToEmfConverter(
mojo::ScopedHandle pdf_file_in, mojo::ScopedHandle pdf_file_in,
const printing::PdfRenderSettings& pdf_render_settings, const printing::PdfRenderSettings& pdf_render_settings,
mojom::PdfToEmfConverterClientPtr client) mojom::PdfToEmfConverterClientPtr client)
...@@ -90,15 +90,15 @@ PdfToEmfConverterImpl::PdfToEmfConverterImpl( ...@@ -90,15 +90,15 @@ PdfToEmfConverterImpl::PdfToEmfConverterImpl(
base::PlatformFile pdf_file; base::PlatformFile pdf_file;
if (mojo::UnwrapPlatformFile(std::move(pdf_file_in), &pdf_file) != if (mojo::UnwrapPlatformFile(std::move(pdf_file_in), &pdf_file) !=
MOJO_RESULT_OK) { MOJO_RESULT_OK) {
LOG(ERROR) << "Invalid PDF file passed to PdfToEmfConverterImpl"; LOG(ERROR) << "Invalid PDF file passed to PdfToEmfConverter.";
return; return;
} }
LoadPdf(base::File(pdf_file)); LoadPdf(base::File(pdf_file));
} }
PdfToEmfConverterImpl::~PdfToEmfConverterImpl() = default; PdfToEmfConverter::~PdfToEmfConverter() = default;
void PdfToEmfConverterImpl::LoadPdf(base::File pdf_file) { void PdfToEmfConverter::LoadPdf(base::File pdf_file) {
int64_t length64 = pdf_file.GetLength(); int64_t length64 = pdf_file.GetLength();
if (length64 <= 0 || length64 > std::numeric_limits<int>::max()) if (length64 <= 0 || length64 > std::numeric_limits<int>::max())
return; return;
...@@ -114,7 +114,7 @@ void PdfToEmfConverterImpl::LoadPdf(base::File pdf_file) { ...@@ -114,7 +114,7 @@ void PdfToEmfConverterImpl::LoadPdf(base::File pdf_file) {
total_page_count_ = page_count; total_page_count_ = page_count;
} }
bool PdfToEmfConverterImpl::RenderPdfPageToMetafile(int page_number, bool PdfToEmfConverter::RenderPdfPageToMetafile(int page_number,
base::File output_file, base::File output_file,
float* scale_factor, float* scale_factor,
bool postscript) { bool postscript) {
...@@ -160,7 +160,7 @@ bool PdfToEmfConverterImpl::RenderPdfPageToMetafile(int page_number, ...@@ -160,7 +160,7 @@ bool PdfToEmfConverterImpl::RenderPdfPageToMetafile(int page_number,
return metafile.SaveTo(&output_file); return metafile.SaveTo(&output_file);
} }
void PdfToEmfConverterImpl::ConvertPage(uint32_t page_number, void PdfToEmfConverter::ConvertPage(uint32_t page_number,
mojo::ScopedHandle emf_file_out, mojo::ScopedHandle emf_file_out,
ConvertPageCallback callback) { ConvertPageCallback callback) {
if (page_number >= total_page_count_) { if (page_number >= total_page_count_) {
......
...@@ -2,24 +2,24 @@ ...@@ -2,24 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_UTILITY_PRINTING_PDF_TO_EMF_CONVERTER_IMPL_H_ #ifndef CHROME_SERVICES_PRINTING_PDF_TO_EMF_CONVERTER_H_
#define CHROME_UTILITY_PRINTING_PDF_TO_EMF_CONVERTER_IMPL_H_ #define CHROME_SERVICES_PRINTING_PDF_TO_EMF_CONVERTER_H_
#include <vector> #include <vector>
#include "base/files/file.h" #include "base/files/file.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/common/printing/pdf_to_emf_converter.mojom.h" #include "chrome/services/printing/public/interfaces/pdf_to_emf_converter.mojom.h"
#include "printing/pdf_render_settings.h" #include "printing/pdf_render_settings.h"
namespace printing { namespace printing {
class PdfToEmfConverterImpl : public mojom::PdfToEmfConverter { class PdfToEmfConverter : public mojom::PdfToEmfConverter {
public: public:
PdfToEmfConverterImpl(mojo::ScopedHandle pdf_file_in, PdfToEmfConverter(mojo::ScopedHandle pdf_file_in,
const PdfRenderSettings& render_settings, const PdfRenderSettings& render_settings,
mojom::PdfToEmfConverterClientPtr client); mojom::PdfToEmfConverterClientPtr client);
~PdfToEmfConverterImpl() override; ~PdfToEmfConverter() override;
int total_page_count() const { return total_page_count_; } int total_page_count() const { return total_page_count_; }
...@@ -39,9 +39,9 @@ class PdfToEmfConverterImpl : public mojom::PdfToEmfConverter { ...@@ -39,9 +39,9 @@ class PdfToEmfConverterImpl : public mojom::PdfToEmfConverter {
PdfRenderSettings pdf_render_settings_; PdfRenderSettings pdf_render_settings_;
std::vector<char> pdf_data_; std::vector<char> pdf_data_;
DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverterImpl); DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverter);
}; };
} // namespace printing } // namespace printing
#endif // CHROME_UTILITY_PRINTING_PDF_TO_EMF_CONVERTER_IMPL_H_ #endif // CHROME_SERVICES_PRINTING_PDF_TO_EMF_CONVERTER_H_
...@@ -2,24 +2,26 @@ ...@@ -2,24 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/utility/printing/pdf_to_emf_converter_factory_impl.h" #include "chrome/services/printing/pdf_to_emf_converter_factory.h"
#include "chrome/utility/printing/pdf_to_emf_converter_impl.h" #include "chrome/services/printing/pdf_to_emf_converter.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/platform_handle.h" #include "mojo/public/cpp/system/platform_handle.h"
namespace printing { namespace printing {
PdfToEmfConverterFactoryImpl::PdfToEmfConverterFactoryImpl() = default; PdfToEmfConverterFactory::PdfToEmfConverterFactory(
std::unique_ptr<service_manager::ServiceContextRef> service_ref)
: service_ref_(std::move(service_ref)) {}
PdfToEmfConverterFactoryImpl::~PdfToEmfConverterFactoryImpl() = default; PdfToEmfConverterFactory::~PdfToEmfConverterFactory() = default;
void PdfToEmfConverterFactoryImpl::CreateConverter( void PdfToEmfConverterFactory::CreateConverter(
mojo::ScopedHandle pdf_file_in, mojo::ScopedHandle pdf_file_in,
const printing::PdfRenderSettings& render_settings, const PdfRenderSettings& render_settings,
mojom::PdfToEmfConverterClientPtr client, mojom::PdfToEmfConverterClientPtr client,
CreateConverterCallback callback) { CreateConverterCallback callback) {
auto converter = std::make_unique<PdfToEmfConverterImpl>( auto converter = std::make_unique<PdfToEmfConverter>(
std::move(pdf_file_in), render_settings, std::move(client)); std::move(pdf_file_in), render_settings, std::move(client));
uint32_t page_count = converter->total_page_count(); uint32_t page_count = converter->total_page_count();
mojom::PdfToEmfConverterPtr converter_ptr; mojom::PdfToEmfConverterPtr converter_ptr;
...@@ -29,11 +31,4 @@ void PdfToEmfConverterFactoryImpl::CreateConverter( ...@@ -29,11 +31,4 @@ void PdfToEmfConverterFactoryImpl::CreateConverter(
std::move(callback).Run(std::move(converter_ptr), page_count); std::move(callback).Run(std::move(converter_ptr), page_count);
} }
// static
void PdfToEmfConverterFactoryImpl::Create(
mojom::PdfToEmfConverterFactoryRequest request) {
mojo::MakeStrongBinding(base::MakeUnique<PdfToEmfConverterFactoryImpl>(),
std::move(request));
}
} // namespace printing } // namespace printing
...@@ -2,31 +2,33 @@ ...@@ -2,31 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_UTILITY_PRINTING_PDF_TO_EMF_CONVERTER_FACTORY_IMPL_H_ #ifndef CHROME_SERVICES_PRINTING_PDF_TO_EMF_CONVERTER_FACTORY_H_
#define CHROME_UTILITY_PRINTING_PDF_TO_EMF_CONVERTER_FACTORY_IMPL_H_ #define CHROME_SERVICES_PRINTING_PDF_TO_EMF_CONVERTER_FACTORY_H_
#include "base/macros.h" #include "base/macros.h"
#include "chrome/common/printing/pdf_to_emf_converter.mojom.h" #include "chrome/services/printing/public/interfaces/pdf_to_emf_converter.mojom.h"
#include "services/service_manager/public/cpp/service_context_ref.h"
namespace printing { namespace printing {
class PdfToEmfConverterFactoryImpl : public mojom::PdfToEmfConverterFactory { class PdfToEmfConverterFactory : public mojom::PdfToEmfConverterFactory {
public: public:
PdfToEmfConverterFactoryImpl(); explicit PdfToEmfConverterFactory(
~PdfToEmfConverterFactoryImpl() override; std::unique_ptr<service_manager::ServiceContextRef> service_ref);
~PdfToEmfConverterFactory() override;
static void Create(mojom::PdfToEmfConverterFactoryRequest request);
private: private:
// mojom::PdfToEmfConverterFactory implementation. // mojom::PdfToEmfConverterFactory implementation.
void CreateConverter(mojo::ScopedHandle pdf_file_in, void CreateConverter(mojo::ScopedHandle pdf_file_in,
const printing::PdfRenderSettings& render_settings, const PdfRenderSettings& render_settings,
mojom::PdfToEmfConverterClientPtr client, mojom::PdfToEmfConverterClientPtr client,
CreateConverterCallback callback) override; CreateConverterCallback callback) override;
DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverterFactoryImpl); const std::unique_ptr<service_manager::ServiceContextRef> service_ref_;
DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverterFactory);
}; };
} // namespace printing } // namespace printing
#endif // CHROME_UTILITY_PRINTING_PDF_TO_EMF_CONVERTER_FACTORY_IMPL_H_ #endif // CHROME_SERVICES_PRINTING_PDF_TO_EMF_CONVERTER_FACTORY_H_
...@@ -97,13 +97,13 @@ bool RenderPdfPagesToPwgRaster(base::File pdf_file, ...@@ -97,13 +97,13 @@ bool RenderPdfPagesToPwgRaster(base::File pdf_file,
} // namespace } // namespace
PdfToPwgRasterConverterImpl::PdfToPwgRasterConverterImpl( PdfToPwgRasterConverter::PdfToPwgRasterConverter(
std::unique_ptr<service_manager::ServiceContextRef> service_ref) std::unique_ptr<service_manager::ServiceContextRef> service_ref)
: service_ref_(std::move(service_ref)) {} : service_ref_(std::move(service_ref)) {}
PdfToPwgRasterConverterImpl::~PdfToPwgRasterConverterImpl() {} PdfToPwgRasterConverter::~PdfToPwgRasterConverter() {}
void PdfToPwgRasterConverterImpl::Convert( void PdfToPwgRasterConverter::Convert(
mojo::ScopedHandle pdf_file_in, mojo::ScopedHandle pdf_file_in,
const PdfRenderSettings& pdf_settings, const PdfRenderSettings& pdf_settings,
const PwgRasterSettings& pwg_raster_settings, const PwgRasterSettings& pwg_raster_settings,
...@@ -112,7 +112,7 @@ void PdfToPwgRasterConverterImpl::Convert( ...@@ -112,7 +112,7 @@ void PdfToPwgRasterConverterImpl::Convert(
base::PlatformFile pdf_file; base::PlatformFile pdf_file;
if (mojo::UnwrapPlatformFile(std::move(pdf_file_in), &pdf_file) != if (mojo::UnwrapPlatformFile(std::move(pdf_file_in), &pdf_file) !=
MOJO_RESULT_OK) { MOJO_RESULT_OK) {
LOG(ERROR) << "Invalid PDF file passed to PdfToPwgRasterConverterImpl"; LOG(ERROR) << "Invalid PDF file passed to PdfToPwgRasterConverter.";
std::move(callback).Run(false); std::move(callback).Run(false);
return; return;
} }
...@@ -120,8 +120,7 @@ void PdfToPwgRasterConverterImpl::Convert( ...@@ -120,8 +120,7 @@ void PdfToPwgRasterConverterImpl::Convert(
base::PlatformFile pwg_raster_file; base::PlatformFile pwg_raster_file;
if (mojo::UnwrapPlatformFile(std::move(pwg_raster_file_out), if (mojo::UnwrapPlatformFile(std::move(pwg_raster_file_out),
&pwg_raster_file) != MOJO_RESULT_OK) { &pwg_raster_file) != MOJO_RESULT_OK) {
LOG(ERROR) LOG(ERROR) << "Invalid PWGRaster file passed to PdfToPwgRasterConverter.";
<< "Invalid PWGRaster file passed to PdfToPwgRasterConverterImpl";
std::move(callback).Run(false); std::move(callback).Run(false);
return; return;
} }
......
...@@ -16,12 +16,12 @@ namespace printing { ...@@ -16,12 +16,12 @@ namespace printing {
struct PdfRenderSettings; struct PdfRenderSettings;
class PdfToPwgRasterConverterImpl class PdfToPwgRasterConverter
: public printing::mojom::PdfToPwgRasterConverter { : public printing::mojom::PdfToPwgRasterConverter {
public: public:
explicit PdfToPwgRasterConverterImpl( explicit PdfToPwgRasterConverter(
std::unique_ptr<service_manager::ServiceContextRef> service_ref); std::unique_ptr<service_manager::ServiceContextRef> service_ref);
~PdfToPwgRasterConverterImpl() override; ~PdfToPwgRasterConverter() override;
private: private:
// printing::mojom::PdfToPwgRasterConverter // printing::mojom::PdfToPwgRasterConverter
...@@ -33,7 +33,7 @@ class PdfToPwgRasterConverterImpl ...@@ -33,7 +33,7 @@ class PdfToPwgRasterConverterImpl
const std::unique_ptr<service_manager::ServiceContextRef> service_ref_; const std::unique_ptr<service_manager::ServiceContextRef> service_ref_;
DISALLOW_COPY_AND_ASSIGN(PdfToPwgRasterConverterImpl); DISALLOW_COPY_AND_ASSIGN(PdfToPwgRasterConverter);
}; };
} // namespace printing } // namespace printing
......
...@@ -8,15 +8,29 @@ ...@@ -8,15 +8,29 @@
#include "chrome/services/printing/pdf_to_pwg_raster_converter.h" #include "chrome/services/printing/pdf_to_pwg_raster_converter.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#if defined(OS_WIN)
#include "chrome/services/printing/pdf_to_emf_converter.h"
#include "chrome/services/printing/pdf_to_emf_converter_factory.h"
#endif
namespace printing { namespace printing {
namespace { namespace {
#if defined(OS_WIN)
void OnPdfToEmfConverterFactoryRequest(
service_manager::ServiceContextRefFactory* ref_factory,
printing::mojom::PdfToEmfConverterFactoryRequest request) {
mojo::MakeStrongBinding(std::make_unique<printing::PdfToEmfConverterFactory>(
ref_factory->CreateRef()),
std::move(request));
}
#endif
void OnPdfToPwgRasterConverterRequest( void OnPdfToPwgRasterConverterRequest(
service_manager::ServiceContextRefFactory* ref_factory, service_manager::ServiceContextRefFactory* ref_factory,
printing::mojom::PdfToPwgRasterConverterRequest request) { printing::mojom::PdfToPwgRasterConverterRequest request) {
mojo::MakeStrongBinding( mojo::MakeStrongBinding(std::make_unique<printing::PdfToPwgRasterConverter>(
std::make_unique<printing::PdfToPwgRasterConverterImpl>(
ref_factory->CreateRef()), ref_factory->CreateRef()),
std::move(request)); std::move(request));
} }
...@@ -35,6 +49,10 @@ void PrintingService::OnStart() { ...@@ -35,6 +49,10 @@ void PrintingService::OnStart() {
ref_factory_ = std::make_unique<service_manager::ServiceContextRefFactory>( ref_factory_ = std::make_unique<service_manager::ServiceContextRefFactory>(
base::Bind(&service_manager::ServiceContext::RequestQuit, base::Bind(&service_manager::ServiceContext::RequestQuit,
base::Unretained(context()))); base::Unretained(context())));
#if defined(OS_WIN)
registry_.AddInterface(
base::Bind(&OnPdfToEmfConverterFactoryRequest, ref_factory_.get()));
#endif
registry_.AddInterface( registry_.AddInterface(
base::Bind(&OnPdfToPwgRasterConverterRequest, ref_factory_.get())); base::Bind(&OnPdfToPwgRasterConverterRequest, ref_factory_.get()));
} }
......
...@@ -11,6 +11,10 @@ mojom("interfaces") { ...@@ -11,6 +11,10 @@ mojom("interfaces") {
"pdf_to_pwg_raster_converter.mojom", "pdf_to_pwg_raster_converter.mojom",
] ]
if (is_win) {
sources += [ "pdf_to_emf_converter.mojom" ]
}
deps = [ deps = [
"//mojo/common:common_custom_types", "//mojo/common:common_custom_types",
"//ui/gfx/geometry/mojo", "//ui/gfx/geometry/mojo",
......
...@@ -184,15 +184,6 @@ static_library("utility") { ...@@ -184,15 +184,6 @@ static_library("utility") {
"printing_handler.cc", "printing_handler.cc",
"printing_handler.h", "printing_handler.h",
] ]
deps += [ "//pdf" ]
if (is_win) {
sources += [
"printing/pdf_to_emf_converter_factory_impl.cc",
"printing/pdf_to_emf_converter_factory_impl.h",
"printing/pdf_to_emf_converter_impl.cc",
"printing/pdf_to_emf_converter_impl.h",
]
}
} }
if (enable_basic_printing || enable_print_preview) { if (enable_basic_printing || enable_print_preview) {
......
...@@ -46,7 +46,6 @@ ...@@ -46,7 +46,6 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "chrome/services/util_win/public/interfaces/constants.mojom.h" #include "chrome/services/util_win/public/interfaces/constants.mojom.h"
#include "chrome/services/util_win/util_win_service.h" #include "chrome/services/util_win/util_win_service.h"
#include "chrome/utility/printing/pdf_to_emf_converter_factory_impl.h"
#endif #endif
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
...@@ -179,11 +178,6 @@ void ChromeContentUtilityClient::UtilityThreadStarted() { ...@@ -179,11 +178,6 @@ void ChromeContentUtilityClient::UtilityThreadStarted() {
registry->AddInterface(base::Bind(CreateResourceUsageReporter), registry->AddInterface(base::Bind(CreateResourceUsageReporter),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
#if defined(OS_WIN)
registry->AddInterface(
base::Bind(printing::PdfToEmfConverterFactoryImpl::Create),
base::ThreadTaskRunnerHandle::Get());
#endif
} }
connection->AddConnectionFilter( connection->AddConnectionFilter(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment