[M120 Migration][VD] Remove accessing oom_score_adj in zygote process
[platform/framework/web/chromium-efl.git] / printing / metafile.cc
1 // Copyright 2014 The Chromium Authors
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/logging.h"
13 #include "base/memory/read_only_shared_memory_region.h"
14 #include "base/numerics/safe_conversions.h"
15 #include "build/build_config.h"
16
17 namespace printing {
18
19 MetafilePlayer::MetafilePlayer() = default;
20
21 MetafilePlayer::~MetafilePlayer() = default;
22
23 Metafile::Metafile() = default;
24
25 Metafile::~Metafile() = default;
26
27 bool Metafile::GetDataAsVector(std::vector<char>* buffer) const {
28   buffer->resize(GetDataSize());
29   if (buffer->empty())
30     return false;
31   return GetData(&buffer->front(),
32                  base::checked_cast<uint32_t>(buffer->size()));
33 }
34
35 base::MappedReadOnlyRegion Metafile::GetDataAsSharedMemoryRegion() const {
36   uint32_t data_size = GetDataSize();
37   if (data_size == 0) {
38     DLOG(ERROR) << "Metafile has no data to map to a region.";
39     return base::MappedReadOnlyRegion();
40   }
41
42   base::MappedReadOnlyRegion region_mapping =
43       base::ReadOnlySharedMemoryRegion::Create(data_size);
44   if (!region_mapping.IsValid()) {
45     DLOG(ERROR) << "Failure mapping metafile data into region for size "
46                 << data_size;
47     return base::MappedReadOnlyRegion();
48   }
49
50   if (!GetData(region_mapping.mapping.memory(), data_size)) {
51     DLOG(ERROR) << "Failure getting metafile data into region";
52     return base::MappedReadOnlyRegion();
53   }
54
55   return region_mapping;
56 }
57
58 #if !BUILDFLAG(IS_ANDROID)
59 bool Metafile::SaveTo(base::File* file) const {
60   if (!file->IsValid())
61     return false;
62
63   std::vector<char> buffer;
64   if (!GetDataAsVector(&buffer))
65     return false;
66
67   if (!file->WriteAtCurrentPosAndCheck(
68           base::as_bytes(base::make_span(buffer)))) {
69     DLOG(ERROR) << "Failed to save file.";
70     return false;
71   }
72   return true;
73 }
74 #endif  // !BUILDFLAG(IS_ANDROID)
75
76 }  // namespace printing