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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <queue> | 10 #include <queue> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | |
12 | 13 |
13 #include "base/files/file.h" | 14 #include "base/files/file.h" |
14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
15 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/macros.h" | 18 #include "base/macros.h" |
18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
19 #include "chrome/common/chrome_utility_messages.h" | 20 #include "chrome/common/chrome_utility_messages.h" |
20 #include "chrome/common/chrome_utility_printing_messages.h" | 21 #include "chrome/common/chrome_utility_printing_messages.h" |
21 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 // files, and to efficiently interact with utility process. | 66 // files, and to efficiently interact with utility process. |
66 class LazyEmf : public MetafilePlayer { | 67 class LazyEmf : public MetafilePlayer { |
67 public: | 68 public: |
68 LazyEmf(const scoped_refptr<RefCountedTempDir>& temp_dir, ScopedTempFile file) | 69 LazyEmf(const scoped_refptr<RefCountedTempDir>& temp_dir, ScopedTempFile file) |
69 : temp_dir_(temp_dir), file_(std::move(file)) { | 70 : temp_dir_(temp_dir), file_(std::move(file)) { |
70 CHECK(file_); | 71 CHECK(file_); |
71 } | 72 } |
72 ~LazyEmf() override { Close(); } | 73 ~LazyEmf() override { Close(); } |
73 | 74 |
74 bool SafePlayback(HDC hdc) const override; | 75 bool SafePlayback(HDC hdc) const override; |
76 bool GetDataAsVector(std::vector<char>* buffer) const override; | |
75 bool SaveTo(base::File* file) const override; | 77 bool SaveTo(base::File* file) const override; |
76 | 78 |
77 private: | 79 private: |
78 void Close() const; | 80 void Close() const; |
79 bool LoadEmf(Emf* emf) const; | 81 bool LoadEmf(Emf* emf) const; |
80 | 82 |
81 mutable scoped_refptr<RefCountedTempDir> temp_dir_; | 83 mutable scoped_refptr<RefCountedTempDir> temp_dir_; |
82 mutable ScopedTempFile file_; // Mutable because of consts in base class. | 84 mutable ScopedTempFile file_; // Mutable because of consts in base class. |
83 | 85 |
84 DISALLOW_COPY_AND_ASSIGN(LazyEmf); | 86 DISALLOW_COPY_AND_ASSIGN(LazyEmf); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 Emf emf; | 253 Emf emf; |
252 bool result = LoadEmf(&emf) && emf.SafePlayback(hdc); | 254 bool result = LoadEmf(&emf) && emf.SafePlayback(hdc); |
253 // TODO(vitalybuka): Fix destruction of metafiles. For some reasons | 255 // TODO(vitalybuka): Fix destruction of metafiles. For some reasons |
254 // instances of Emf are not deleted. crbug.com/411683 | 256 // instances of Emf are not deleted. crbug.com/411683 |
255 // It's known that the Emf going to be played just once to a printer. So just | 257 // It's known that the Emf going to be played just once to a printer. So just |
256 // release file here. | 258 // release file here. |
257 Close(); | 259 Close(); |
258 return result; | 260 return result; |
259 } | 261 } |
260 | 262 |
263 bool LazyEmf::GetDataAsVector(std::vector<char>* buffer) const { | |
Lei Zhang
2016/07/25 21:06:04
Thanks for implemeting this... but will this ever
skau
2016/07/27 00:16:47
It's not currently called. NOTREACHED() probably
| |
264 Emf emf; | |
265 return LoadEmf(&emf) && emf.GetDataAsVector(buffer); | |
266 } | |
267 | |
261 bool LazyEmf::SaveTo(base::File* file) const { | 268 bool LazyEmf::SaveTo(base::File* file) const { |
262 Emf emf; | 269 Emf emf; |
263 return LoadEmf(&emf) && emf.SaveTo(file); | 270 return LoadEmf(&emf) && emf.SaveTo(file); |
264 } | 271 } |
265 | 272 |
266 void LazyEmf::Close() const { | 273 void LazyEmf::Close() const { |
267 file_.reset(); | 274 file_.reset(); |
268 temp_dir_ = NULL; | 275 temp_dir_ = NULL; |
269 } | 276 } |
270 | 277 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 | 498 |
492 PdfToEmfConverter::~PdfToEmfConverter() { | 499 PdfToEmfConverter::~PdfToEmfConverter() { |
493 } | 500 } |
494 | 501 |
495 // static | 502 // static |
496 std::unique_ptr<PdfToEmfConverter> PdfToEmfConverter::CreateDefault() { | 503 std::unique_ptr<PdfToEmfConverter> PdfToEmfConverter::CreateDefault() { |
497 return std::unique_ptr<PdfToEmfConverter>(new PdfToEmfConverterImpl()); | 504 return std::unique_ptr<PdfToEmfConverter>(new PdfToEmfConverterImpl()); |
498 } | 505 } |
499 | 506 |
500 } // namespace printing | 507 } // namespace printing |
OLD | NEW |