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

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

Issue 2477283002: Convert printing IPCs to Mojo
Patch Set: git cl format Created 4 years 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
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>
11 #include <queue> 11 #include <queue>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/files/file.h" 15 #include "base/files/file.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/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "chrome/common/chrome_utility_messages.h" 22 #include "chrome/common/chrome_utility_messages.h"
23 #include "chrome/common/chrome_utility_printing_messages.h"
24 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
24 #include "components/printing/common/printing.mojom.h"
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/child_process_data.h" 26 #include "content/public/browser/child_process_data.h"
27 #include "content/public/browser/utility_process_host.h" 27 #include "content/public/browser/utility_process_host.h"
28 #include "content/public/browser/utility_process_host_client.h" 28 #include "content/public/browser/utility_process_host_client.h"
29 #include "mojo/public/cpp/bindings/binding.h"
30 #include "mojo/public/cpp/system/platform_handle.h"
29 #include "printing/emf_win.h" 31 #include "printing/emf_win.h"
30 #include "printing/pdf_render_settings.h" 32 #include "printing/pdf_render_settings.h"
33 #include "services/service_manager/public/cpp/interface_provider.h"
31 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
32 35
33 namespace printing { 36 namespace printing {
34 37
35 namespace { 38 namespace {
36 39
37 using content::BrowserThread; 40 using content::BrowserThread;
38 41
39 class PdfToEmfConverterImpl; 42 class PdfToEmfConverterImpl;
40 43
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // 1. Create instance on the UI thread. (files_, settings_,) 97 // 1. Create instance on the UI thread. (files_, settings_,)
95 // 2. Create pdf file on the FILE thread. 98 // 2. Create pdf file on the FILE thread.
96 // 3. Start utility process and start conversion on the IO thread. 99 // 3. Start utility process and start conversion on the IO thread.
97 // 4. Utility process returns page count. 100 // 4. Utility process returns page count.
98 // 5. For each page: 101 // 5. For each page:
99 // 1. Clients requests page with file handle to a temp file. 102 // 1. Clients requests page with file handle to a temp file.
100 // 2. Utility converts the page, save it to the file and reply. 103 // 2. Utility converts the page, save it to the file and reply.
101 // 104 //
102 // All these steps work sequentially, so no data should be accessed 105 // All these steps work sequentially, so no data should be accessed
103 // simultaneously by several threads. 106 // simultaneously by several threads.
104 class PdfToEmfUtilityProcessHostClient 107 class PdfToEmfUtilityProcessHostClient
Sam McNally 2016/12/12 06:09:20 Consider using UtilityProcessMojoClient to abstrac
tibell 2016/12/13 23:41:54 Done.
105 : public content::UtilityProcessHostClient { 108 : public content::UtilityProcessHostClient,
109 public mojom::FontPreCaching {
106 public: 110 public:
107 PdfToEmfUtilityProcessHostClient( 111 PdfToEmfUtilityProcessHostClient(
108 base::WeakPtr<PdfToEmfConverterImpl> converter, 112 base::WeakPtr<PdfToEmfConverterImpl> converter,
109 const PdfRenderSettings& settings); 113 const PdfRenderSettings& settings);
110 114
111 void Start(const scoped_refptr<base::RefCountedMemory>& data, 115 void Start(const scoped_refptr<base::RefCountedMemory>& data,
112 bool print_text_with_gdi, 116 bool print_text_with_gdi,
113 const PdfToEmfConverter::StartCallback& start_callback); 117 const PdfToEmfConverter::StartCallback& start_callback);
114 118
115 void GetPage(int page_number, 119 void GetPage(int page_number,
116 const PdfToEmfConverter::GetPageCallback& get_page_callback); 120 const PdfToEmfConverter::GetPageCallback& get_page_callback);
117 121
118 void Stop(); 122 void Stop();
119 123
120 // Needs to be public to handle ChromeUtilityHostMsg_PreCacheFontCharacters
121 // sync message replies.
122 bool Send(IPC::Message* msg);
123
124 // UtilityProcessHostClient implementation. 124 // UtilityProcessHostClient implementation.
125 void OnProcessCrashed(int exit_code) override; 125 void OnProcessCrashed(int exit_code) override;
126 void OnProcessLaunchFailed(int exit_code) override; 126 void OnProcessLaunchFailed(int exit_code) override;
127 bool OnMessageReceived(const IPC::Message& message) override; 127 bool OnMessageReceived(const IPC::Message& message) override;
128 128
129 private: 129 private:
130 class GetPageCallbackData { 130 class GetPageCallbackData {
131 public: 131 public:
132 GetPageCallbackData(int page_number, 132 GetPageCallbackData(int page_number,
133 PdfToEmfConverter::GetPageCallback callback) 133 PdfToEmfConverter::GetPageCallback callback)
(...skipping 23 matching lines...) Expand all
157 ScopedTempFile emf_; 157 ScopedTempFile emf_;
158 158
159 DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData); 159 DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData);
160 }; 160 };
161 161
162 ~PdfToEmfUtilityProcessHostClient() override; 162 ~PdfToEmfUtilityProcessHostClient() override;
163 163
164 // Message handlers. 164 // Message handlers.
165 void OnPageCount(int page_count); 165 void OnPageCount(int page_count);
166 void OnPageDone(bool success, float scale_factor); 166 void OnPageDone(bool success, float scale_factor);
167 void OnPreCacheFontCharacters(const LOGFONT& log_font, 167
168 const base::string16& characters); 168 // mojom::FontPreCaching:
169 void PreCacheFontCharacters(
170 const LOGFONT& log_font,
171 const base::string16& characters,
172 const PreCacheFontCharactersCallback& callback) override;
169 173
170 void OnFailed(); 174 void OnFailed();
171 void OnTempPdfReady(bool print_text_with_gdi, ScopedTempFile pdf); 175 void OnTempPdfReady(bool print_text_with_gdi, ScopedTempFile pdf);
172 void OnTempEmfReady(GetPageCallbackData* callback_data, ScopedTempFile emf); 176 void OnTempEmfReady(GetPageCallbackData* callback_data, ScopedTempFile emf);
173 177
174 scoped_refptr<RefCountedTempDir> temp_dir_; 178 scoped_refptr<RefCountedTempDir> temp_dir_;
175 179
176 // Used to suppress callbacks after PdfToEmfConverterImpl is deleted. 180 // Used to suppress callbacks after PdfToEmfConverterImpl is deleted.
177 base::WeakPtr<PdfToEmfConverterImpl> converter_; 181 base::WeakPtr<PdfToEmfConverterImpl> converter_;
178 PdfRenderSettings settings_; 182 PdfRenderSettings settings_;
179 183
180 // Document loaded callback. 184 // Document loaded callback.
181 PdfToEmfConverter::StartCallback start_callback_; 185 PdfToEmfConverter::StartCallback start_callback_;
182 186
183 // Process host for IPC. 187 // Process host for IPC.
184 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; 188 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
185 189
186 // Queue of callbacks for GetPage() requests. Utility process should reply 190 // Queue of callbacks for GetPage() requests. Utility process should reply
187 // with PageDone in the same order as requests were received. 191 // with PageDone in the same order as requests were received.
188 // Use containers that keeps element pointers valid after push() and pop(). 192 // Use containers that keeps element pointers valid after push() and pop().
189 typedef std::queue<GetPageCallbackData> GetPageCallbacks; 193 typedef std::queue<GetPageCallbackData> GetPageCallbacks;
190 GetPageCallbacks get_page_callbacks_; 194 GetPageCallbacks get_page_callbacks_;
191 195
196 mojom::PrintingPtr printing_;
197
198 // Interface that receives font precaching requests.
199 mojo::Binding<mojom::FontPreCaching> binding_;
200
192 DISALLOW_COPY_AND_ASSIGN(PdfToEmfUtilityProcessHostClient); 201 DISALLOW_COPY_AND_ASSIGN(PdfToEmfUtilityProcessHostClient);
193 }; 202 };
194 203
195 class PdfToEmfConverterImpl : public PdfToEmfConverter { 204 class PdfToEmfConverterImpl : public PdfToEmfConverter {
196 public: 205 public:
197 PdfToEmfConverterImpl(); 206 PdfToEmfConverterImpl();
198 207
199 ~PdfToEmfConverterImpl() override; 208 ~PdfToEmfConverterImpl() override;
200 209
201 void Start(const scoped_refptr<base::RefCountedMemory>& data, 210 void Start(const scoped_refptr<base::RefCountedMemory>& data,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 return false; 299 return false;
291 std::vector<char> data(size); 300 std::vector<char> data(size);
292 if (file_->ReadAtCurrentPos(data.data(), data.size()) != size) 301 if (file_->ReadAtCurrentPos(data.data(), data.size()) != size)
293 return false; 302 return false;
294 return emf->InitFromData(data.data(), data.size()); 303 return emf->InitFromData(data.data(), data.size());
295 } 304 }
296 305
297 PdfToEmfUtilityProcessHostClient::PdfToEmfUtilityProcessHostClient( 306 PdfToEmfUtilityProcessHostClient::PdfToEmfUtilityProcessHostClient(
298 base::WeakPtr<PdfToEmfConverterImpl> converter, 307 base::WeakPtr<PdfToEmfConverterImpl> converter,
299 const PdfRenderSettings& settings) 308 const PdfRenderSettings& settings)
300 : converter_(converter), settings_(settings) { 309 : converter_(converter), settings_(settings), binding_(this) {}
301 }
302 310
303 PdfToEmfUtilityProcessHostClient::~PdfToEmfUtilityProcessHostClient() { 311 PdfToEmfUtilityProcessHostClient::~PdfToEmfUtilityProcessHostClient() {
304 } 312 }
305 313
306 void PdfToEmfUtilityProcessHostClient::Start( 314 void PdfToEmfUtilityProcessHostClient::Start(
307 const scoped_refptr<base::RefCountedMemory>& data, 315 const scoped_refptr<base::RefCountedMemory>& data,
308 bool print_text_with_gdi, 316 bool print_text_with_gdi,
309 const PdfToEmfConverter::StartCallback& start_callback) { 317 const PdfToEmfConverter::StartCallback& start_callback) {
310 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 318 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
311 BrowserThread::PostTask( 319 BrowserThread::PostTask(
312 BrowserThread::IO, FROM_HERE, 320 BrowserThread::IO, FROM_HERE,
313 base::Bind(&PdfToEmfUtilityProcessHostClient::Start, this, data, 321 base::Bind(&PdfToEmfUtilityProcessHostClient::Start, this, data,
314 print_text_with_gdi, start_callback)); 322 print_text_with_gdi, start_callback));
315 return; 323 return;
316 } 324 }
317 325
318 // Store callback before any OnFailed() call to make it called on failure. 326 // Store callback before any OnFailed() call to make it called on failure.
319 start_callback_ = start_callback; 327 start_callback_ = start_callback;
320 328
321 // NOTE: This process _must_ be sandboxed, otherwise the pdf dll will load 329 // NOTE: This process _must_ be sandboxed, otherwise the pdf dll will load
322 // gdiplus.dll, change how rendering happens, and not be able to correctly 330 // gdiplus.dll, change how rendering happens, and not be able to correctly
323 // generate when sent to a metafile DC. 331 // generate when sent to a metafile DC.
324 utility_process_host_ = content::UtilityProcessHost::Create( 332 utility_process_host_ = content::UtilityProcessHost::Create(
325 this, base::ThreadTaskRunnerHandle::Get()) 333 this, base::ThreadTaskRunnerHandle::Get())
326 ->AsWeakPtr(); 334 ->AsWeakPtr();
327 utility_process_host_->SetName(l10n_util::GetStringUTF16( 335 utility_process_host_->SetName(l10n_util::GetStringUTF16(
328 IDS_UTILITY_PROCESS_EMF_CONVERTOR_NAME)); 336 IDS_UTILITY_PROCESS_EMF_CONVERTOR_NAME));
337 utility_process_host_->Start();
338
339 mojom::PrintingFactoryPtr printing_factory;
340 utility_process_host_->GetRemoteInterfaces()->GetInterface(&printing_factory);
341 printing_factory->MakePrinting(mojo::GetProxy(&printing_),
342 binding_.CreateInterfacePtrAndBind());
329 343
330 BrowserThread::PostTaskAndReplyWithResult( 344 BrowserThread::PostTaskAndReplyWithResult(
331 BrowserThread::FILE, FROM_HERE, 345 BrowserThread::FILE, FROM_HERE,
332 base::Bind(&CreateTempPdfFile, data, &temp_dir_), 346 base::Bind(&CreateTempPdfFile, data, &temp_dir_),
333 base::Bind(&PdfToEmfUtilityProcessHostClient::OnTempPdfReady, this, 347 base::Bind(&PdfToEmfUtilityProcessHostClient::OnTempPdfReady, this,
334 print_text_with_gdi)); 348 print_text_with_gdi));
335 } 349 }
336 350
337 void PdfToEmfUtilityProcessHostClient::OnTempPdfReady(bool print_text_with_gdi, 351 void PdfToEmfUtilityProcessHostClient::OnTempPdfReady(bool print_text_with_gdi,
338 ScopedTempFile pdf) { 352 ScopedTempFile pdf) {
339 DCHECK_CURRENTLY_ON(BrowserThread::IO); 353 DCHECK_CURRENTLY_ON(BrowserThread::IO);
340 if (!utility_process_host_ || !pdf) 354 if (!utility_process_host_ || !pdf)
341 return OnFailed(); 355 return OnFailed();
342 // Should reply with OnPageCount(). 356 printing_->RenderPDFPagesToMetafiles(
343 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles( 357 mojo::WrapPlatformFile(pdf->GetPlatformFile()), settings_,
344 IPC::GetPlatformFileForTransit(pdf->GetPlatformFile(), false), settings_, 358 print_text_with_gdi,
345 print_text_with_gdi)); 359 base::Bind(&PdfToEmfUtilityProcessHostClient::OnPageCount,
360 base::Unretained(this)));
346 } 361 }
347 362
348 void PdfToEmfUtilityProcessHostClient::OnPageCount(int page_count) { 363 void PdfToEmfUtilityProcessHostClient::OnPageCount(int page_count) {
349 DCHECK_CURRENTLY_ON(BrowserThread::IO); 364 DCHECK_CURRENTLY_ON(BrowserThread::IO);
350 if (start_callback_.is_null()) 365 if (start_callback_.is_null())
351 return OnFailed(); 366 return OnFailed();
352 BrowserThread::PostTask(BrowserThread::UI, 367 BrowserThread::PostTask(BrowserThread::UI,
353 FROM_HERE, 368 FROM_HERE,
354 base::Bind(&PdfToEmfConverterImpl::RunCallback, 369 base::Bind(&PdfToEmfConverterImpl::RunCallback,
355 converter_, 370 converter_,
(...skipping 29 matching lines...) Expand all
385 this, 400 this,
386 &get_page_callbacks_.back())); 401 &get_page_callbacks_.back()));
387 } 402 }
388 403
389 void PdfToEmfUtilityProcessHostClient::OnTempEmfReady( 404 void PdfToEmfUtilityProcessHostClient::OnTempEmfReady(
390 GetPageCallbackData* callback_data, 405 GetPageCallbackData* callback_data,
391 ScopedTempFile emf) { 406 ScopedTempFile emf) {
392 DCHECK_CURRENTLY_ON(BrowserThread::IO); 407 DCHECK_CURRENTLY_ON(BrowserThread::IO);
393 if (!utility_process_host_ || !emf) 408 if (!utility_process_host_ || !emf)
394 return OnFailed(); 409 return OnFailed();
395 IPC::PlatformFileForTransit transit =
396 IPC::GetPlatformFileForTransit(emf->GetPlatformFile(), false);
397 callback_data->set_emf(std::move(emf)); 410 callback_data->set_emf(std::move(emf));
398 // Should reply with OnPageDone(). 411 printing_->RenderPDFPagesToMetafilesGetPage(
399 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage( 412 callback_data->page_number(),
400 callback_data->page_number(), transit)); 413 mojo::WrapPlatformFile(emf->GetPlatformFile()),
414 base::Bind(&PdfToEmfUtilityProcessHostClient::OnPageDone,
415 base::Unretained(this)));
401 } 416 }
402 417
403 void PdfToEmfUtilityProcessHostClient::OnPageDone(bool success, 418 void PdfToEmfUtilityProcessHostClient::OnPageDone(bool success,
404 float scale_factor) { 419 float scale_factor) {
405 DCHECK_CURRENTLY_ON(BrowserThread::IO); 420 DCHECK_CURRENTLY_ON(BrowserThread::IO);
406 if (get_page_callbacks_.empty()) 421 if (get_page_callbacks_.empty())
407 return OnFailed(); 422 return OnFailed();
408 GetPageCallbackData& data = get_page_callbacks_.front(); 423 GetPageCallbackData& data = get_page_callbacks_.front();
409 std::unique_ptr<MetafilePlayer> emf; 424 std::unique_ptr<MetafilePlayer> emf;
410 425
411 if (success) { 426 if (success) {
412 ScopedTempFile temp_emf = data.TakeEmf(); 427 ScopedTempFile temp_emf = data.TakeEmf();
413 if (!temp_emf) // Unexpected message from utility process. 428 if (!temp_emf) // Unexpected message from utility process.
414 return OnFailed(); 429 return OnFailed();
415 emf = base::MakeUnique<LazyEmf>(temp_dir_, std::move(temp_emf)); 430 emf = base::MakeUnique<LazyEmf>(temp_dir_, std::move(temp_emf));
416 } 431 }
417 432
418 BrowserThread::PostTask(BrowserThread::UI, 433 BrowserThread::PostTask(BrowserThread::UI,
419 FROM_HERE, 434 FROM_HERE,
420 base::Bind(&PdfToEmfConverterImpl::RunCallback, 435 base::Bind(&PdfToEmfConverterImpl::RunCallback,
421 converter_, 436 converter_,
422 base::Bind(data.callback(), 437 base::Bind(data.callback(),
423 data.page_number(), 438 data.page_number(),
424 scale_factor, 439 scale_factor,
425 base::Passed(&emf)))); 440 base::Passed(&emf))));
426 get_page_callbacks_.pop(); 441 get_page_callbacks_.pop();
427 } 442 }
428 443
429 void PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters( 444 void PdfToEmfUtilityProcessHostClient::PreCacheFontCharacters(
430 const LOGFONT& font, 445 const LOGFONT& font,
431 const base::string16& str) { 446 const base::string16& str,
447 const PreCacheFontCharactersCallback& callback) {
432 // TODO(scottmg): pdf/ppapi still require the renderer to be able to precache 448 // TODO(scottmg): pdf/ppapi still require the renderer to be able to precache
433 // GDI fonts (http://crbug.com/383227), even when using DirectWrite. 449 // GDI fonts (http://crbug.com/383227), even when using DirectWrite.
434 // Eventually this shouldn't be added and should be moved to 450 // Eventually this shouldn't be added and should be moved to
435 // FontCacheDispatcher too. http://crbug.com/356346. 451 // FontCacheDispatcher too. http://crbug.com/356346.
436 452
437 // First, comments from FontCacheDispatcher::OnPreCacheFont do apply here too. 453 // First, comments from FontCacheDispatcher::OnPreCacheFont do apply here too.
438 // Except that for True Type fonts, 454 // Except that for True Type fonts,
439 // GetTextMetrics will not load the font in memory. 455 // GetTextMetrics will not load the font in memory.
440 // The only way windows seem to load properly, it is to create a similar 456 // The only way windows seem to load properly, it is to create a similar
441 // device (like the one in which we print), then do an ExtTextOut, 457 // device (like the one in which we print), then do an ExtTextOut,
442 // as we do in the printing thread, which is sandboxed. 458 // as we do in the printing thread, which is sandboxed.
443 HDC hdc = CreateEnhMetaFile(nullptr, nullptr, nullptr, nullptr); 459 HDC hdc = CreateEnhMetaFile(nullptr, nullptr, nullptr, nullptr);
444 HFONT font_handle = CreateFontIndirect(&font); 460 HFONT font_handle = CreateFontIndirect(&font);
445 DCHECK(font_handle != nullptr); 461 DCHECK(font_handle != nullptr);
446 462
447 HGDIOBJ old_font = SelectObject(hdc, font_handle); 463 HGDIOBJ old_font = SelectObject(hdc, font_handle);
448 DCHECK(old_font != nullptr); 464 DCHECK(old_font != nullptr);
449 465
450 ExtTextOut(hdc, 0, 0, ETO_GLYPH_INDEX, 0, str.c_str(), str.length(), nullptr); 466 ExtTextOut(hdc, 0, 0, ETO_GLYPH_INDEX, 0, str.c_str(), str.length(), nullptr);
451 467
452 SelectObject(hdc, old_font); 468 SelectObject(hdc, old_font);
453 DeleteObject(font_handle); 469 DeleteObject(font_handle);
454 470
455 HENHMETAFILE metafile = CloseEnhMetaFile(hdc); 471 HENHMETAFILE metafile = CloseEnhMetaFile(hdc);
456 472
457 if (metafile) 473 if (metafile)
458 DeleteEnhMetaFile(metafile); 474 DeleteEnhMetaFile(metafile);
475 callback.Run();
459 } 476 }
460 477
461 void PdfToEmfUtilityProcessHostClient::Stop() { 478 void PdfToEmfUtilityProcessHostClient::Stop() {
462 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 479 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
463 BrowserThread::PostTask( 480 BrowserThread::PostTask(
464 BrowserThread::IO, 481 BrowserThread::IO,
465 FROM_HERE, 482 FROM_HERE,
466 base::Bind(&PdfToEmfUtilityProcessHostClient::Stop, this)); 483 base::Bind(&PdfToEmfUtilityProcessHostClient::Stop, this));
467 return; 484 return;
468 } 485 }
469 Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop()); 486 printing_->RenderPDFPagesToMetafilesStop();
470 } 487 }
471 488
472 void PdfToEmfUtilityProcessHostClient::OnProcessCrashed(int exit_code) { 489 void PdfToEmfUtilityProcessHostClient::OnProcessCrashed(int exit_code) {
473 OnFailed(); 490 OnFailed();
474 } 491 }
475 492
476 void PdfToEmfUtilityProcessHostClient::OnProcessLaunchFailed(int exit_code) { 493 void PdfToEmfUtilityProcessHostClient::OnProcessLaunchFailed(int exit_code) {
477 OnFailed(); 494 OnFailed();
478 } 495 }
479 496
480 bool PdfToEmfUtilityProcessHostClient::OnMessageReceived( 497 bool PdfToEmfUtilityProcessHostClient::OnMessageReceived(
481 const IPC::Message& message) { 498 const IPC::Message& message) {
482 bool handled = true;
483 IPC_BEGIN_MESSAGE_MAP(PdfToEmfUtilityProcessHostClient, message)
484 IPC_MESSAGE_HANDLER(
485 ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, OnPageCount)
486 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone,
487 OnPageDone)
488 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_PreCacheFontCharacters,
489 OnPreCacheFontCharacters)
490 IPC_MESSAGE_UNHANDLED(handled = false)
491 IPC_END_MESSAGE_MAP()
492 return handled;
493 }
494
495 bool PdfToEmfUtilityProcessHostClient::Send(IPC::Message* msg) {
496 if (utility_process_host_)
497 return utility_process_host_->Send(msg);
498 delete msg;
499 return false; 499 return false;
500 } 500 }
501 501
502 void PdfToEmfUtilityProcessHostClient::OnFailed() { 502 void PdfToEmfUtilityProcessHostClient::OnFailed() {
503 DCHECK_CURRENTLY_ON(BrowserThread::IO); 503 DCHECK_CURRENTLY_ON(BrowserThread::IO);
504 if (!start_callback_.is_null()) 504 if (!start_callback_.is_null())
505 OnPageCount(0); 505 OnPageCount(0);
506 while (!get_page_callbacks_.empty()) 506 while (!get_page_callbacks_.empty())
507 OnPageDone(false, 0.0f); 507 OnPageDone(false, 0.0f);
508 utility_process_host_.reset(); 508 utility_process_host_.reset();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 541
542 PdfToEmfConverter::~PdfToEmfConverter() { 542 PdfToEmfConverter::~PdfToEmfConverter() {
543 } 543 }
544 544
545 // static 545 // static
546 std::unique_ptr<PdfToEmfConverter> PdfToEmfConverter::CreateDefault() { 546 std::unique_ptr<PdfToEmfConverter> PdfToEmfConverter::CreateDefault() {
547 return std::unique_ptr<PdfToEmfConverter>(new PdfToEmfConverterImpl()); 547 return std::unique_ptr<PdfToEmfConverter>(new PdfToEmfConverterImpl());
548 } 548 }
549 549
550 } // namespace printing 550 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698