[M120 Migration][VD] Remove accessing oom_score_adj in zygote process
[platform/framework/web/chromium-efl.git] / printing / client_info_helpers.cc
1 // Copyright 2022 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/client_info_helpers.h"
6
7 #include "base/no_destructor.h"
8 #include "base/types/optional_util.h"
9 #include "printing/mojom/print.mojom.h"
10 #include "third_party/re2/src/re2/re2.h"
11
12 namespace printing {
13
14 namespace {
15
16 bool ValidateClientType(mojom::IppClientInfo::ClientType type) {
17   return type >= mojom::IppClientInfo::ClientType::kMinValue &&
18          type <= mojom::IppClientInfo::ClientType::kMaxValue;
19 }
20
21 bool ValidateStringMember(const std::string* value, size_t max_length) {
22   static const base::NoDestructor<RE2> kStringRegex("[a-zA-Z0-9_.-]*");
23   return value == nullptr ||
24          (value->size() <= max_length && RE2::FullMatch(*value, *kStringRegex));
25 }
26
27 }  // namespace
28
29 bool ValidateClientInfoItem(const mojom::IppClientInfo& client_info) {
30   return ValidateClientType(client_info.client_type) &&
31          ValidateStringMember(&client_info.client_name,
32                               kClientInfoMaxNameLength) &&
33          ValidateStringMember(&client_info.client_string_version,
34                               kClientInfoMaxStringVersionLength) &&
35          ValidateStringMember(base::OptionalToPtr(client_info.client_patches),
36                               kClientInfoMaxPatchesLength) &&
37          ValidateStringMember(base::OptionalToPtr(client_info.client_version),
38                               kClientInfoMaxVersionLength);
39 }
40
41 }  // namespace printing