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" |
40 #include "printing/emf_win.h" | 39 #include "printing/emf_win.h" |
41 #include "sandbox/win/src/sandbox_policy.h" | 40 #include "sandbox/win/src/sandbox_policy.h" |
42 #include "sandbox/win/src/sandbox_types.h" | 41 #include "sandbox/win/src/sandbox_types.h" |
42 #include "services/service_manager/public/cpp/interface_provider.h" | |
43 #include "ui/base/ui_base_switches.h" | 43 #include "ui/base/ui_base_switches.h" |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 using content::ChildProcessHost; | 47 using content::ChildProcessHost; |
48 | 48 |
49 enum ServiceUtilityProcessHostEvent { | 49 enum ServiceUtilityProcessHostEvent { |
50 SERVICE_UTILITY_STARTED, | 50 SERVICE_UTILITY_STARTED, |
51 SERVICE_UTILITY_DISCONNECTED, | 51 SERVICE_UTILITY_DISCONNECTED, |
52 SERVICE_UTILITY_METAFILE_REQUEST, | 52 SERVICE_UTILITY_METAFILE_REQUEST, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 class ServiceUtilityProcessHost::PdfToEmfState { | 90 class ServiceUtilityProcessHost::PdfToEmfState { |
91 public: | 91 public: |
92 explicit PdfToEmfState(ServiceUtilityProcessHost* host) | 92 explicit PdfToEmfState(ServiceUtilityProcessHost* host) |
93 : host_(host), page_count_(0), current_page_(0), pages_in_progress_(0) {} | 93 : host_(host), page_count_(0), current_page_(0), pages_in_progress_(0) {} |
94 ~PdfToEmfState() { Stop(); } | 94 ~PdfToEmfState() { Stop(); } |
95 | 95 |
96 bool Start(base::File pdf_file, | 96 bool Start(base::File pdf_file, |
97 const printing::PdfRenderSettings& conversion_settings) { | 97 const printing::PdfRenderSettings& conversion_settings) { |
98 if (!temp_dir_.CreateUniqueTempDir()) | 98 if (!temp_dir_.CreateUniqueTempDir()) |
99 return false; | 99 return false; |
100 return host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles( | 100 host_->GetPrinting()->RenderPDFPagesToMetafiles( |
101 IPC::TakePlatformFileForTransit(std::move(pdf_file)), | 101 std::move(pdf_file), conversion_settings, |
102 conversion_settings, false /* print_text_with_gdi */)); | 102 false /* print_text_with_gdi */, |
103 base::Bind( | |
104 &ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageCount, | |
105 base::Unretained(host_))); | |
106 return true; | |
103 } | 107 } |
104 | 108 |
105 void GetMorePages() { | 109 void GetMorePages() { |
106 const int kMaxNumberOfTempFilesPerDocument = 3; | 110 const int kMaxNumberOfTempFilesPerDocument = 3; |
107 while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument && | 111 while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument && |
108 current_page_ < page_count_) { | 112 current_page_ < page_count_) { |
109 ++pages_in_progress_; | 113 ++pages_in_progress_; |
110 emf_files_.push(CreateTempFile()); | 114 emf_files_.push(CreateTempFile()); |
111 host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage( | 115 host_->GetPrinting()->RenderPDFPagesToMetafilesGetPage( |
112 current_page_++, | 116 current_page_++, emf_files_.back().Duplicate(), |
113 IPC::GetPlatformFileForTransit( | 117 base::Bind( |
114 emf_files_.back().GetPlatformFile(), false))); | 118 &ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageDone, |
119 base::Unretained(host_))); | |
115 } | 120 } |
116 } | 121 } |
117 | 122 |
118 // Returns true if all pages processed and client should not expect more | 123 // Returns true if all pages processed and client should not expect more |
119 // results. | 124 // results. |
120 bool OnPageProcessed() { | 125 bool OnPageProcessed() { |
121 --pages_in_progress_; | 126 --pages_in_progress_; |
122 GetMorePages(); | 127 GetMorePages(); |
123 if (pages_in_progress_ || current_page_ < page_count_) | 128 if (pages_in_progress_ || current_page_ < page_count_) |
124 return false; | 129 return false; |
125 Stop(); | 130 Stop(); |
126 return true; | 131 return true; |
127 } | 132 } |
128 | 133 |
129 base::File TakeNextFile() { | 134 base::File TakeNextFile() { |
130 DCHECK(!emf_files_.empty()); | 135 DCHECK(!emf_files_.empty()); |
131 base::File file; | 136 base::File file; |
132 if (!emf_files_.empty()) | 137 if (!emf_files_.empty()) |
133 file = std::move(emf_files_.front()); | 138 file = std::move(emf_files_.front()); |
134 emf_files_.pop(); | 139 emf_files_.pop(); |
135 return file; | 140 return file; |
136 } | 141 } |
137 | 142 |
138 void set_page_count(int page_count) { page_count_ = page_count; } | 143 void set_page_count(int page_count) { page_count_ = page_count; } |
139 bool has_page_count() { return page_count_ > 0; } | 144 bool has_page_count() { return page_count_ > 0; } |
140 | 145 |
141 private: | 146 private: |
142 void Stop() { | 147 void Stop() { host_->printing_.reset(); } |
143 host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop()); | |
144 } | |
145 | 148 |
146 base::File CreateTempFile() { | 149 base::File CreateTempFile() { |
147 base::FilePath path; | 150 base::FilePath path; |
148 if (!base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &path)) | 151 if (!base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &path)) |
149 return base::File(); | 152 return base::File(); |
150 return base::File(path, | 153 return base::File(path, |
151 base::File::FLAG_CREATE_ALWAYS | | 154 base::File::FLAG_CREATE_ALWAYS | |
152 base::File::FLAG_WRITE | | 155 base::File::FLAG_WRITE | |
153 base::File::FLAG_READ | | 156 base::File::FLAG_READ | |
154 base::File::FLAG_DELETE_ON_CLOSE | | 157 base::File::FLAG_DELETE_ON_CLOSE | |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 } | 200 } |
198 | 201 |
199 bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults( | 202 bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults( |
200 const std::string& printer_name) { | 203 const std::string& printer_name) { |
201 ReportUmaEvent(SERVICE_UTILITY_CAPS_REQUEST); | 204 ReportUmaEvent(SERVICE_UTILITY_CAPS_REQUEST); |
202 start_time_ = base::Time::Now(); | 205 start_time_ = base::Time::Now(); |
203 if (!StartProcess(true)) | 206 if (!StartProcess(true)) |
204 return false; | 207 return false; |
205 DCHECK(!waiting_for_reply_); | 208 DCHECK(!waiting_for_reply_); |
206 waiting_for_reply_ = true; | 209 waiting_for_reply_ = true; |
207 return Send(new ChromeUtilityMsg_GetPrinterCapsAndDefaults(printer_name)); | 210 GetPrinting()->GetPrinterCapsAndDefaults( |
211 printer_name, | |
212 base::Bind(&ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults, | |
213 base::Unretained(this), printer_name)); | |
214 return true; | |
208 } | 215 } |
209 | 216 |
210 bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults( | 217 bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults( |
211 const std::string& printer_name) { | 218 const std::string& printer_name) { |
212 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_REQUEST); | 219 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_REQUEST); |
213 start_time_ = base::Time::Now(); | 220 start_time_ = base::Time::Now(); |
214 if (!StartProcess(true)) | 221 if (!StartProcess(true)) |
215 return false; | 222 return false; |
216 DCHECK(!waiting_for_reply_); | 223 DCHECK(!waiting_for_reply_); |
217 waiting_for_reply_ = true; | 224 waiting_for_reply_ = true; |
218 return Send( | 225 GetPrinting()->GetPrinterSemanticCapsAndDefaults( |
219 new ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults(printer_name)); | 226 printer_name, |
227 base::Bind( | |
228 &ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults, | |
229 base::Unretained(this), printer_name)); | |
230 return true; | |
220 } | 231 } |
221 | 232 |
222 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { | 233 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { |
223 std::string mojo_channel_token = | 234 std::string mojo_channel_token = |
224 child_process_host_->CreateChannelMojo(mojo_child_token_); | 235 child_process_host_->CreateChannelMojo(mojo_child_token_); |
225 if (mojo_channel_token.empty()) | 236 if (mojo_channel_token.empty()) |
226 return false; | 237 return false; |
227 | 238 |
228 base::FilePath exe_path = GetUtilityProcessCmd(); | 239 base::FilePath exe_path = GetUtilityProcessCmd(); |
229 if (exe_path.empty()) { | 240 if (exe_path.empty()) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 if (success) { | 292 if (success) { |
282 mojo::edk::ChildProcessLaunched(process_.Handle(), | 293 mojo::edk::ChildProcessLaunched(process_.Handle(), |
283 std::move(parent_handle), | 294 std::move(parent_handle), |
284 mojo_child_token_); | 295 mojo_child_token_); |
285 } else { | 296 } else { |
286 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); | 297 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); |
287 } | 298 } |
288 return success; | 299 return success; |
289 } | 300 } |
290 | 301 |
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() { | 302 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { |
299 return ChildProcessHost::GetChildPath(ChildProcessHost::CHILD_NORMAL); | 303 return ChildProcessHost::GetChildPath(ChildProcessHost::CHILD_NORMAL); |
300 } | 304 } |
301 | 305 |
302 void ServiceUtilityProcessHost::OnChildDisconnected() { | 306 void ServiceUtilityProcessHost::OnChildDisconnected() { |
303 if (waiting_for_reply_) { | 307 if (waiting_for_reply_) { |
304 // If we are yet to receive a reply then notify the client that the | 308 // If we are yet to receive a reply then notify the client that the |
305 // child died. | 309 // child died. |
306 client_task_runner_->PostTask( | 310 client_task_runner_->PostTask( |
307 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); | 311 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); |
308 ReportUmaEvent(SERVICE_UTILITY_DISCONNECTED); | 312 ReportUmaEvent(SERVICE_UTILITY_DISCONNECTED); |
309 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityDisconnectTime", | 313 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityDisconnectTime", |
310 base::Time::Now() - start_time_); | 314 base::Time::Now() - start_time_); |
311 } | 315 } |
312 delete this; | 316 delete this; |
313 } | 317 } |
314 | 318 |
315 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { | 319 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { |
316 bool handled = true; | 320 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 } | 321 } |
338 | 322 |
339 const base::Process& ServiceUtilityProcessHost::GetProcess() const { | 323 const base::Process& ServiceUtilityProcessHost::GetProcess() const { |
340 return process_; | 324 return process_; |
341 } | 325 } |
342 | 326 |
343 void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) { | 327 void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) { |
344 if (!success || pdf_to_emf_state_->OnPageProcessed()) | 328 if (!success || pdf_to_emf_state_->OnPageProcessed()) |
345 OnPDFToEmfFinished(success); | 329 OnPDFToEmfFinished(success); |
346 } | 330 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 ReportUmaEvent(SERVICE_UTILITY_METAFILE_FAILED); | 367 ReportUmaEvent(SERVICE_UTILITY_METAFILE_FAILED); |
384 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityMetafileFailTime", | 368 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityMetafileFailTime", |
385 base::Time::Now() - start_time_); | 369 base::Time::Now() - start_time_); |
386 } | 370 } |
387 client_task_runner_->PostTask( | 371 client_task_runner_->PostTask( |
388 FROM_HERE, base::Bind(&Client::OnRenderPDFPagesToMetafileDone, | 372 FROM_HERE, base::Bind(&Client::OnRenderPDFPagesToMetafileDone, |
389 client_.get(), success)); | 373 client_.get(), success)); |
390 pdf_to_emf_state_.reset(); | 374 pdf_to_emf_state_.reset(); |
391 } | 375 } |
392 | 376 |
393 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsSucceeded( | 377 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults( |
394 const std::string& printer_name, | 378 const std::string& printer_name, |
395 const printing::PrinterCapsAndDefaults& caps_and_defaults) { | 379 const base::Optional<printing::PrinterCapsAndDefaults>& caps_and_defaults) { |
396 DCHECK(waiting_for_reply_); | 380 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; | 381 waiting_for_reply_ = false; |
401 client_task_runner_->PostTask( | 382 if (caps_and_defaults) { |
402 FROM_HERE, base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), | 383 ReportUmaEvent(SERVICE_UTILITY_CAPS_SUCCEEDED); |
403 true, printer_name, caps_and_defaults)); | 384 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsTime", |
385 base::Time::Now() - start_time_); | |
386 client_task_runner_->PostTask( | |
387 FROM_HERE, | |
388 base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), true, | |
389 printer_name, caps_and_defaults.value())); | |
390 } else { | |
391 ReportUmaEvent(SERVICE_UTILITY_CAPS_FAILED); | |
392 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsFailTime", | |
393 base::Time::Now() - start_time_); | |
394 client_task_runner_->PostTask( | |
395 FROM_HERE, | |
396 base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), false, | |
397 printer_name, printing::PrinterCapsAndDefaults())); | |
398 } | |
404 } | 399 } |
405 | 400 |
406 void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsSucceeded( | 401 void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults( |
407 const std::string& printer_name, | 402 const std::string& printer_name, |
408 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) { | 403 const base::Optional<printing::PrinterSemanticCapsAndDefaults>& |
404 caps_and_defaults) { | |
409 DCHECK(waiting_for_reply_); | 405 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; | 406 waiting_for_reply_ = false; |
414 client_task_runner_->PostTask( | 407 if (caps_and_defaults) { |
415 FROM_HERE, | 408 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_SUCCEEDED); |
416 base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, client_.get(), | 409 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsTime", |
417 true, printer_name, caps_and_defaults)); | 410 base::Time::Now() - start_time_); |
418 } | 411 client_task_runner_->PostTask( |
419 | 412 FROM_HERE, |
420 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsFailed( | 413 base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, client_.get(), |
421 const std::string& printer_name) { | 414 true, printer_name, caps_and_defaults.value())); |
422 DCHECK(waiting_for_reply_); | 415 } else { |
423 ReportUmaEvent(SERVICE_UTILITY_CAPS_FAILED); | 416 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_FAILED); |
424 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsFailTime", | 417 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsFailTime", |
425 base::Time::Now() - start_time_); | 418 base::Time::Now() - start_time_); |
426 waiting_for_reply_ = false; | 419 client_task_runner_->PostTask( |
427 client_task_runner_->PostTask( | 420 FROM_HERE, base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, |
428 FROM_HERE, | 421 client_.get(), false, printer_name, |
429 base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), false, | 422 printing::PrinterSemanticCapsAndDefaults())); |
430 printer_name, printing::PrinterCapsAndDefaults())); | 423 } |
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 } | 424 } |
445 | 425 |
446 bool ServiceUtilityProcessHost::Client::MetafileAvailable(float scale_factor, | 426 bool ServiceUtilityProcessHost::Client::MetafileAvailable(float scale_factor, |
447 base::File file) { | 427 base::File file) { |
448 file.Seek(base::File::FROM_BEGIN, 0); | 428 file.Seek(base::File::FROM_BEGIN, 0); |
449 int64_t size = file.GetLength(); | 429 int64_t size = file.GetLength(); |
450 if (size <= 0) { | 430 if (size <= 0) { |
451 OnRenderPDFPagesToMetafileDone(false); | 431 OnRenderPDFPagesToMetafileDone(false); |
452 return false; | 432 return false; |
453 } | 433 } |
454 std::vector<char> data(size); | 434 std::vector<char> data(size); |
455 if (file.ReadAtCurrentPos(data.data(), data.size()) != size) { | 435 if (file.ReadAtCurrentPos(data.data(), data.size()) != size) { |
456 OnRenderPDFPagesToMetafileDone(false); | 436 OnRenderPDFPagesToMetafileDone(false); |
457 return false; | 437 return false; |
458 } | 438 } |
459 printing::Emf emf; | 439 printing::Emf emf; |
460 if (!emf.InitFromData(data.data(), data.size())) { | 440 if (!emf.InitFromData(data.data(), data.size())) { |
461 OnRenderPDFPagesToMetafileDone(false); | 441 OnRenderPDFPagesToMetafileDone(false); |
462 return false; | 442 return false; |
463 } | 443 } |
464 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); | 444 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); |
465 return true; | 445 return true; |
466 } | 446 } |
447 | |
448 printing::mojom::Printing* ServiceUtilityProcessHost::GetPrinting() { | |
449 if (!printing_) { | |
450 printing::mojom::PrintingFactoryPtr printing_factory; | |
451 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
| |
452 // We don't care about calls to FontPreCaching so we pass a null pointer | |
453 // (FontPreCachingPtr no-arg constructor creates a null InterfacePtr) as the | |
454 // second argument. | |
455 printing_factory->MakePrinting(mojo::MakeRequest(&printing_), | |
456 printing::mojom::FontPreCachingPtr()); | |
457 } | |
458 return printing_.get(); | |
459 } | |
OLD | NEW |