Chromium Code Reviews| 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..a658b22b5d93e59f6b8c9bae6b6714cec40f6eaa 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" |
| @@ -40,6 +39,7 @@ |
| #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 +97,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_->GetPrinting()->RenderPDFPagesToMetafiles( |
| + std::move(pdf_file), conversion_settings, |
| + false /* print_text_with_gdi */, |
| + base::Bind( |
| + &ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageCount, |
| + base::Unretained(host_))); |
| + return true; |
| } |
| void GetMorePages() { |
| @@ -108,10 +112,11 @@ class ServiceUtilityProcessHost::PdfToEmfState { |
| current_page_ < page_count_) { |
| ++pages_in_progress_; |
| emf_files_.push(CreateTempFile()); |
| - host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage( |
| - current_page_++, |
| - IPC::GetPlatformFileForTransit( |
| - emf_files_.back().GetPlatformFile(), false))); |
| + host_->GetPrinting()->RenderPDFPagesToMetafilesGetPage( |
| + current_page_++, emf_files_.back().Duplicate(), |
| + base::Bind( |
| + &ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageDone, |
| + base::Unretained(host_))); |
| } |
| } |
| @@ -139,9 +144,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_.reset(); } |
| base::File CreateTempFile() { |
| base::FilePath path; |
| @@ -204,7 +207,11 @@ bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults( |
| return false; |
| DCHECK(!waiting_for_reply_); |
| waiting_for_reply_ = true; |
| - return Send(new ChromeUtilityMsg_GetPrinterCapsAndDefaults(printer_name)); |
| + GetPrinting()->GetPrinterCapsAndDefaults( |
| + printer_name, |
| + base::Bind(&ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults, |
| + base::Unretained(this), printer_name)); |
| + return true; |
| } |
| bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults( |
| @@ -215,8 +222,12 @@ bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults( |
| return false; |
| DCHECK(!waiting_for_reply_); |
| waiting_for_reply_ = true; |
| - return Send( |
| - new ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults(printer_name)); |
| + GetPrinting()->GetPrinterSemanticCapsAndDefaults( |
| + printer_name, |
| + base::Bind( |
| + &ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults, |
| + base::Unretained(this), printer_name)); |
| + return true; |
| } |
| bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { |
| @@ -288,13 +299,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 +317,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 +374,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 +444,16 @@ bool ServiceUtilityProcessHost::Client::MetafileAvailable(float scale_factor, |
| OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); |
| return true; |
| } |
| + |
| +printing::mojom::Printing* ServiceUtilityProcessHost::GetPrinting() { |
| + if (!printing_) { |
| + printing::mojom::PrintingFactoryPtr printing_factory; |
| + child_process_host_->GetRemoteInterfaces()->GetInterface(&printing_factory); |
|
leonhsl(Using Gerrit)
2017/01/18 03:35:29
Hi, I came across here while checking some issue a
leonhsl(Using Gerrit)
2017/01/18 03:38:11
The issue I'm investigating is https://bugs.chromi
|
| + // We don't care about calls to FontPreCaching so we pass a null pointer |
| + // (FontPreCachingPtr no-arg constructor creates a null InterfacePtr) as the |
| + // second argument. |
| + printing_factory->MakePrinting(mojo::MakeRequest(&printing_), |
| + printing::mojom::FontPreCachingPtr()); |
| + } |
| + return printing_.get(); |
| +} |