OLD | NEW |
(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 |
OLD | NEW |