xref: /aosp_15_r20/external/cronet/net/quic/set_quic_flag.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 "net/quic/set_quic_flag.h"
6 
7 #include "base/strings/string_number_conversions.h"
8 #include "net/third_party/quiche/src/quiche/common/platform/api/quiche_flags.h"
9 #include "net/third_party/quiche/src/quiche/quic/platform/api/quic_flags.h"
10 
11 namespace net {
12 
13 namespace {
14 
SetQuicFlagByName_bool(bool * flag,const std::string & value)15 void SetQuicFlagByName_bool(bool* flag, const std::string& value) {
16   if (value == "true" || value == "True")
17     *flag = true;
18   else if (value == "false" || value == "False")
19     *flag = false;
20 }
SetQuicFlagByName_double(double * flag,const std::string & value)21 void SetQuicFlagByName_double(double* flag, const std::string& value) {
22   double val;
23   if (base::StringToDouble(value, &val))
24     *flag = val;
25 }
26 
SetQuicFlagByName_uint64_t(uint64_t * flag,const std::string & value)27 void SetQuicFlagByName_uint64_t(uint64_t* flag, const std::string& value) {
28   uint64_t val;
29   if (base::StringToUint64(value, &val) && val >= 0)
30     *flag = val;
31 }
32 
SetQuicFlagByName_int32_t(int32_t * flag,const std::string & value)33 void SetQuicFlagByName_int32_t(int32_t* flag, const std::string& value) {
34   int val;
35   if (base::StringToInt(value, &val))
36     *flag = val;
37 }
38 
SetQuicFlagByName_int64_t(int64_t * flag,const std::string & value)39 void SetQuicFlagByName_int64_t(int64_t* flag, const std::string& value) {
40   int64_t val;
41   if (base::StringToInt64(value, &val))
42     *flag = val;
43 }
44 
45 }  // namespace
46 
SetQuicFlagByName(const std::string & flag_name,const std::string & value)47 void SetQuicFlagByName(const std::string& flag_name, const std::string& value) {
48 #define QUIC_FLAG(flag, default_value)            \
49   if (flag_name == "FLAGS_" #flag) {              \
50     SetQuicFlagByName_bool(&FLAGS_##flag, value); \
51     return;                                       \
52   }
53 #include "net/third_party/quiche/src/quiche/quic/core/quic_flags_list.h"
54 #undef QUIC_FLAG
55 
56 #define QUICHE_PROTOCOL_FLAG(type, flag, ...)       \
57   if (flag_name == "FLAGS_" #flag) {                \
58     SetQuicFlagByName_##type(&FLAGS_##flag, value); \
59     return;                                         \
60   }
61 #include "net/third_party/quiche/src/quiche/common/quiche_protocol_flags_list.h"
62 #undef QUICHE_PROTOCOL_FLAG
63 }
64 
65 }  // namespace net
66