OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/printing/pdf_to_emf_converter.h" | 5 #include "chrome/browser/printing/pdf_to_emf_converter.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 ScopedTempFile emf_; | 140 ScopedTempFile emf_; |
141 }; | 141 }; |
142 | 142 |
143 virtual ~PdfToEmfUtilityProcessHostClient(); | 143 virtual ~PdfToEmfUtilityProcessHostClient(); |
144 | 144 |
145 bool Send(IPC::Message* msg); | 145 bool Send(IPC::Message* msg); |
146 | 146 |
147 // Message handlers. | 147 // Message handlers. |
148 void OnProcessStarted(); | 148 void OnProcessStarted(); |
149 void OnPageCount(int page_count); | 149 void OnPageCount(int page_count); |
150 void OnPageDone(bool success, double scale_factor); | 150 void OnPageDone(bool success, float scale_factor); |
151 | 151 |
152 void OnFailed(); | 152 void OnFailed(); |
153 void OnTempPdfReady(ScopedTempFile pdf); | 153 void OnTempPdfReady(ScopedTempFile pdf); |
154 void OnTempEmfReady(GetPageCallbackData* callback_data, ScopedTempFile emf); | 154 void OnTempEmfReady(GetPageCallbackData* callback_data, ScopedTempFile emf); |
155 | 155 |
156 scoped_refptr<RefCountedTempDir> temp_dir_; | 156 scoped_refptr<RefCountedTempDir> temp_dir_; |
157 | 157 |
158 // Used to suppress callbacks after PdfToEmfConverterImpl is deleted. | 158 // Used to suppress callbacks after PdfToEmfConverterImpl is deleted. |
159 base::WeakPtr<PdfToEmfConverterImpl> converter_; | 159 base::WeakPtr<PdfToEmfConverterImpl> converter_; |
160 PdfRenderSettings settings_; | 160 PdfRenderSettings settings_; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 base::ProcessHandle process = utility_process_host_->GetData().handle; | 379 base::ProcessHandle process = utility_process_host_->GetData().handle; |
380 IPC::PlatformFileForTransit transit = | 380 IPC::PlatformFileForTransit transit = |
381 IPC::GetFileHandleForProcess(emf->GetPlatformFile(), process, false); | 381 IPC::GetFileHandleForProcess(emf->GetPlatformFile(), process, false); |
382 callback_data->set_emf(emf.Pass()); | 382 callback_data->set_emf(emf.Pass()); |
383 // Should reply with OnPageDone(). | 383 // Should reply with OnPageDone(). |
384 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage( | 384 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage( |
385 callback_data->page_number(), transit)); | 385 callback_data->page_number(), transit)); |
386 } | 386 } |
387 | 387 |
388 void PdfToEmfUtilityProcessHostClient::OnPageDone(bool success, | 388 void PdfToEmfUtilityProcessHostClient::OnPageDone(bool success, |
389 double scale_factor) { | 389 float scale_factor) { |
390 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 390 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
391 if (get_page_callbacks_.empty()) | 391 if (get_page_callbacks_.empty()) |
392 return OnFailed(); | 392 return OnFailed(); |
393 scoped_ptr<MetafilePlayer> emf; | 393 scoped_ptr<MetafilePlayer> emf; |
394 GetPageCallbackData& data = get_page_callbacks_.front(); | 394 GetPageCallbackData& data = get_page_callbacks_.front(); |
395 if (success) | 395 if (success) |
396 emf.reset(new LazyEmf(temp_dir_, data.emf().Pass())); | 396 emf.reset(new LazyEmf(temp_dir_, data.emf().Pass())); |
397 BrowserThread::PostTask(BrowserThread::UI, | 397 BrowserThread::PostTask(BrowserThread::UI, |
398 FROM_HERE, | 398 FROM_HERE, |
399 base::Bind(&PdfToEmfConverterImpl::RunCallback, | 399 base::Bind(&PdfToEmfConverterImpl::RunCallback, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 return utility_process_host_->Send(msg); | 443 return utility_process_host_->Send(msg); |
444 delete msg; | 444 delete msg; |
445 return false; | 445 return false; |
446 } | 446 } |
447 | 447 |
448 void PdfToEmfUtilityProcessHostClient::OnFailed() { | 448 void PdfToEmfUtilityProcessHostClient::OnFailed() { |
449 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 449 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
450 if (!start_callback_.is_null()) | 450 if (!start_callback_.is_null()) |
451 OnPageCount(0); | 451 OnPageCount(0); |
452 while (!get_page_callbacks_.empty()) | 452 while (!get_page_callbacks_.empty()) |
453 OnPageDone(false, 0.0); | 453 OnPageDone(false, 0.0f); |
454 utility_process_host_.reset(); | 454 utility_process_host_.reset(); |
455 } | 455 } |
456 | 456 |
457 PdfToEmfConverterImpl::PdfToEmfConverterImpl() : weak_ptr_factory_(this) { | 457 PdfToEmfConverterImpl::PdfToEmfConverterImpl() : weak_ptr_factory_(this) { |
458 } | 458 } |
459 | 459 |
460 PdfToEmfConverterImpl::~PdfToEmfConverterImpl() { | 460 PdfToEmfConverterImpl::~PdfToEmfConverterImpl() { |
461 if (utility_client_.get()) | 461 if (utility_client_.get()) |
462 utility_client_->Stop(); | 462 utility_client_->Stop(); |
463 } | 463 } |
(...skipping 22 matching lines...) Expand all Loading... |
486 | 486 |
487 PdfToEmfConverter::~PdfToEmfConverter() { | 487 PdfToEmfConverter::~PdfToEmfConverter() { |
488 } | 488 } |
489 | 489 |
490 // static | 490 // static |
491 scoped_ptr<PdfToEmfConverter> PdfToEmfConverter::CreateDefault() { | 491 scoped_ptr<PdfToEmfConverter> PdfToEmfConverter::CreateDefault() { |
492 return scoped_ptr<PdfToEmfConverter>(new PdfToEmfConverterImpl()); | 492 return scoped_ptr<PdfToEmfConverter>(new PdfToEmfConverterImpl()); |
493 } | 493 } |
494 | 494 |
495 } // namespace printing | 495 } // namespace printing |
OLD | NEW |