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 std::move(pdf_file), conversion_settings, |
102 conversion_settings, false /* print_text_with_gdi */)); | 103 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_++, emf_files_.back().Duplicate(), |
113 IPC::GetPlatformFileForTransit( | 118 base::Bind( |
114 emf_files_.back().GetPlatformFile(), false))); | 119 &ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesPageDone, |
120 base::Unretained(host_))); | |
115 } | 121 } |
116 } | 122 } |
117 | 123 |
118 // Returns true if all pages processed and client should not expect more | 124 // Returns true if all pages processed and client should not expect more |
119 // results. | 125 // results. |
120 bool OnPageProcessed() { | 126 bool OnPageProcessed() { |
121 --pages_in_progress_; | 127 --pages_in_progress_; |
122 GetMorePages(); | 128 GetMorePages(); |
123 if (pages_in_progress_ || current_page_ < page_count_) | 129 if (pages_in_progress_ || current_page_ < page_count_) |
124 return false; | 130 return false; |
125 Stop(); | 131 Stop(); |
126 return true; | 132 return true; |
127 } | 133 } |
128 | 134 |
129 base::File TakeNextFile() { | 135 base::File TakeNextFile() { |
130 DCHECK(!emf_files_.empty()); | 136 DCHECK(!emf_files_.empty()); |
131 base::File file; | 137 base::File file; |
132 if (!emf_files_.empty()) | 138 if (!emf_files_.empty()) |
133 file = std::move(emf_files_.front()); | 139 file = std::move(emf_files_.front()); |
134 emf_files_.pop(); | 140 emf_files_.pop(); |
135 return file; | 141 return file; |
136 } | 142 } |
137 | 143 |
138 void set_page_count(int page_count) { page_count_ = page_count; } | 144 void set_page_count(int page_count) { page_count_ = page_count; } |
139 bool has_page_count() { return page_count_ > 0; } | 145 bool has_page_count() { return page_count_ > 0; } |
140 | 146 |
141 private: | 147 private: |
142 void Stop() { | 148 void Stop() { host_->printing_.reset(); } |
143 host_->Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop()); | |
144 } | |
145 | 149 |
146 base::File CreateTempFile() { | 150 base::File CreateTempFile() { |
147 base::FilePath path; | 151 base::FilePath path; |
148 if (!base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &path)) | 152 if (!base::CreateTemporaryFileInDir(temp_dir_.GetPath(), &path)) |
149 return base::File(); | 153 return base::File(); |
150 return base::File(path, | 154 return base::File(path, |
151 base::File::FLAG_CREATE_ALWAYS | | 155 base::File::FLAG_CREATE_ALWAYS | |
152 base::File::FLAG_WRITE | | 156 base::File::FLAG_WRITE | |
153 base::File::FLAG_READ | | 157 base::File::FLAG_READ | |
154 base::File::FLAG_DELETE_ON_CLOSE | | 158 base::File::FLAG_DELETE_ON_CLOSE | |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 } | 201 } |
198 | 202 |
199 bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults( | 203 bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults( |
200 const std::string& printer_name) { | 204 const std::string& printer_name) { |
201 ReportUmaEvent(SERVICE_UTILITY_CAPS_REQUEST); | 205 ReportUmaEvent(SERVICE_UTILITY_CAPS_REQUEST); |
202 start_time_ = base::Time::Now(); | 206 start_time_ = base::Time::Now(); |
203 if (!StartProcess(true)) | 207 if (!StartProcess(true)) |
204 return false; | 208 return false; |
205 DCHECK(!waiting_for_reply_); | 209 DCHECK(!waiting_for_reply_); |
206 waiting_for_reply_ = true; | 210 waiting_for_reply_ = true; |
207 return Send(new ChromeUtilityMsg_GetPrinterCapsAndDefaults(printer_name)); | 211 printing()->GetPrinterCapsAndDefaults( |
212 printer_name, | |
213 base::Bind(&ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults, | |
214 base::Unretained(this), printer_name)); | |
215 return true; | |
208 } | 216 } |
209 | 217 |
210 bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults( | 218 bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults( |
211 const std::string& printer_name) { | 219 const std::string& printer_name) { |
212 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_REQUEST); | 220 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_REQUEST); |
213 start_time_ = base::Time::Now(); | 221 start_time_ = base::Time::Now(); |
214 if (!StartProcess(true)) | 222 if (!StartProcess(true)) |
215 return false; | 223 return false; |
216 DCHECK(!waiting_for_reply_); | 224 DCHECK(!waiting_for_reply_); |
217 waiting_for_reply_ = true; | 225 waiting_for_reply_ = true; |
218 return Send( | 226 printing()->GetPrinterSemanticCapsAndDefaults( |
219 new ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults(printer_name)); | 227 printer_name, |
228 base::Bind( | |
229 &ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults, | |
230 base::Unretained(this), printer_name)); | |
231 return true; | |
220 } | 232 } |
221 | 233 |
222 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { | 234 bool ServiceUtilityProcessHost::StartProcess(bool no_sandbox) { |
223 std::string mojo_channel_token = | 235 std::string mojo_channel_token = |
224 child_process_host_->CreateChannelMojo(mojo_child_token_); | 236 child_process_host_->CreateChannelMojo(mojo_child_token_); |
225 if (mojo_channel_token.empty()) | 237 if (mojo_channel_token.empty()) |
226 return false; | 238 return false; |
227 | 239 |
228 base::FilePath exe_path = GetUtilityProcessCmd(); | 240 base::FilePath exe_path = GetUtilityProcessCmd(); |
229 if (exe_path.empty()) { | 241 if (exe_path.empty()) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 if (success) { | 293 if (success) { |
282 mojo::edk::ChildProcessLaunched(process_.Handle(), | 294 mojo::edk::ChildProcessLaunched(process_.Handle(), |
283 std::move(parent_handle), | 295 std::move(parent_handle), |
284 mojo_child_token_); | 296 mojo_child_token_); |
285 } else { | 297 } else { |
286 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); | 298 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); |
287 } | 299 } |
288 return success; | 300 return success; |
289 } | 301 } |
290 | 302 |
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() { | 303 base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() { |
299 return ChildProcessHost::GetChildPath(ChildProcessHost::CHILD_NORMAL); | 304 return ChildProcessHost::GetChildPath(ChildProcessHost::CHILD_NORMAL); |
300 } | 305 } |
301 | 306 |
302 void ServiceUtilityProcessHost::OnChildDisconnected() { | 307 void ServiceUtilityProcessHost::OnChildDisconnected() { |
303 if (waiting_for_reply_) { | 308 if (waiting_for_reply_) { |
304 // If we are yet to receive a reply then notify the client that the | 309 // If we are yet to receive a reply then notify the client that the |
305 // child died. | 310 // child died. |
306 client_task_runner_->PostTask( | 311 client_task_runner_->PostTask( |
307 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); | 312 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); |
308 ReportUmaEvent(SERVICE_UTILITY_DISCONNECTED); | 313 ReportUmaEvent(SERVICE_UTILITY_DISCONNECTED); |
309 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityDisconnectTime", | 314 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityDisconnectTime", |
310 base::Time::Now() - start_time_); | 315 base::Time::Now() - start_time_); |
311 } | 316 } |
312 delete this; | 317 delete this; |
313 } | 318 } |
314 | 319 |
groby-ooo-7-16
2016/12/14 17:28:29
Does this still need to be an IPC::Listener?
tibell
2016/12/14 23:12:19
Unfortunately OnMessageReceived is defined pure vi
| |
315 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { | 320 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { |
316 bool handled = true; | 321 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 } | 322 } |
338 | 323 |
339 const base::Process& ServiceUtilityProcessHost::GetProcess() const { | 324 const base::Process& ServiceUtilityProcessHost::GetProcess() const { |
340 return process_; | 325 return process_; |
341 } | 326 } |
342 | 327 |
343 void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) { | 328 void ServiceUtilityProcessHost::OnMetafileSpooled(bool success) { |
344 if (!success || pdf_to_emf_state_->OnPageProcessed()) | 329 if (!success || pdf_to_emf_state_->OnPageProcessed()) |
345 OnPDFToEmfFinished(success); | 330 OnPDFToEmfFinished(success); |
346 } | 331 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 ReportUmaEvent(SERVICE_UTILITY_METAFILE_FAILED); | 368 ReportUmaEvent(SERVICE_UTILITY_METAFILE_FAILED); |
384 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityMetafileFailTime", | 369 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityMetafileFailTime", |
385 base::Time::Now() - start_time_); | 370 base::Time::Now() - start_time_); |
386 } | 371 } |
387 client_task_runner_->PostTask( | 372 client_task_runner_->PostTask( |
388 FROM_HERE, base::Bind(&Client::OnRenderPDFPagesToMetafileDone, | 373 FROM_HERE, base::Bind(&Client::OnRenderPDFPagesToMetafileDone, |
389 client_.get(), success)); | 374 client_.get(), success)); |
390 pdf_to_emf_state_.reset(); | 375 pdf_to_emf_state_.reset(); |
391 } | 376 } |
392 | 377 |
393 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsSucceeded( | 378 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults( |
394 const std::string& printer_name, | 379 const std::string& printer_name, |
395 const printing::PrinterCapsAndDefaults& caps_and_defaults) { | 380 const base::Optional<printing::PrinterCapsAndDefaults>& caps_and_defaults) { |
396 DCHECK(waiting_for_reply_); | 381 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; | 382 waiting_for_reply_ = false; |
401 client_task_runner_->PostTask( | 383 if (caps_and_defaults) { |
402 FROM_HERE, base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), | 384 ReportUmaEvent(SERVICE_UTILITY_CAPS_SUCCEEDED); |
403 true, printer_name, caps_and_defaults)); | 385 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsTime", |
386 base::Time::Now() - start_time_); | |
387 client_task_runner_->PostTask( | |
388 FROM_HERE, | |
389 base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), true, | |
390 printer_name, caps_and_defaults.value())); | |
391 } else { | |
392 ReportUmaEvent(SERVICE_UTILITY_CAPS_FAILED); | |
393 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsFailTime", | |
394 base::Time::Now() - start_time_); | |
395 client_task_runner_->PostTask( | |
396 FROM_HERE, | |
397 base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), false, | |
398 printer_name, printing::PrinterCapsAndDefaults())); | |
399 } | |
404 } | 400 } |
405 | 401 |
406 void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsSucceeded( | 402 void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults( |
407 const std::string& printer_name, | 403 const std::string& printer_name, |
408 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) { | 404 const base::Optional<printing::PrinterSemanticCapsAndDefaults>& |
405 caps_and_defaults) { | |
409 DCHECK(waiting_for_reply_); | 406 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; | 407 waiting_for_reply_ = false; |
414 client_task_runner_->PostTask( | 408 if (caps_and_defaults) { |
415 FROM_HERE, | 409 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_SUCCEEDED); |
416 base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, client_.get(), | 410 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsTime", |
417 true, printer_name, caps_and_defaults)); | 411 base::Time::Now() - start_time_); |
418 } | 412 client_task_runner_->PostTask( |
419 | 413 FROM_HERE, |
420 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsFailed( | 414 base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, client_.get(), |
421 const std::string& printer_name) { | 415 true, printer_name, caps_and_defaults.value())); |
422 DCHECK(waiting_for_reply_); | 416 } else { |
423 ReportUmaEvent(SERVICE_UTILITY_CAPS_FAILED); | 417 ReportUmaEvent(SERVICE_UTILITY_SEMANTIC_CAPS_FAILED); |
424 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilityCapsFailTime", | 418 UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsFailTime", |
425 base::Time::Now() - start_time_); | 419 base::Time::Now() - start_time_); |
426 waiting_for_reply_ = false; | 420 client_task_runner_->PostTask( |
427 client_task_runner_->PostTask( | 421 FROM_HERE, base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, |
428 FROM_HERE, | 422 client_.get(), false, printer_name, |
429 base::Bind(&Client::OnGetPrinterCapsAndDefaults, client_.get(), false, | 423 printing::PrinterSemanticCapsAndDefaults())); |
430 printer_name, printing::PrinterCapsAndDefaults())); | 424 } |
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 } | 425 } |
445 | 426 |
446 bool ServiceUtilityProcessHost::Client::MetafileAvailable(float scale_factor, | 427 bool ServiceUtilityProcessHost::Client::MetafileAvailable(float scale_factor, |
447 base::File file) { | 428 base::File file) { |
448 file.Seek(base::File::FROM_BEGIN, 0); | 429 file.Seek(base::File::FROM_BEGIN, 0); |
449 int64_t size = file.GetLength(); | 430 int64_t size = file.GetLength(); |
450 if (size <= 0) { | 431 if (size <= 0) { |
451 OnRenderPDFPagesToMetafileDone(false); | 432 OnRenderPDFPagesToMetafileDone(false); |
452 return false; | 433 return false; |
453 } | 434 } |
454 std::vector<char> data(size); | 435 std::vector<char> data(size); |
455 if (file.ReadAtCurrentPos(data.data(), data.size()) != size) { | 436 if (file.ReadAtCurrentPos(data.data(), data.size()) != size) { |
456 OnRenderPDFPagesToMetafileDone(false); | 437 OnRenderPDFPagesToMetafileDone(false); |
457 return false; | 438 return false; |
458 } | 439 } |
459 printing::Emf emf; | 440 printing::Emf emf; |
460 if (!emf.InitFromData(data.data(), data.size())) { | 441 if (!emf.InitFromData(data.data(), data.size())) { |
461 OnRenderPDFPagesToMetafileDone(false); | 442 OnRenderPDFPagesToMetafileDone(false); |
462 return false; | 443 return false; |
463 } | 444 } |
464 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); | 445 OnRenderPDFPagesToMetafilePageDone(scale_factor, emf); |
465 return true; | 446 return true; |
466 } | 447 } |
448 | |
449 printing::mojom::Printing* ServiceUtilityProcessHost::printing() { | |
450 if (!printing_) { | |
451 printing::mojom::PrintingFactoryPtr printing_factory; | |
452 child_process_host_->GetRemoteInterfaces()->GetInterface(&printing_factory); | |
453 // We don't care about calls to FontPreCaching so we pass a null pointer for | |
groby-ooo-7-16
2016/12/14 17:28:29
This comment seems out of date?
tibell
2016/12/14 23:12:19
printing::mojom::FontPreCachingPtr() does create a
| |
454 // the second argument. | |
455 printing_factory->MakePrinting(mojo::GetProxy(&printing_), | |
456 printing::mojom::FontPreCachingPtr()); | |
457 } | |
458 return printing_.get(); | |
459 } | |
OLD | NEW |