Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/printing/pdf_to_emf_converter.cc

Issue 2633573002: Add Postscript Printing (Closed)
Patch Set: Merge Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/printing/pdf_to_emf_converter.h ('k') | chrome/browser/printing/print_job.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 private: 84 private:
85 mutable scoped_refptr<RefCountedTempDir> temp_dir_; 85 mutable scoped_refptr<RefCountedTempDir> temp_dir_;
86 mutable ScopedTempFile file_; // Mutable because of consts in base class. 86 mutable ScopedTempFile file_; // Mutable because of consts in base class.
87 87
88 bool GetDataAsVector(std::vector<char>* buffer) const override; 88 bool GetDataAsVector(std::vector<char>* buffer) const override;
89 bool SaveTo(base::File* file) const override; 89 bool SaveTo(base::File* file) const override;
90 90
91 DISALLOW_COPY_AND_ASSIGN(LazyEmf); 91 DISALLOW_COPY_AND_ASSIGN(LazyEmf);
92 }; 92 };
93 93
94 // Postscript metafile subclass to override SafePlayback.
95 class PostScriptMetaFile : public LazyEmf {
96 public:
97 PostScriptMetaFile(const scoped_refptr<RefCountedTempDir>& temp_dir,
98 ScopedTempFile file)
99 : LazyEmf(temp_dir, std::move(file)) {}
100 ~PostScriptMetaFile() override;
101
102 protected:
103 // MetafilePlayer:
104 bool SafePlayback(HDC hdc) const override;
105
106 DISALLOW_COPY_AND_ASSIGN(PostScriptMetaFile);
107 };
108
94 // Class for converting PDF to another format for printing (Emf, Postscript). 109 // Class for converting PDF to another format for printing (Emf, Postscript).
95 // Class uses 3 threads: UI, IO and FILE. 110 // Class uses 3 threads: UI, IO and FILE.
96 // Internal workflow is following: 111 // Internal workflow is following:
97 // 1. Create instance on the UI thread. (files_, settings_,) 112 // 1. Create instance on the UI thread. (files_, settings_,)
98 // 2. Create pdf file on the FILE thread. 113 // 2. Create pdf file on the FILE thread.
99 // 3. Start utility process and start conversion on the IO thread. 114 // 3. Start utility process and start conversion on the IO thread.
100 // 4. Utility process returns page count. 115 // 4. Utility process returns page count.
101 // 5. For each page: 116 // 5. For each page:
102 // 1. Clients requests page with file handle to a temp file. 117 // 1. Clients requests page with file handle to a temp file.
103 // 2. Utility converts the page, save it to the file and reply. 118 // 2. Utility converts the page, save it to the file and reply.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 int page_number_; 168 int page_number_;
154 169
155 PdfConverter::GetPageCallback callback_; 170 PdfConverter::GetPageCallback callback_;
156 ScopedTempFile file_; 171 ScopedTempFile file_;
157 172
158 DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData); 173 DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData);
159 }; 174 };
160 175
161 ~PdfConverterUtilityProcessHostClient() override; 176 ~PdfConverterUtilityProcessHostClient() override;
162 177
178 bool OnMessageReceived(const IPC::Message& message) override;
179
163 // Helper functions: must be overridden by subclasses 180 // Helper functions: must be overridden by subclasses
164 // Set the process name 181 // Set the process name
165 virtual base::string16 GetName() const = 0; 182 virtual base::string16 GetName() const;
166 // Create a metafileplayer subclass file from a temporary file. 183 // Create a metafileplayer subclass file from a temporary file.
167 virtual std::unique_ptr<MetafilePlayer> GetFileFromTemp( 184 virtual std::unique_ptr<MetafilePlayer> GetFileFromTemp(
168 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread> 185 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
169 temp_file) = 0; 186 temp_file);
170 // Send the messages to Start, GetPage, and Stop. 187 // Send the messages to Start, GetPage, and Stop.
171 virtual void SendStartMessage(IPC::PlatformFileForTransit transit) = 0; 188 virtual void SendStartMessage(IPC::PlatformFileForTransit transit);
172 virtual void SendGetPageMessage(int page_number, 189 virtual void SendGetPageMessage(int page_number,
173 IPC::PlatformFileForTransit transit) = 0; 190 IPC::PlatformFileForTransit transit);
174 virtual void SendStopMessage() = 0; 191 virtual void SendStopMessage();
175 192
176 // Message handlers: 193 // Message handlers:
177 void OnPageCount(int page_count); 194 void OnPageCount(int page_count);
178 void OnPageDone(bool success, float scale_factor); 195 void OnPageDone(bool success, float scale_factor);
179 196
180 void OnFailed(); 197 void OnFailed();
181 void OnTempPdfReady(ScopedTempFile pdf); 198 void OnTempPdfReady(ScopedTempFile pdf);
182 void OnTempFileReady(GetPageCallbackData* callback_data, 199 void OnTempFileReady(GetPageCallbackData* callback_data,
183 ScopedTempFile temp_file); 200 ScopedTempFile temp_file);
184 201
202 // Additional message handler needed for Pdf to Emf
203 void OnPreCacheFontCharacters(const LOGFONT& log_font,
204 const base::string16& characters);
205
185 scoped_refptr<RefCountedTempDir> temp_dir_; 206 scoped_refptr<RefCountedTempDir> temp_dir_;
186 207
187 // Used to suppress callbacks after PdfConverter is deleted. 208 // Used to suppress callbacks after PdfConverter is deleted.
188 base::WeakPtr<PdfConverterImpl> converter_; 209 base::WeakPtr<PdfConverterImpl> converter_;
189 PdfRenderSettings settings_; 210 PdfRenderSettings settings_;
190 211
191 // Document loaded callback. 212 // Document loaded callback.
192 PdfConverter::StartCallback start_callback_; 213 PdfConverter::StartCallback start_callback_;
193 214
194 // Process host for IPC. 215 // Process host for IPC.
195 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; 216 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
196 217
197 // Queue of callbacks for GetPage() requests. Utility process should reply 218 // Queue of callbacks for GetPage() requests. Utility process should reply
198 // with PageDone in the same order as requests were received. 219 // with PageDone in the same order as requests were received.
199 // Use containers that keeps element pointers valid after push() and pop(). 220 // Use containers that keeps element pointers valid after push() and pop().
200 using GetPageCallbacks = std::queue<GetPageCallbackData>; 221 using GetPageCallbacks = std::queue<GetPageCallbackData>;
201 GetPageCallbacks get_page_callbacks_; 222 GetPageCallbacks get_page_callbacks_;
223
224 DISALLOW_COPY_AND_ASSIGN(PdfConverterUtilityProcessHostClient);
202 }; 225 };
203 226
204 // Converts PDF into Emf. 227 std::unique_ptr<MetafilePlayer>
205 class PdfToEmfUtilityProcessHostClient 228 PdfConverterUtilityProcessHostClient::GetFileFromTemp(
206 : public PdfConverterUtilityProcessHostClient { 229 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
207 public: 230 temp_file) {
208 PdfToEmfUtilityProcessHostClient(base::WeakPtr<PdfConverterImpl> converter, 231 if (settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 ||
209 const PdfRenderSettings& settings) 232 settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3) {
210 : PdfConverterUtilityProcessHostClient(converter, settings) {} 233 return base::MakeUnique<PostScriptMetaFile>(temp_dir_,
211 234 std::move(temp_file));
212 bool OnMessageReceived(const IPC::Message& message) override; 235 }
213 236 return base::MakeUnique<LazyEmf>(temp_dir_, std::move(temp_file));
214 private: 237 }
215 ~PdfToEmfUtilityProcessHostClient() override;
216 // Helpers to send messages and set process name
217 base::string16 GetName() const override;
218 std::unique_ptr<MetafilePlayer> GetFileFromTemp(
219 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
220 temp_file) override;
221 void SendStartMessage(IPC::PlatformFileForTransit transit) override;
222 void SendGetPageMessage(int page_number,
223 IPC::PlatformFileForTransit transit) override;
224 void SendStopMessage() override;
225
226 // Additional message handler needed for Pdf to Emf
227 void OnPreCacheFontCharacters(const LOGFONT& log_font,
228 const base::string16& characters);
229
230 DISALLOW_COPY_AND_ASSIGN(PdfToEmfUtilityProcessHostClient);
231 };
232 238
233 class PdfConverterImpl : public PdfConverter { 239 class PdfConverterImpl : public PdfConverter {
234 public: 240 public:
235 PdfConverterImpl(); 241 PdfConverterImpl();
236 242
237 ~PdfConverterImpl() override; 243 ~PdfConverterImpl() override;
238 244
245 base::WeakPtr<PdfConverterImpl> GetWeakPtr() {
246 return weak_ptr_factory_.GetWeakPtr();
247 }
248
239 void Start(const scoped_refptr<base::RefCountedMemory>& data, 249 void Start(const scoped_refptr<base::RefCountedMemory>& data,
240 const PdfRenderSettings& conversion_settings, 250 const PdfRenderSettings& conversion_settings,
241 const StartCallback& start_callback) override; 251 const StartCallback& start_callback);
242 252
243 void GetPage(int page_number, 253 void GetPage(int page_number,
244 const GetPageCallback& get_page_callback) override; 254 const GetPageCallback& get_page_callback) override;
245 255
246 // Helps to cancel callbacks if this object is destroyed. 256 // Helps to cancel callbacks if this object is destroyed.
247 void RunCallback(const base::Closure& callback); 257 void RunCallback(const base::Closure& callback);
248 258
249 protected: 259 void Start(
260 const scoped_refptr<PdfConverterUtilityProcessHostClient>& utility_client,
261 const scoped_refptr<base::RefCountedMemory>& data,
262 const StartCallback& start_callback);
263
264 private:
250 scoped_refptr<PdfConverterUtilityProcessHostClient> utility_client_; 265 scoped_refptr<PdfConverterUtilityProcessHostClient> utility_client_;
251 266
252 private: 267 base::WeakPtrFactory<PdfConverterImpl> weak_ptr_factory_;
268
253 DISALLOW_COPY_AND_ASSIGN(PdfConverterImpl); 269 DISALLOW_COPY_AND_ASSIGN(PdfConverterImpl);
254 }; 270 };
255 271
256 class PdfToEmfConverterImpl : public PdfConverterImpl {
257 public:
258 PdfToEmfConverterImpl();
259
260 ~PdfToEmfConverterImpl() override;
261
262 void Start(const scoped_refptr<base::RefCountedMemory>& data,
263 const PdfRenderSettings& conversion_settings,
264 const StartCallback& start_callback) override;
265
266 private:
267 base::WeakPtrFactory<PdfToEmfConverterImpl> weak_ptr_factory_;
268
269 DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverterImpl);
270 };
271
272 ScopedTempFile CreateTempFile(scoped_refptr<RefCountedTempDir>* temp_dir) { 272 ScopedTempFile CreateTempFile(scoped_refptr<RefCountedTempDir>* temp_dir) {
273 if (!temp_dir->get()) 273 if (!temp_dir->get())
274 *temp_dir = new RefCountedTempDir(); 274 *temp_dir = new RefCountedTempDir();
275 ScopedTempFile file; 275 ScopedTempFile file;
276 if (!(*temp_dir)->IsValid()) 276 if (!(*temp_dir)->IsValid())
277 return file; 277 return file;
278 base::FilePath path; 278 base::FilePath path;
279 if (!base::CreateTemporaryFileInDir((*temp_dir)->GetPath(), &path)) { 279 if (!base::CreateTemporaryFileInDir((*temp_dir)->GetPath(), &path)) {
280 PLOG(ERROR) << "Failed to create file in " 280 PLOG(ERROR) << "Failed to create file in "
281 << (*temp_dir)->GetPath().value(); 281 << (*temp_dir)->GetPath().value();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 file_->Seek(base::File::FROM_BEGIN, 0); 340 file_->Seek(base::File::FROM_BEGIN, 0);
341 int64_t size = file_->GetLength(); 341 int64_t size = file_->GetLength();
342 if (size <= 0) 342 if (size <= 0)
343 return false; 343 return false;
344 std::vector<char> data(size); 344 std::vector<char> data(size);
345 if (file_->ReadAtCurrentPos(data.data(), data.size()) != size) 345 if (file_->ReadAtCurrentPos(data.data(), data.size()) != size)
346 return false; 346 return false;
347 return emf->InitFromData(data.data(), data.size()); 347 return emf->InitFromData(data.data(), data.size());
348 } 348 }
349 349
350 PostScriptMetaFile::~PostScriptMetaFile() {
351 }
352
353 bool PostScriptMetaFile::SafePlayback(HDC hdc) const {
354 // TODO(thestig): Fix destruction of metafiles. For some reasons
355 // instances of Emf are not deleted. https://crbug.com/260806
356 // It's known that the Emf going to be played just once to a printer. So just
357 // release |file_| before returning.
358 Emf emf;
359 if (!LoadEmf(&emf)) {
360 Close();
361 return false;
362 }
363
364 {
365 // Ensure enumerator destruction before calling Close() below.
366 Emf::Enumerator emf_enum(emf, nullptr, nullptr);
367 for (const Emf::Record& record : emf_enum) {
368 auto* emf_record = record.record();
369 if (emf_record->iType != EMR_GDICOMMENT)
370 continue;
371
372 const EMRGDICOMMENT* comment =
373 reinterpret_cast<const EMRGDICOMMENT*>(emf_record);
374 const char* data = reinterpret_cast<const char*>(comment->Data);
375 const uint16_t* ptr = reinterpret_cast<const uint16_t*>(data);
376 int ret = ExtEscape(hdc, PASSTHROUGH, 2 + *ptr, data, 0, nullptr);
377 DCHECK_EQ(*ptr, ret);
378 }
379 }
380 Close();
381 return true;
382 }
383
350 PdfConverterUtilityProcessHostClient::PdfConverterUtilityProcessHostClient( 384 PdfConverterUtilityProcessHostClient::PdfConverterUtilityProcessHostClient(
351 base::WeakPtr<PdfConverterImpl> converter, 385 base::WeakPtr<PdfConverterImpl> converter,
352 const PdfRenderSettings& settings) 386 const PdfRenderSettings& settings)
353 : converter_(converter), settings_(settings) {} 387 : converter_(converter), settings_(settings) {}
354 388
355 PdfConverterUtilityProcessHostClient::~PdfConverterUtilityProcessHostClient() {} 389 PdfConverterUtilityProcessHostClient::~PdfConverterUtilityProcessHostClient() {}
356 390
357 void PdfConverterUtilityProcessHostClient::Start( 391 void PdfConverterUtilityProcessHostClient::Start(
358 const scoped_refptr<base::RefCountedMemory>& data, 392 const scoped_refptr<base::RefCountedMemory>& data,
359 const PdfConverter::StartCallback& start_callback) { 393 const PdfConverter::StartCallback& start_callback) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 base::Bind(&PdfConverterImpl::RunCallback, converter_, 491 base::Bind(&PdfConverterImpl::RunCallback, converter_,
458 base::Bind(data.callback(), data.page_number(), scale_factor, 492 base::Bind(data.callback(), data.page_number(), scale_factor,
459 base::Passed(&file)))); 493 base::Passed(&file))));
460 get_page_callbacks_.pop(); 494 get_page_callbacks_.pop();
461 } 495 }
462 496
463 void PdfConverterUtilityProcessHostClient::Stop() { 497 void PdfConverterUtilityProcessHostClient::Stop() {
464 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 498 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
465 BrowserThread::PostTask( 499 BrowserThread::PostTask(
466 BrowserThread::IO, FROM_HERE, 500 BrowserThread::IO, FROM_HERE,
467 base::Bind(&PdfToEmfUtilityProcessHostClient::Stop, this)); 501 base::Bind(&PdfConverterUtilityProcessHostClient::Stop, this));
468 return; 502 return;
469 } 503 }
470 SendStopMessage(); 504 SendStopMessage();
471 } 505 }
472 506
473 void PdfConverterUtilityProcessHostClient::OnProcessCrashed(int exit_code) { 507 void PdfConverterUtilityProcessHostClient::OnProcessCrashed(int exit_code) {
474 OnFailed(); 508 OnFailed();
475 } 509 }
476 510
477 void PdfConverterUtilityProcessHostClient::OnProcessLaunchFailed( 511 void PdfConverterUtilityProcessHostClient::OnProcessLaunchFailed(
(...skipping 10 matching lines...) Expand all
488 522
489 void PdfConverterUtilityProcessHostClient::OnFailed() { 523 void PdfConverterUtilityProcessHostClient::OnFailed() {
490 DCHECK_CURRENTLY_ON(BrowserThread::IO); 524 DCHECK_CURRENTLY_ON(BrowserThread::IO);
491 if (!start_callback_.is_null()) 525 if (!start_callback_.is_null())
492 OnPageCount(0); 526 OnPageCount(0);
493 while (!get_page_callbacks_.empty()) 527 while (!get_page_callbacks_.empty())
494 OnPageDone(false, 0.0f); 528 OnPageDone(false, 0.0f);
495 utility_process_host_.reset(); 529 utility_process_host_.reset();
496 } 530 }
497 531
498 // PDF to Emf
499 PdfToEmfUtilityProcessHostClient::~PdfToEmfUtilityProcessHostClient() {}
500 532
501 void PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters( 533 void PdfConverterUtilityProcessHostClient::OnPreCacheFontCharacters(
502 const LOGFONT& font, 534 const LOGFONT& font,
503 const base::string16& str) { 535 const base::string16& str) {
504 // TODO(scottmg): pdf/ppapi still require the renderer to be able to precache 536 // TODO(scottmg): pdf/ppapi still require the renderer to be able to precache
505 // GDI fonts (http://crbug.com/383227), even when using DirectWrite. 537 // GDI fonts (http://crbug.com/383227), even when using DirectWrite.
506 // Eventually this shouldn't be added and should be moved to 538 // Eventually this shouldn't be added and should be moved to
507 // FontCacheDispatcher too. http://crbug.com/356346. 539 // FontCacheDispatcher too. http://crbug.com/356346.
508 540
509 // First, comments from FontCacheDispatcher::OnPreCacheFont do apply here too. 541 // First, comments from FontCacheDispatcher::OnPreCacheFont do apply here too.
510 // Except that for True Type fonts, 542 // Except that for True Type fonts,
511 // GetTextMetrics will not load the font in memory. 543 // GetTextMetrics will not load the font in memory.
(...skipping 11 matching lines...) Expand all
523 555
524 SelectObject(hdc, old_font); 556 SelectObject(hdc, old_font);
525 DeleteObject(font_handle); 557 DeleteObject(font_handle);
526 558
527 HENHMETAFILE metafile = CloseEnhMetaFile(hdc); 559 HENHMETAFILE metafile = CloseEnhMetaFile(hdc);
528 560
529 if (metafile) 561 if (metafile)
530 DeleteEnhMetaFile(metafile); 562 DeleteEnhMetaFile(metafile);
531 } 563 }
532 564
533 bool PdfToEmfUtilityProcessHostClient::OnMessageReceived( 565 bool PdfConverterUtilityProcessHostClient::OnMessageReceived(
534 const IPC::Message& message) { 566 const IPC::Message& message) {
535 bool handled = true; 567 bool handled = true;
536 IPC_BEGIN_MESSAGE_MAP(PdfToEmfUtilityProcessHostClient, message) 568 IPC_BEGIN_MESSAGE_MAP(PdfConverterUtilityProcessHostClient, message)
537 IPC_MESSAGE_HANDLER( 569 IPC_MESSAGE_HANDLER(
538 ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, OnPageCount) 570 ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, OnPageCount)
539 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone, 571 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone,
540 OnPageDone) 572 OnPageDone)
541 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PreCacheFontCharacters, 573 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PreCacheFontCharacters,
542 OnPreCacheFontCharacters) 574 OnPreCacheFontCharacters)
543 IPC_MESSAGE_UNHANDLED(handled = false) 575 IPC_MESSAGE_UNHANDLED(handled = false)
544 IPC_END_MESSAGE_MAP() 576 IPC_END_MESSAGE_MAP()
545 return handled; 577 return handled;
546 } 578 }
547 579
548 base::string16 PdfToEmfUtilityProcessHostClient::GetName() const { 580 base::string16 PdfConverterUtilityProcessHostClient::GetName() const {
549 return l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_EMF_CONVERTOR_NAME); 581 return l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PDF_CONVERTOR_NAME);
550 } 582 }
551 583
552 std::unique_ptr<MetafilePlayer> 584 void PdfConverterUtilityProcessHostClient::SendGetPageMessage(
553 PdfToEmfUtilityProcessHostClient::GetFileFromTemp(
554 std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
555 temp_file) {
556 return base::MakeUnique<LazyEmf>(temp_dir_, std::move(temp_file));
557 }
558
559 void PdfToEmfUtilityProcessHostClient::SendGetPageMessage(
560 int page_number, 585 int page_number,
561 IPC::PlatformFileForTransit transit) { 586 IPC::PlatformFileForTransit transit) {
562 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage(page_number, 587 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage(page_number,
563 transit)); 588 transit));
564 } 589 }
565 590
566 void PdfToEmfUtilityProcessHostClient::SendStartMessage( 591 void PdfConverterUtilityProcessHostClient::SendStartMessage(
567 IPC::PlatformFileForTransit transit) { 592 IPC::PlatformFileForTransit transit) {
568 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles(transit, settings_)); 593 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles(transit, settings_));
569 } 594 }
570 595
571 void PdfToEmfUtilityProcessHostClient::SendStopMessage() { 596 void PdfConverterUtilityProcessHostClient::SendStopMessage() {
572 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop()); 597 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop());
573 } 598 }
599 /*void PdfToPostScriptUtilityProcessHostClient::OnPageDone(bool success) {
600 PdfConverterUtilityProcessHostClient::OnPageDone(success, 0.0f);
601 }
602 */
603 // Pdf Converter Impl and subclasses
604 PdfConverterImpl::PdfConverterImpl() : weak_ptr_factory_(this) {}
574 605
575 // Pdf Converter Impl and subclasses 606 PdfConverterImpl::~PdfConverterImpl() {
576 PdfConverterImpl::PdfConverterImpl() {} 607 if (utility_client_.get())
608 utility_client_->Stop();
609 }
577 610
578 PdfConverterImpl::~PdfConverterImpl() {} 611 void PdfConverterImpl::Start(
579 612 const scoped_refptr<PdfConverterUtilityProcessHostClient>& utility_client,
580 void PdfConverterImpl::Start(const scoped_refptr<base::RefCountedMemory>& data, 613 const scoped_refptr<base::RefCountedMemory>& data,
581 const PdfRenderSettings& conversion_settings, 614 const StartCallback& start_callback) {
582 const StartCallback& start_callback) { 615 DCHECK(!utility_client_);
583 DCHECK(!utility_client_.get()); 616 utility_client_ = utility_client;
617 utility_client_->Start(data, start_callback);
584 } 618 }
585 619
586 void PdfConverterImpl::GetPage(int page_number, 620 void PdfConverterImpl::GetPage(int page_number,
587 const GetPageCallback& get_page_callback) { 621 const GetPageCallback& get_page_callback) {
588 utility_client_->GetPage(page_number, get_page_callback); 622 utility_client_->GetPage(page_number, get_page_callback);
589 } 623 }
590 624
591 void PdfConverterImpl::RunCallback(const base::Closure& callback) { 625 void PdfConverterImpl::RunCallback(const base::Closure& callback) {
592 DCHECK_CURRENTLY_ON(BrowserThread::UI); 626 DCHECK_CURRENTLY_ON(BrowserThread::UI);
593 callback.Run(); 627 callback.Run();
594 } 628 }
595 629
596 PdfToEmfConverterImpl::PdfToEmfConverterImpl() : weak_ptr_factory_(this) {}
597
598 PdfToEmfConverterImpl::~PdfToEmfConverterImpl() {
599 if (utility_client_.get())
600 utility_client_->Stop();
601 }
602
603 void PdfToEmfConverterImpl::Start(
604 const scoped_refptr<base::RefCountedMemory>& data,
605 const PdfRenderSettings& conversion_settings,
606 const StartCallback& start_callback) {
607 DCHECK(!utility_client_.get());
608 utility_client_ = new PdfToEmfUtilityProcessHostClient(
609 weak_ptr_factory_.GetWeakPtr(), conversion_settings);
610 utility_client_->Start(data, start_callback);
611 }
612
613 } // namespace 630 } // namespace
614 631
615 PdfConverter::~PdfConverter() {} 632 PdfConverter::~PdfConverter() {}
616 633
617 // static 634 // static
618 std::unique_ptr<PdfConverter> PdfConverter::CreatePdfToEmfConverter() { 635 std::unique_ptr<PdfConverter> PdfConverter::StartPdfConverter(
619 return base::MakeUnique<PdfToEmfConverterImpl>(); 636 const scoped_refptr<base::RefCountedMemory>& data,
637 const PdfRenderSettings& conversion_settings,
638 const StartCallback& start_callback) {
639 std::unique_ptr<PdfConverterImpl> converter =
640 base::MakeUnique<PdfConverterImpl>();
641 converter->Start(
642 new PdfConverterUtilityProcessHostClient(converter->GetWeakPtr(),
643 conversion_settings),
644 data, start_callback);
645 return std::move(converter);
620 } 646 }
621 647
622 } // namespace printing 648 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/pdf_to_emf_converter.h ('k') | chrome/browser/printing/print_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698