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

Side by Side Diff: printing/metafile.cc

Issue 568633002: Extracted MetafilePlayer interface from printing::MetafilePlayer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no_expose
Patch Set: Thu Sep 11 16:10:13 PDT 2014 Created 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "printing/metafile.h"
6
7 #include <vector>
8
9 #include "base/files/file.h"
10 #include "base/numerics/safe_conversions.h"
11
12 namespace printing {
13
14 bool Metafile::GetDataAsVector(std::vector<char>* buffer) const {
15 buffer->resize(GetDataSize());
16 if (buffer->empty())
17 return false;
18 return GetData(&buffer->front(), base::checked_cast<uint32>(buffer->size()));
19 }
20
21 bool Metafile::SaveTo(base::File* file) const {
22 if (!file->IsValid())
23 return false;
24
25 std::vector<char> buffer;
26 if (!GetDataAsVector(&buffer))
27 return false;
28
29 int size = base::checked_cast<int>(buffer.size());
30 if (file->WriteAtCurrentPos(&buffer[0], size) != size) {
31 DLOG(ERROR) << "Failed to save file.";
32 return false;
33 }
34 return true;
35 }
36
37 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698