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

Side by Side Diff: printing/metafile.cc

Issue 1343593002: Cleanup code in printing/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 | « printing/metafile.h ('k') | printing/pdf_metafile_cg_mac.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 "printing/metafile.h" 5 #include "printing/metafile.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
11 11
12 namespace printing { 12 namespace printing {
13 13
14 MetafilePlayer::MetafilePlayer() { 14 MetafilePlayer::MetafilePlayer() {
15 } 15 }
16 16
17 MetafilePlayer::~MetafilePlayer() { 17 MetafilePlayer::~MetafilePlayer() {
18 } 18 }
19 19
20 Metafile::Metafile() { 20 Metafile::Metafile() {
21 } 21 }
22 22
23 Metafile::~Metafile() { 23 Metafile::~Metafile() {
24 } 24 }
25 25
26 bool Metafile::GetDataAsVector(std::vector<char>* buffer) const { 26 bool Metafile::GetDataAsVector(std::vector<char>* buffer) const {
27 buffer->resize(GetDataSize()); 27 buffer->resize(GetDataSize());
28 if (buffer->empty()) 28 if (buffer->empty())
29 return false; 29 return false;
30 return GetData(&buffer->front(), base::checked_cast<uint32>(buffer->size())); 30 return GetData(&buffer->front(),
31 base::checked_cast<uint32_t>(buffer->size()));
31 } 32 }
32 33
33 bool Metafile::SaveTo(base::File* file) const { 34 bool Metafile::SaveTo(base::File* file) const {
34 if (!file->IsValid()) 35 if (!file->IsValid())
35 return false; 36 return false;
36 37
37 std::vector<char> buffer; 38 std::vector<char> buffer;
38 if (!GetDataAsVector(&buffer)) 39 if (!GetDataAsVector(&buffer))
39 return false; 40 return false;
40 41
41 int size = base::checked_cast<int>(buffer.size()); 42 int size = base::checked_cast<int>(buffer.size());
42 if (file->WriteAtCurrentPos(&buffer[0], size) != size) { 43 if (file->WriteAtCurrentPos(&buffer[0], size) != size) {
43 DLOG(ERROR) << "Failed to save file."; 44 DLOG(ERROR) << "Failed to save file.";
44 return false; 45 return false;
45 } 46 }
46 return true; 47 return true;
47 } 48 }
48 49
49 } // namespace printing 50 } // namespace printing
OLDNEW
« no previous file with comments | « printing/metafile.h ('k') | printing/pdf_metafile_cg_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698