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

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

Issue 1062873003: Give names to all utility processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typos Created 5 years, 8 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
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 <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"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "chrome/common/chrome_utility_messages.h" 13 #include "chrome/common/chrome_utility_messages.h"
14 #include "chrome/common/chrome_utility_printing_messages.h" 14 #include "chrome/common/chrome_utility_printing_messages.h"
15 #include "chrome/grit/generated_resources.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/child_process_data.h" 17 #include "content/public/browser/child_process_data.h"
17 #include "content/public/browser/utility_process_host.h" 18 #include "content/public/browser/utility_process_host.h"
18 #include "content/public/browser/utility_process_host_client.h" 19 #include "content/public/browser/utility_process_host_client.h"
19 #include "printing/emf_win.h" 20 #include "printing/emf_win.h"
20 #include "printing/pdf_render_settings.h" 21 #include "printing/pdf_render_settings.h"
22 #include "ui/base/l10n/l10n_util.h"
21 23
22 namespace printing { 24 namespace printing {
23 25
24 namespace { 26 namespace {
25 27
26 using content::BrowserThread; 28 using content::BrowserThread;
27 29
28 class PdfToEmfConverterImpl; 30 class PdfToEmfConverterImpl;
29 31
30 // Allows to delete temporary directory after all temporary files created inside 32 // Allows to delete temporary directory after all temporary files created inside
(...skipping 23 matching lines...) Expand all
54 // Wrapper for Emf to keep only file handle in memory, and load actual data only 56 // Wrapper for Emf to keep only file handle in memory, and load actual data only
55 // on playback. Emf::InitFromFile() can play metafile directly from disk, but it 57 // on playback. Emf::InitFromFile() can play metafile directly from disk, but it
56 // can't open file handles. We need file handles to reliably delete temporary 58 // can't open file handles. We need file handles to reliably delete temporary
57 // files, and to efficiently interact with utility process. 59 // files, and to efficiently interact with utility process.
58 class LazyEmf : public MetafilePlayer { 60 class LazyEmf : public MetafilePlayer {
59 public: 61 public:
60 LazyEmf(const scoped_refptr<RefCountedTempDir>& temp_dir, ScopedTempFile file) 62 LazyEmf(const scoped_refptr<RefCountedTempDir>& temp_dir, ScopedTempFile file)
61 : temp_dir_(temp_dir), file_(file.Pass()) {} 63 : temp_dir_(temp_dir), file_(file.Pass()) {}
62 virtual ~LazyEmf() { Close(); } 64 virtual ~LazyEmf() { Close(); }
63 65
64 virtual bool SafePlayback(HDC hdc) const override; 66 bool SafePlayback(HDC hdc) const override;
65 virtual bool SaveTo(base::File* file) const override; 67 bool SaveTo(base::File* file) const override;
66 68
67 private: 69 private:
68 void Close() const; 70 void Close() const;
69 bool LoadEmf(Emf* emf) const; 71 bool LoadEmf(Emf* emf) const;
70 72
71 mutable scoped_refptr<RefCountedTempDir> temp_dir_; 73 mutable scoped_refptr<RefCountedTempDir> temp_dir_;
72 mutable ScopedTempFile file_; // Mutable because of consts in base class. 74 mutable ScopedTempFile file_; // Mutable because of consts in base class.
73 75
74 DISALLOW_COPY_AND_ASSIGN(LazyEmf); 76 DISALLOW_COPY_AND_ASSIGN(LazyEmf);
75 }; 77 };
(...skipping 20 matching lines...) Expand all
96 98
97 void Start(const scoped_refptr<base::RefCountedMemory>& data, 99 void Start(const scoped_refptr<base::RefCountedMemory>& data,
98 const PdfToEmfConverter::StartCallback& start_callback); 100 const PdfToEmfConverter::StartCallback& start_callback);
99 101
100 void GetPage(int page_number, 102 void GetPage(int page_number,
101 const PdfToEmfConverter::GetPageCallback& get_page_callback); 103 const PdfToEmfConverter::GetPageCallback& get_page_callback);
102 104
103 void Stop(); 105 void Stop();
104 106
105 // UtilityProcessHostClient implementation. 107 // UtilityProcessHostClient implementation.
106 virtual void OnProcessCrashed(int exit_code) override; 108 void OnProcessCrashed(int exit_code) override;
107 virtual void OnProcessLaunchFailed() override; 109 void OnProcessLaunchFailed() override;
108 virtual bool OnMessageReceived(const IPC::Message& message) override; 110 bool OnMessageReceived(const IPC::Message& message) override;
109 111
110 private: 112 private:
111 class GetPageCallbackData { 113 class GetPageCallbackData {
112 MOVE_ONLY_TYPE_FOR_CPP_03(GetPageCallbackData, RValue); 114 MOVE_ONLY_TYPE_FOR_CPP_03(GetPageCallbackData, RValue);
113 115
114 public: 116 public:
115 GetPageCallbackData(int page_number, 117 GetPageCallbackData(int page_number,
116 PdfToEmfConverter::GetPageCallback callback) 118 PdfToEmfConverter::GetPageCallback callback)
117 : page_number_(page_number), callback_(callback) {} 119 : page_number_(page_number), callback_(callback) {}
118 120
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 176
175 DISALLOW_COPY_AND_ASSIGN(PdfToEmfUtilityProcessHostClient); 177 DISALLOW_COPY_AND_ASSIGN(PdfToEmfUtilityProcessHostClient);
176 }; 178 };
177 179
178 class PdfToEmfConverterImpl : public PdfToEmfConverter { 180 class PdfToEmfConverterImpl : public PdfToEmfConverter {
179 public: 181 public:
180 PdfToEmfConverterImpl(); 182 PdfToEmfConverterImpl();
181 183
182 virtual ~PdfToEmfConverterImpl(); 184 virtual ~PdfToEmfConverterImpl();
183 185
184 virtual void Start(const scoped_refptr<base::RefCountedMemory>& data, 186 void Start(const scoped_refptr<base::RefCountedMemory>& data,
185 const PdfRenderSettings& conversion_settings, 187 const PdfRenderSettings& conversion_settings,
186 const StartCallback& start_callback) override; 188 const StartCallback& start_callback) override;
187 189
188 virtual void GetPage(int page_number, 190 void GetPage(int page_number,
189 const GetPageCallback& get_page_callback) override; 191 const GetPageCallback& get_page_callback) override;
190 192
191 // Helps to cancel callbacks if this object is destroyed. 193 // Helps to cancel callbacks if this object is destroyed.
192 void RunCallback(const base::Closure& callback); 194 void RunCallback(const base::Closure& callback);
193 195
194 private: 196 private:
195 scoped_refptr<PdfToEmfUtilityProcessHostClient> utility_client_; 197 scoped_refptr<PdfToEmfUtilityProcessHostClient> utility_client_;
196 base::WeakPtrFactory<PdfToEmfConverterImpl> weak_ptr_factory_; 198 base::WeakPtrFactory<PdfToEmfConverterImpl> weak_ptr_factory_;
197 199
198 DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverterImpl); 200 DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverterImpl);
199 }; 201 };
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // Store callback before any OnFailed() call to make it called on failure. 293 // Store callback before any OnFailed() call to make it called on failure.
292 start_callback_ = start_callback; 294 start_callback_ = start_callback;
293 295
294 // NOTE: This process _must_ be sandboxed, otherwise the pdf dll will load 296 // NOTE: This process _must_ be sandboxed, otherwise the pdf dll will load
295 // gdiplus.dll, change how rendering happens, and not be able to correctly 297 // gdiplus.dll, change how rendering happens, and not be able to correctly
296 // generate when sent to a metafile DC. 298 // generate when sent to a metafile DC.
297 utility_process_host_ = 299 utility_process_host_ =
298 content::UtilityProcessHost::Create( 300 content::UtilityProcessHost::Create(
299 this, base::MessageLoop::current()->message_loop_proxy()) 301 this, base::MessageLoop::current()->message_loop_proxy())
300 ->AsWeakPtr(); 302 ->AsWeakPtr();
301 if (!utility_process_host_) 303 utility_process_host_->SetName(l10n_util::GetStringUTF16(
302 return OnFailed(); 304 IDS_UTILITY_PROCESS_EMF_CONVERTOR_NAME));
303 // Should reply with OnProcessStarted(). 305 // Should reply with OnProcessStarted().
304 Send(new ChromeUtilityMsg_StartupPing); 306 Send(new ChromeUtilityMsg_StartupPing);
305 } 307 }
306 308
307 void PdfToEmfUtilityProcessHostClient::OnProcessStarted() { 309 void PdfToEmfUtilityProcessHostClient::OnProcessStarted() {
308 DCHECK_CURRENTLY_ON(BrowserThread::IO); 310 DCHECK_CURRENTLY_ON(BrowserThread::IO);
309 if (!utility_process_host_) 311 if (!utility_process_host_)
310 return OnFailed(); 312 return OnFailed();
311 313
312 scoped_refptr<base::RefCountedMemory> data = data_; 314 scoped_refptr<base::RefCountedMemory> data = data_;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 488
487 PdfToEmfConverter::~PdfToEmfConverter() { 489 PdfToEmfConverter::~PdfToEmfConverter() {
488 } 490 }
489 491
490 // static 492 // static
491 scoped_ptr<PdfToEmfConverter> PdfToEmfConverter::CreateDefault() { 493 scoped_ptr<PdfToEmfConverter> PdfToEmfConverter::CreateDefault() {
492 return scoped_ptr<PdfToEmfConverter>(new PdfToEmfConverterImpl()); 494 return scoped_ptr<PdfToEmfConverter>(new PdfToEmfConverterImpl());
493 } 495 }
494 496
495 } // namespace printing 497 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698