Upload upstream chromium 73.0.3683.0
[platform/framework/web/chromium-efl.git] / printing / metafile.cc
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 <stdint.h>
8
9 #include <vector>
10
11 #include "base/files/file.h"
12 #include "base/numerics/safe_conversions.h"
13
14 namespace printing {
15
16 MetafilePlayer::MetafilePlayer() = default;
17
18 MetafilePlayer::~MetafilePlayer() = default;
19
20 Metafile::Metafile() = default;
21
22 Metafile::~Metafile() = default;
23
24 bool Metafile::GetDataAsVector(std::vector<char>* buffer) const {
25   buffer->resize(GetDataSize());
26   if (buffer->empty())
27     return false;
28   return GetData(&buffer->front(),
29                  base::checked_cast<uint32_t>(buffer->size()));
30 }
31
32 bool Metafile::SaveTo(base::File* file) const {
33   if (!file->IsValid())
34     return false;
35
36   std::vector<char> buffer;
37   if (!GetDataAsVector(&buffer))
38     return false;
39
40   int size = base::checked_cast<int>(buffer.size());
41   if (file->WriteAtCurrentPos(&buffer[0], size) != size) {
42     DLOG(ERROR) << "Failed to save file.";
43     return false;
44   }
45   return true;
46 }
47
48 }  // namespace printing