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.
5 #include "printing/metafile.h"
11 #include "base/files/file.h"
12 #include "base/numerics/safe_conversions.h"
16 MetafilePlayer::MetafilePlayer() = default;
18 MetafilePlayer::~MetafilePlayer() = default;
20 Metafile::Metafile() = default;
22 Metafile::~Metafile() = default;
24 bool Metafile::GetDataAsVector(std::vector<char>* buffer) const {
25 buffer->resize(GetDataSize());
28 return GetData(&buffer->front(),
29 base::checked_cast<uint32_t>(buffer->size()));
32 bool Metafile::SaveTo(base::File* file) const {
36 std::vector<char> buffer;
37 if (!GetDataAsVector(&buffer))
40 int size = base::checked_cast<int>(buffer.size());
41 if (file->WriteAtCurrentPos(&buffer[0], size) != size) {
42 DLOG(ERROR) << "Failed to save file.";
48 } // namespace printing