| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/service/service_utility_process_host.h" | 5 #include "chrome/service/service_utility_process_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 21 #include "base/process/launch.h" | 21 #include "base/process/launch.h" |
| 22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/task_runner_util.h" | 24 #include "base/task_runner_util.h" |
| 25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "base/win/win_util.h" | 26 #include "base/win/win_util.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/chrome_utility_printing_messages.h" | |
| 30 #include "content/public/common/child_process_host.h" | 29 #include "content/public/common/child_process_host.h" |
| 31 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 32 #include "content/public/common/mojo_channel_switches.h" | 31 #include "content/public/common/mojo_channel_switches.h" |
| 33 #include "content/public/common/result_codes.h" | 32 #include "content/public/common/result_codes.h" |
| 34 #include "content/public/common/sandbox_init.h" | 33 #include "content/public/common/sandbox_init.h" |
| 35 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 34 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 36 #include "mojo/edk/embedder/embedder.h" | 35 #include "mojo/edk/embedder/embedder.h" |
| 37 #include "mojo/edk/embedder/named_platform_channel_pair.h" | 36 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
| 38 #include "mojo/edk/embedder/platform_channel_pair.h" | 37 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 39 #include "mojo/edk/embedder/scoped_platform_handle.h" | 38 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 39 #include "mojo/public/cpp/system/platform_handle.h" |
| 40 #include "printing/emf_win.h" | 40 #include "printing/emf_win.h" |
| 41 #include "sandbox/win/src/sandbox_policy.h" | 41 #include "sandbox/win/src/sandbox_policy.h" |
| 42 #include "sandbox/win/src/sandbox_types.h" | 42 #include "sandbox/win/src/sandbox_types.h" |
| 43 #include "services/service_manager/public/cpp/interface_provider.h" |
| 43 #include "ui/base/ui_base_switches.h" | 44 #include "ui/base/ui_base_switches.h" |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 using content::ChildProcessHost; | 48 using content::ChildProcessHost; |
| 48 | 49 |
| 49 enum ServiceUtilityProcessHostEvent { | 50 enum ServiceUtilityProcessHostEvent { |
| 50 SERVICE_UTILITY_STARTED, | 51 SERVICE_UTILITY_STARTED, |
| 51 SERVICE_UTILITY_DISCONNECTED, | 52 SERVICE_UTILITY_DISCONNECTED, |
| 52 SERVICE_UTILITY_METAFILE_REQUEST, | 53 SERVICE_UTILITY_METAFILE_REQUEST, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 class ServiceUtilityProcessHost::PdfToEmfState { | 91 class ServiceUtilityProcessHost::PdfToEmfState { |
| 91 public: | 92 public: |
| 92 explicit PdfToEmfState(ServiceUtilityProcessHost* host) | 93 explicit PdfToEmfState(ServiceUtilityProcessHost* host) |
| 93 : host_(host), page_count_(0), current_page_(0), pages_in_progress_(0) {} | 94 : host_(host), page_count_(0), current_page_(0), pages_in_progress_(0) {} |
| 94 ~PdfToEmfState() { Stop(); } | 95 ~PdfToEmfState() { Stop(); } |
| 95 | 96 |
| 96 bool Start(base::File pdf_file, | 97 bool Start(base::File pdf_file, |
| 97 const printing::PdfRenderSettings& conversion_settings) { | 98 const printing::PdfRenderSettings& conversion_settings) { |
| 98 if (!temp_dir_.CreateUniqueTempDir()) | 99 if (!temp_dir_.CreateUniqueTempDir()) |
| 99 return false; | 100 return false; |
| 100 return host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles( | 101 host_->printing()->RenderPDFPagesToMetafiles( |
| 101 IPC::TakePlatformFileForTransit(std::move(pdf_file)), | 102 mojo::WrapPlatformFile(pdf_file.TakePlatformFile()), |
| 102 conversion_settings, false /* print_text_with_gdi */)); | 103 conversion_settings, false /* print_text_with_gdi */, |
| 104 base::Bind( |
| 105 &ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageCount, |
| 106 base::Unretained(host_))); |
| 107 return true; |
| 103 } | 108 } |
| 104 | 109 |
| 105 void GetMorePages() { | 110 void GetMorePages() { |
| 106 const int kMaxNumberOfTempFilesPerDocument = 3; | 111 const int kMaxNumberOfTempFilesPerDocument = 3; |
| 107 while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument && | 112 while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument && |
| 108 current_page_ < page_count_) { | 113 current_page_ < page_count_) { |
| 109 ++pages_in_progress_; | 114 ++pages_in_progress_; |
| 110 emf_files_.push(CreateTempFile()); | 115 emf_files_.push(CreateTempFile()); |
| 111 host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage( | 116 host_->printing()->RenderPDFPagesToMetafilesGetPage( |
| 112 current_page_++, | 117 current_page_++, |
| 113 IPC::GetPlatformFileForTransit( | 118 mojo::WrapPlatformFile(emf_files_.back().GetPlatformFile()), |
| 114 emf_files_.back().GetPlatformFile(), false))); | 119 base::Bind( |
| 120 &ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageDone, |
| 121 base::Unretained(host_))); |
| 115 } | 122 } |
| 116 } | 123 } |
| 117 | 124 |
| 118 // Returns true if all pages processed and client should not expect more | 125 // Returns true if all pages processed and client should not expect more |
| 119 // results. | 126 // results. |
| 120 bool OnPageProcessed() { | 127 bool OnPageProcessed() { |
| 121 --pages_in_progress_; | 128 --pages_in_progress_; |
| 122 GetMorePages(); | 129 GetMorePages(); |
| 123 if (pages_in_progress_ || current_page_ < page_count_) | 130 if (pages_in_progress_ || current_page_ < page_count_) |
| 124 return false; | 131 return false; |
| 125 Stop(); | 132 Stop(); |
| 126 return true; | 133 return true; |
| 127 } | 134 } |
| 128 | 135 |
| 129 base::File TakeNextFile() { | 136 base::File TakeNextFile() { |
| 130 DCHECK(!emf_files_.empty()); | 137 DCHECK(!emf_files_.empty()); |
| 131 base::File file; | 138 base::File file; |
| 132 if (!emf_files_.empty()) | 139 if (!emf_files_.empty()) |
| 133 file = std::move(emf_files_.front()); | 140 file = std::move(emf_files_.front()); |
| 134 emf_files_.pop(); | 141 emf_files_.pop(); |
| 135 return file; | 142 return file; |
| 136 } | 143 } |
| 137 | 144 |
| 138 void set_page_count(int page_count) { page_count_ = page_count; } | 145 void set_page_count(int page_count) { page_count_ = page_count; } |
| 139 bool has_page_count() { return page_count_ > 0; } | 146 bool has_page_count() { return page_count_ > 0; } |
| 140 | 147 |
| 141 private: | 148 private: |
| 142 void Stop() { | 149 void Stop() { host_->printing()->RenderPDFPagesToMetafilesStop(); } |
| 143 host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop()); | |
| 144 } | |
| 145 | 150 |
| 146 base::File CreateTempFile() { | 151 base::File CreateTempFile() { |
| 147 base::FilePath path; | 152 base::FilePath path; |
| 148 if (!base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &path)) | 153 if (!base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &path)) |
| 149 return base::File(); | 154 return base::File(); |
| 150 return base::File(path, | 155 return base::File(path, |
| 151 base::File::FLAG_CREATE_ALWAYS | | 156 base::File::FLAG_CREATE_ALWAYS | |
| 152 base::File::FLAG_WRITE | | 157 base::File::FLAG_WRITE | |
| 153 base::File::FLAG_READ | | 158 base::File::FLAG_READ | |
| 154 base::File::FLAG_DELETE_ON_CLOSE | | 159 base::File::FLAG_DELETE_ON_CLOSE | |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 202 } |
| 198 | 203 |
| 199 bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults( | 204 bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults( |
| 200 const std::string& printer_name) { | 205 const std::string& printer_name) { |
| 201 ReportUmaEvent(SERVICE_UTILITY_CAPS_REQUEST); | 206 ReportUmaEvent(SERVICE_UTILITY_CAPS_REQUEST); |
| 202 start_time_ = base::Time::Now(); | 207 start_time_ = base::Time::Now(); |
| 203 if (!StartProcess(true)) | 208 if (!StartProcess(true)) |
| 204 return false; | 209 return false; |
| 205 DCHECK(!waiting_for_reply_); | 210 DCHECK(!waiting_for_reply_); |
| 206 waiting_for_reply_ = true; | 211 waiting_for_reply_ = true; |
| 207 return Send(new ChromeUtilityMsg_GetPrinterCapsAndDefaults(printer_name)); | 212 printing()->GetPrinterCapsAndDefaults( |
| 213 printer_name, |
| 214 base::Bind(&ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults, |
| 215 base::Unretained(this), printer_name)); |
| 216 return true; |
| 208 } | 217 } |
| 209 | 218 |
| 210 bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults( | 219 bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults( |
| 211 const std::string& printer_name) { | 220 const std::string& printer_name) { |
| 212 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_REQUEST); | 221 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_REQUEST); |
| 213 start_time_ = base::Time::Now(); | 222 start_time_ = base::Time::Now(); |
| 214 if (!StartProcess(true)) | 223 if (!StartProcess(true)) |
| 215 return false; | 224 return false; |
| 216 DCHECK(!waiting_for_reply_); | 225 DCHECK(!waiting_for_reply_); |
| 217 waiting_for_reply_ = true; | 226 waiting_for_reply_ = true; |
| 218 return Send( | 227 printing()->GetPrinterSemanticCapsAndDefaults( |
| 219 new ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults(printer_name)); | 228 printer_name, |
| 229 base::Bind( |
| 230 &ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults, |
| 231 base::Unretained(this), printer_name)); |
| 232 return true; |
| 220 } | 233 } |
| 221 | 234 |
| 222 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { | 235 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { |
| 223 std::string mojo_channel_token = | 236 std::string mojo_channel_token = |
| 224 child_process_host_->CreateChannelMojo(mojo_child_token_); | 237 child_process_host_->CreateChannelMojo(mojo_child_token_); |
| 225 if (mojo_channel_token.empty()) | 238 if (mojo_channel_token.empty()) |
| 226 return false; | 239 return false; |
| 227 | 240 |
| 228 base::FilePath exe_path = GetUtilityProcessCmd(); | 241 base::FilePath exe_path = GetUtilityProcessCmd(); |
| 229 if (exe_path.empty()) { | 242 if (exe_path.empty()) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 if (success) { | 294 if (success) { |
| 282 mojo::edk::ChildProcessLaunched(process_.Handle(), | 295 mojo::edk::ChildProcessLaunched(process_.Handle(), |
| 283 std::move(parent_handle), | 296 std::move(parent_handle), |
| 284 mojo_child_token_); | 297 mojo_child_token_); |
| 285 } else { | 298 } else { |
| 286 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); | 299 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); |
| 287 } | 300 } |
| 288 return success; | 301 return success; |
| 289 } | 302 } |
| 290 | 303 |
| 291 bool ServiceUtilityProcessHost::Send(IPC::Message* msg) { | |
| 292 if (child_process_host_) | |
| 293 return child_process_host_->Send(msg); | |
| 294 delete msg; | |
| 295 return false; | |
| 296 } | |
| 297 | |
| 298 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { | 304 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { |
| 299 return ChildProcessHost::GetChildPath(ChildProcessHost::CHILD_NORMAL); | 305 return ChildProcessHost::GetChildPath(ChildProcessHost::CHILD_NORMAL); |
| 300 } | 306 } |
| 301 | 307 |
| 302 void ServiceUtilityProcessHost::OnChildDisconnected() { | 308 void ServiceUtilityProcessHost::OnChildDisconnected() { |
| 303 if (waiting_for_reply_) { | 309 if (waiting_for_reply_) { |
| 304 // If we are yet to receive a reply then notify the client that the | 310 // If we are yet to receive a reply then notify the client that the |
| 305 // child died. | 311 // child died. |
| 306 client_task_runner_->PostTask( | 312 client_task_runner_->PostTask( |
| 307 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); | 313 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); |
| 308 ReportUmaEvent(SERVICE_UTILITY_DISCONNECTED); | 314 ReportUmaEvent(SERVICE_UTILITY_DISCONNECTED); |
| 309 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityDisconnectTime", | 315 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityDisconnectTime", |
| 310 base::Time::Now() - start_time_); | 316 base::Time::Now() - start_time_); |
| 311 } | 317 } |
| 312 delete this; | 318 delete this; |
| 313 } | 319 } |
| 314 | 320 |
| 315 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { | 321 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 316 bool handled = true; | 322 return false; |
| 317 IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message) | |
| 318 IPC_MESSAGE_HANDLER( | |
| 319 ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, | |
| 320 OnRenderPDFPagesToMetafilesPageCount) | |
| 321 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone, | |
| 322 OnRenderPDFPagesToMetafilesPageDone) | |
| 323 IPC_MESSAGE_HANDLER( | |
| 324 ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded, | |
| 325 OnGetPrinterCapsAndDefaultsSucceeded) | |
| 326 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed, | |
| 327 OnGetPrinterCapsAndDefaultsFailed) | |
| 328 IPC_MESSAGE_HANDLER( | |
| 329 ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded, | |
| 330 OnGetPrinterSemanticCapsAndDefaultsSucceeded) | |
| 331 IPC_MESSAGE_HANDLER( | |
| 332 ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed, | |
| 333 OnGetPrinterSemanticCapsAndDefaultsFailed) | |
| 334 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 335 IPC_END_MESSAGE_MAP() | |
| 336 return handled; | |
| 337 } | 323 } |
| 338 | 324 |
| 339 const base::Process& ServiceUtilityProcessHost::GetProcess() const { | 325 const base::Process& ServiceUtilityProcessHost::GetProcess() const { |
| 340 return process_; | 326 return process_; |
| 341 } | 327 } |
| 342 | 328 |
| 343 void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) { | 329 void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) { |
| 344 if (!success || pdf_to_emf_state_->OnPageProcessed()) | 330 if (!success || pdf_to_emf_state_->OnPageProcessed()) |
| 345 OnPDFToEmfFinished(success); | 331 OnPDFToEmfFinished(success); |
| 346 } | 332 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 ReportUmaEvent(SERVICE_UTILITY_METAFILE_FAILED); | 369 ReportUmaEvent(SERVICE_UTILITY_METAFILE_FAILED); |
| 384 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityMetafileFailTime", | 370 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityMetafileFailTime", |
| 385 base::Time::Now() - start_time_); | 371 base::Time::Now() - start_time_); |
| 386 } | 372 } |
| 387 client_task_runner_->PostTask( | 373 client_task_runner_->PostTask( |
| 388 FROM_HERE, base::Bind(&Client::OnRenderPDFPagesToMetafileDone, | 374 FROM_HERE, base::Bind(&Client::OnRenderPDFPagesToMetafileDone, |
| 389 client_.get(), success)); | 375 client_.get(), success)); |
| 390 pdf_to_emf_state_.reset(); | 376 pdf_to_emf_state_.reset(); |
| 391 } | 377 } |
| 392 | 378 |
| 393 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsSucceeded( | 379 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults( |
| 394 const std::string& printer_name, | 380 const std::string& printer_name, |
| 395 const printing::PrinterCapsAndDefaults& caps_and_defaults) { | 381 const base::Optional<printing::PrinterCapsAndDefaults>& caps_and_defaults) { |
| 396 DCHECK(waiting_for_reply_); | 382 DCHECK(waiting_for_reply_); |
| 397 ReportUmaEvent(SERVICE_UTILITY_CAPS_SUCCEEDED); | |
| 398 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsTime", | |
| 399 base::Time::Now() - start_time_); | |
| 400 waiting_for_reply_ = false; | 383 waiting_for_reply_ = false; |
| 401 client_task_runner_->PostTask( | 384 if (caps_and_defaults) { |
| 402 FROM_HERE, base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), | 385 ReportUmaEvent(SERVICE_UTILITY_CAPS_SUCCEEDED); |
| 403 true, printer_name, caps_and_defaults)); | 386 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsTime", |
| 387 base::Time::Now() - start_time_); |
| 388 client_task_runner_->PostTask( |
| 389 FROM_HERE, |
| 390 base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), true, |
| 391 printer_name, caps_and_defaults.value())); |
| 392 } else { |
| 393 ReportUmaEvent(SERVICE_UTILITY_CAPS_FAILED); |
| 394 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsFailTime", |
| 395 base::Time::Now() - start_time_); |
| 396 client_task_runner_->PostTask( |
| 397 FROM_HERE, |
| 398 base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), false, |
| 399 printer_name, printing::PrinterCapsAndDefaults())); |
| 400 } |
| 404 } | 401 } |
| 405 | 402 |
| 406 void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsSucceeded( | 403 void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults( |
| 407 const std::string& printer_name, | 404 const std::string& printer_name, |
| 408 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) { | 405 const base::Optional<printing::PrinterSemanticCapsAndDefaults>& |
| 406 caps_and_defaults) { |
| 409 DCHECK(waiting_for_reply_); | 407 DCHECK(waiting_for_reply_); |
| 410 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_SUCCEEDED); | |
| 411 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsTime", | |
| 412 base::Time::Now() - start_time_); | |
| 413 waiting_for_reply_ = false; | 408 waiting_for_reply_ = false; |
| 414 client_task_runner_->PostTask( | 409 if (caps_and_defaults) { |
| 415 FROM_HERE, | 410 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_SUCCEEDED); |
| 416 base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, client_.get(), | 411 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsTime", |
| 417 true, printer_name, caps_and_defaults)); | 412 base::Time::Now() - start_time_); |
| 418 } | 413 client_task_runner_->PostTask( |
| 419 | 414 FROM_HERE, |
| 420 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsFailed( | 415 base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, client_.get(), |
| 421 const std::string& printer_name) { | 416 true, printer_name, caps_and_defaults.value())); |
| 422 DCHECK(waiting_for_reply_); | 417 } else { |
| 423 ReportUmaEvent(SERVICE_UTILITY_CAPS_FAILED); | 418 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_FAILED); |
| 424 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsFailTime", | 419 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsFailTime", |
| 425 base::Time::Now() - start_time_); | 420 base::Time::Now() - start_time_); |
| 426 waiting_for_reply_ = false; | 421 client_task_runner_->PostTask( |
| 427 client_task_runner_->PostTask( | 422 FROM_HERE, base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, |
| 428 FROM_HERE, | 423 client_.get(), false, printer_name, |
| 429 base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), false, | 424 printing::PrinterSemanticCapsAndDefaults())); |
| 430 printer_name, printing::PrinterCapsAndDefaults())); | 425 } |
| 431 } | |
| 432 | |
| 433 void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsFailed( | |
| 434 const std::string& printer_name) { | |
| 435 DCHECK(waiting_for_reply_); | |
| 436 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_FAILED); | |
| 437 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsFailTime", | |
| 438 base::Time::Now() - start_time_); | |
| 439 waiting_for_reply_ = false; | |
| 440 client_task_runner_->PostTask( | |
| 441 FROM_HERE, base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, | |
| 442 client_.get(), false, printer_name, | |
| 443 printing::PrinterSemanticCapsAndDefaults())); | |
| 444 } | 426 } |
| 445 | 427 |
| 446 bool ServiceUtilityProcessHost::Client::MetafileAvailable(float scale_factor, | 428 bool ServiceUtilityProcessHost::Client::MetafileAvailable(float scale_factor, |
| 447 base::File file) { | 429 base::File file) { |
| 448 file.Seek(base::File::FROM_BEGIN, 0); | 430 file.Seek(base::File::FROM_BEGIN, 0); |
| 449 int64_t size = file.GetLength(); | 431 int64_t size = file.GetLength(); |
| 450 if (size <= 0) { | 432 if (size <= 0) { |
| 451 OnRenderPDFPagesToMetafileDone(false); | 433 OnRenderPDFPagesToMetafileDone(false); |
| 452 return false; | 434 return false; |
| 453 } | 435 } |
| 454 std::vector<char> data(size); | 436 std::vector<char> data(size); |
| 455 if (file.ReadAtCurrentPos(data.data(), data.size()) != size) { | 437 if (file.ReadAtCurrentPos(data.data(), data.size()) != size) { |
| 456 OnRenderPDFPagesToMetafileDone(false); | 438 OnRenderPDFPagesToMetafileDone(false); |
| 457 return false; | 439 return false; |
| 458 } | 440 } |
| 459 printing::Emf emf; | 441 printing::Emf emf; |
| 460 if (!emf.InitFromData(data.data(), data.size())) { | 442 if (!emf.InitFromData(data.data(), data.size())) { |
| 461 OnRenderPDFPagesToMetafileDone(false); | 443 OnRenderPDFPagesToMetafileDone(false); |
| 462 return false; | 444 return false; |
| 463 } | 445 } |
| 464 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); | 446 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); |
| 465 return true; | 447 return true; |
| 466 } | 448 } |
| 449 |
| 450 printing::mojom::Printing* ServiceUtilityProcessHost::printing() { |
| 451 if (!printing_) { |
| 452 printing::mojom::PrintingFactoryPtr printing_factory; |
| 453 child_process_host_->GetRemoteInterfaces()->GetInterface(&printing_factory); |
| 454 // We don't care about calls to FontPreCaching so we pass a null pointer for |
| 455 // the second argument. |
| 456 printing_factory->MakePrinting(mojo::GetProxy(&printing_), |
| 457 printing::mojom::FontPreCachingPtr()); |
| 458 } |
| 459 return printing_.get(); |
| 460 } |
| OLD | NEW |