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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Wrapper for Emf to keep only file handle in memory, and load actual data only | 54 // 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 | 55 // 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 | 56 // can't open file handles. We need file handles to reliably delete temporary |
57 // files, and to efficiently interact with utility process. | 57 // files, and to efficiently interact with utility process. |
58 class LazyEmf : public MetafilePlayer { | 58 class LazyEmf : public MetafilePlayer { |
59 public: | 59 public: |
60 LazyEmf(const scoped_refptr<RefCountedTempDir>& temp_dir, ScopedTempFile file) | 60 LazyEmf(const scoped_refptr<RefCountedTempDir>& temp_dir, ScopedTempFile file) |
61 : temp_dir_(temp_dir), file_(file.Pass()) {} | 61 : temp_dir_(temp_dir), file_(file.Pass()) {} |
62 virtual ~LazyEmf() { Close(); } | 62 virtual ~LazyEmf() { Close(); } |
63 | 63 |
64 virtual bool SafePlayback(HDC hdc) const OVERRIDE; | 64 virtual bool SafePlayback(HDC hdc) const override; |
65 virtual bool SaveTo(base::File* file) const OVERRIDE; | 65 virtual bool SaveTo(base::File* file) const override; |
66 | 66 |
67 private: | 67 private: |
68 void Close() const; | 68 void Close() const; |
69 bool LoadEmf(Emf* emf) const; | 69 bool LoadEmf(Emf* emf) const; |
70 | 70 |
71 mutable scoped_refptr<RefCountedTempDir> temp_dir_; | 71 mutable scoped_refptr<RefCountedTempDir> temp_dir_; |
72 mutable ScopedTempFile file_; // Mutable because of consts in base class. | 72 mutable ScopedTempFile file_; // Mutable because of consts in base class. |
73 | 73 |
74 DISALLOW_COPY_AND_ASSIGN(LazyEmf); | 74 DISALLOW_COPY_AND_ASSIGN(LazyEmf); |
75 }; | 75 }; |
(...skipping 20 matching lines...) Expand all Loading... |
96 | 96 |
97 void Start(const scoped_refptr<base::RefCountedMemory>& data, | 97 void Start(const scoped_refptr<base::RefCountedMemory>& data, |
98 const PdfToEmfConverter::StartCallback& start_callback); | 98 const PdfToEmfConverter::StartCallback& start_callback); |
99 | 99 |
100 void GetPage(int page_number, | 100 void GetPage(int page_number, |
101 const PdfToEmfConverter::GetPageCallback& get_page_callback); | 101 const PdfToEmfConverter::GetPageCallback& get_page_callback); |
102 | 102 |
103 void Stop(); | 103 void Stop(); |
104 | 104 |
105 // UtilityProcessHostClient implementation. | 105 // UtilityProcessHostClient implementation. |
106 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 106 virtual void OnProcessCrashed(int exit_code) override; |
107 virtual void OnProcessLaunchFailed() OVERRIDE; | 107 virtual void OnProcessLaunchFailed() override; |
108 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 108 virtual bool OnMessageReceived(const IPC::Message& message) override; |
109 | 109 |
110 private: | 110 private: |
111 class GetPageCallbackData { | 111 class GetPageCallbackData { |
112 MOVE_ONLY_TYPE_FOR_CPP_03(GetPageCallbackData, RValue); | 112 MOVE_ONLY_TYPE_FOR_CPP_03(GetPageCallbackData, RValue); |
113 | 113 |
114 public: | 114 public: |
115 GetPageCallbackData(int page_number, | 115 GetPageCallbackData(int page_number, |
116 PdfToEmfConverter::GetPageCallback callback) | 116 PdfToEmfConverter::GetPageCallback callback) |
117 : page_number_(page_number), callback_(callback) {} | 117 : page_number_(page_number), callback_(callback) {} |
118 | 118 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 }; | 176 }; |
177 | 177 |
178 class PdfToEmfConverterImpl : public PdfToEmfConverter { | 178 class PdfToEmfConverterImpl : public PdfToEmfConverter { |
179 public: | 179 public: |
180 PdfToEmfConverterImpl(); | 180 PdfToEmfConverterImpl(); |
181 | 181 |
182 virtual ~PdfToEmfConverterImpl(); | 182 virtual ~PdfToEmfConverterImpl(); |
183 | 183 |
184 virtual void Start(const scoped_refptr<base::RefCountedMemory>& data, | 184 virtual void Start(const scoped_refptr<base::RefCountedMemory>& data, |
185 const PdfRenderSettings& conversion_settings, | 185 const PdfRenderSettings& conversion_settings, |
186 const StartCallback& start_callback) OVERRIDE; | 186 const StartCallback& start_callback) override; |
187 | 187 |
188 virtual void GetPage(int page_number, | 188 virtual void GetPage(int page_number, |
189 const GetPageCallback& get_page_callback) OVERRIDE; | 189 const GetPageCallback& get_page_callback) override; |
190 | 190 |
191 // Helps to cancel callbacks if this object is destroyed. | 191 // Helps to cancel callbacks if this object is destroyed. |
192 void RunCallback(const base::Closure& callback); | 192 void RunCallback(const base::Closure& callback); |
193 | 193 |
194 private: | 194 private: |
195 scoped_refptr<PdfToEmfUtilityProcessHostClient> utility_client_; | 195 scoped_refptr<PdfToEmfUtilityProcessHostClient> utility_client_; |
196 base::WeakPtrFactory<PdfToEmfConverterImpl> weak_ptr_factory_; | 196 base::WeakPtrFactory<PdfToEmfConverterImpl> weak_ptr_factory_; |
197 | 197 |
198 DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverterImpl); | 198 DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverterImpl); |
199 }; | 199 }; |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |