xref: /aosp_15_r20/external/webrtc/rtc_base/experiments/field_trial_list.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2019 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #include "rtc_base/experiments/field_trial_list.h"
11 
12 #include "absl/strings/string_view.h"
13 
14 namespace webrtc {
15 
FieldTrialListBase(absl::string_view key)16 FieldTrialListBase::FieldTrialListBase(absl::string_view key)
17     : FieldTrialParameterInterface(key),
18       failed_(false),
19       parse_got_called_(false) {}
20 
Failed() const21 bool FieldTrialListBase::Failed() const {
22   return failed_;
23 }
Used() const24 bool FieldTrialListBase::Used() const {
25   return parse_got_called_;
26 }
27 
Length()28 int FieldTrialListWrapper::Length() {
29   return GetList()->Size();
30 }
Failed()31 bool FieldTrialListWrapper::Failed() {
32   return GetList()->Failed();
33 }
Used()34 bool FieldTrialListWrapper::Used() {
35   return GetList()->Used();
36 }
37 
Parse(absl::optional<std::string> str_value)38 bool FieldTrialStructListBase::Parse(absl::optional<std::string> str_value) {
39   RTC_DCHECK_NOTREACHED();
40   return true;
41 }
42 
ValidateAndGetLength()43 int FieldTrialStructListBase::ValidateAndGetLength() {
44   int length = -1;
45   for (std::unique_ptr<FieldTrialListWrapper>& list : sub_lists_) {
46     if (list->Failed())
47       return -1;
48     else if (!list->Used())
49       continue;
50     else if (length == -1)
51       length = list->Length();
52     else if (length != list->Length())
53       return -1;
54   }
55 
56   return length;
57 }
58 
59 }  // namespace webrtc
60