| Index: chrome/service/service_utility_process_host.cc
|
| diff --git a/chrome/service/service_utility_process_host.cc b/chrome/service/service_utility_process_host.cc
|
| index 24431254afd7082e5995855614aa3556828a0f8f..de2229a7591e52edd5eb8ca0a658caad94af63b6 100644
|
| --- a/chrome/service/service_utility_process_host.cc
|
| +++ b/chrome/service/service_utility_process_host.cc
|
| @@ -26,7 +26,6 @@
|
| #include "base/win/win_util.h"
|
| #include "build/build_config.h"
|
| #include "chrome/common/chrome_switches.h"
|
| -#include "chrome/common/chrome_utility_printing_messages.h"
|
| #include "content/public/common/child_process_host.h"
|
| #include "content/public/common/content_switches.h"
|
| #include "content/public/common/mojo_channel_switches.h"
|
| @@ -37,9 +36,11 @@
|
| #include "mojo/edk/embedder/named_platform_channel_pair.h"
|
| #include "mojo/edk/embedder/platform_channel_pair.h"
|
| #include "mojo/edk/embedder/scoped_platform_handle.h"
|
| +#include "mojo/public/cpp/system/platform_handle.h"
|
| #include "printing/emf_win.h"
|
| #include "sandbox/win/src/sandbox_policy.h"
|
| #include "sandbox/win/src/sandbox_types.h"
|
| +#include "services/service_manager/public/cpp/interface_provider.h"
|
| #include "ui/base/ui_base_switches.h"
|
|
|
| namespace {
|
| @@ -97,9 +98,13 @@ class ServiceUtilityProcessHost::PdfToEmfState {
|
| const printing::PdfRenderSettings& conversion_settings) {
|
| if (!temp_dir_.CreateUniqueTempDir())
|
| return false;
|
| - return host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles(
|
| - IPC::TakePlatformFileForTransit(std::move(pdf_file)),
|
| - conversion_settings, false /* print_text_with_gdi */));
|
| + host_->printing()->RenderPDFPagesToMetafiles(
|
| + mojo::WrapPlatformFile(pdf_file.TakePlatformFile()),
|
| + conversion_settings, false /* print_text_with_gdi */,
|
| + base::Bind(
|
| + &ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageCount,
|
| + base::Unretained(host_)));
|
| + return true;
|
| }
|
|
|
| void GetMorePages() {
|
| @@ -108,10 +113,12 @@ class ServiceUtilityProcessHost::PdfToEmfState {
|
| current_page_ < page_count_) {
|
| ++pages_in_progress_;
|
| emf_files_.push(CreateTempFile());
|
| - host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage(
|
| + host_->printing()->RenderPDFPagesToMetafilesGetPage(
|
| current_page_++,
|
| - IPC::GetPlatformFileForTransit(
|
| - emf_files_.back().GetPlatformFile(), false)));
|
| + mojo::WrapPlatformFile(emf_files_.back().GetPlatformFile()),
|
| + base::Bind(
|
| + &ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageDone,
|
| + base::Unretained(host_)));
|
| }
|
| }
|
|
|
| @@ -139,9 +146,7 @@ class ServiceUtilityProcessHost::PdfToEmfState {
|
| bool has_page_count() { return page_count_ > 0; }
|
|
|
| private:
|
| - void Stop() {
|
| - host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop());
|
| - }
|
| + void Stop() { host_->printing()->RenderPDFPagesToMetafilesStop(); }
|
|
|
| base::File CreateTempFile() {
|
| base::FilePath path;
|
| @@ -204,7 +209,11 @@ bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults(
|
| return false;
|
| DCHECK(!waiting_for_reply_);
|
| waiting_for_reply_ = true;
|
| - return Send(new ChromeUtilityMsg_GetPrinterCapsAndDefaults(printer_name));
|
| + printing()->GetPrinterCapsAndDefaults(
|
| + printer_name,
|
| + base::Bind(&ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults,
|
| + base::Unretained(this), printer_name));
|
| + return true;
|
| }
|
|
|
| bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults(
|
| @@ -215,8 +224,12 @@ bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults(
|
| return false;
|
| DCHECK(!waiting_for_reply_);
|
| waiting_for_reply_ = true;
|
| - return Send(
|
| - new ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults(printer_name));
|
| + printing()->GetPrinterSemanticCapsAndDefaults(
|
| + printer_name,
|
| + base::Bind(
|
| + &ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults,
|
| + base::Unretained(this), printer_name));
|
| + return true;
|
| }
|
|
|
| bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) {
|
| @@ -288,13 +301,6 @@ bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line,
|
| return success;
|
| }
|
|
|
| -bool ServiceUtilityProcessHost::Send(IPC::Message* msg) {
|
| - if (child_process_host_)
|
| - return child_process_host_->Send(msg);
|
| - delete msg;
|
| - return false;
|
| -}
|
| -
|
| base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() {
|
| return ChildProcessHost::GetChildPath(ChildProcessHost::CHILD_NORMAL);
|
| }
|
| @@ -313,27 +319,7 @@ void ServiceUtilityProcessHost::OnChildDisconnected() {
|
| }
|
|
|
| bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message)
|
| - IPC_MESSAGE_HANDLER(
|
| - ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount,
|
| - OnRenderPDFPagesToMetafilesPageCount)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone,
|
| - OnRenderPDFPagesToMetafilesPageDone)
|
| - IPC_MESSAGE_HANDLER(
|
| - ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded,
|
| - OnGetPrinterCapsAndDefaultsSucceeded)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed,
|
| - OnGetPrinterCapsAndDefaultsFailed)
|
| - IPC_MESSAGE_HANDLER(
|
| - ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded,
|
| - OnGetPrinterSemanticCapsAndDefaultsSucceeded)
|
| - IPC_MESSAGE_HANDLER(
|
| - ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed,
|
| - OnGetPrinterSemanticCapsAndDefaultsFailed)
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - return handled;
|
| + return false;
|
| }
|
|
|
| const base::Process& ServiceUtilityProcessHost::GetProcess() const {
|
| @@ -390,57 +376,53 @@ void ServiceUtilityProcessHost::OnPDFToEmfFinished(bool success) {
|
| pdf_to_emf_state_.reset();
|
| }
|
|
|
| -void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsSucceeded(
|
| +void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults(
|
| const std::string& printer_name,
|
| - const printing::PrinterCapsAndDefaults& caps_and_defaults) {
|
| + const base::Optional<printing::PrinterCapsAndDefaults>& caps_and_defaults) {
|
| DCHECK(waiting_for_reply_);
|
| - ReportUmaEvent(SERVICE_UTILITY_CAPS_SUCCEEDED);
|
| - UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsTime",
|
| - base::Time::Now() - start_time_);
|
| waiting_for_reply_ = false;
|
| - client_task_runner_->PostTask(
|
| - FROM_HERE, base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(),
|
| - true, printer_name, caps_and_defaults));
|
| + if (caps_and_defaults) {
|
| + ReportUmaEvent(SERVICE_UTILITY_CAPS_SUCCEEDED);
|
| + UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsTime",
|
| + base::Time::Now() - start_time_);
|
| + client_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), true,
|
| + printer_name, caps_and_defaults.value()));
|
| + } else {
|
| + ReportUmaEvent(SERVICE_UTILITY_CAPS_FAILED);
|
| + UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsFailTime",
|
| + base::Time::Now() - start_time_);
|
| + client_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), false,
|
| + printer_name, printing::PrinterCapsAndDefaults()));
|
| + }
|
| }
|
|
|
| -void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsSucceeded(
|
| +void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults(
|
| const std::string& printer_name,
|
| - const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) {
|
| + const base::Optional<printing::PrinterSemanticCapsAndDefaults>&
|
| + caps_and_defaults) {
|
| DCHECK(waiting_for_reply_);
|
| - ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_SUCCEEDED);
|
| - UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsTime",
|
| - base::Time::Now() - start_time_);
|
| waiting_for_reply_ = false;
|
| - client_task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, client_.get(),
|
| - true, printer_name, caps_and_defaults));
|
| -}
|
| -
|
| -void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsFailed(
|
| - const std::string& printer_name) {
|
| - DCHECK(waiting_for_reply_);
|
| - ReportUmaEvent(SERVICE_UTILITY_CAPS_FAILED);
|
| - UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsFailTime",
|
| - base::Time::Now() - start_time_);
|
| - waiting_for_reply_ = false;
|
| - client_task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), false,
|
| - printer_name, printing::PrinterCapsAndDefaults()));
|
| -}
|
| -
|
| -void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsFailed(
|
| - const std::string& printer_name) {
|
| - DCHECK(waiting_for_reply_);
|
| - ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_FAILED);
|
| - UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsFailTime",
|
| - base::Time::Now() - start_time_);
|
| - waiting_for_reply_ = false;
|
| - client_task_runner_->PostTask(
|
| - FROM_HERE, base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults,
|
| - client_.get(), false, printer_name,
|
| - printing::PrinterSemanticCapsAndDefaults()));
|
| + if (caps_and_defaults) {
|
| + ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_SUCCEEDED);
|
| + UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsTime",
|
| + base::Time::Now() - start_time_);
|
| + client_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, client_.get(),
|
| + true, printer_name, caps_and_defaults.value()));
|
| + } else {
|
| + ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_FAILED);
|
| + UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsFailTime",
|
| + base::Time::Now() - start_time_);
|
| + client_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults,
|
| + client_.get(), false, printer_name,
|
| + printing::PrinterSemanticCapsAndDefaults()));
|
| + }
|
| }
|
|
|
| bool ServiceUtilityProcessHost::Client::MetafileAvailable(float scale_factor,
|
| @@ -464,3 +446,15 @@ bool ServiceUtilityProcessHost::Client::MetafileAvailable(float scale_factor,
|
| OnRenderPDFPagesToMetafilePageDone(scale_factor, emf);
|
| return true;
|
| }
|
| +
|
| +printing::mojom::Printing* ServiceUtilityProcessHost::printing() {
|
| + if (!printing_) {
|
| + printing::mojom::PrintingFactoryPtr printing_factory;
|
| + child_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_),
|
| + printing::mojom::FontPreCachingPtr());
|
| + }
|
| + return printing_.get();
|
| +}
|
|
|