[M85 Dev][EFL] Fix errors to generate ninja files
[platform/framework/web/chromium-efl.git] / chrome / browser / unexpire_flags.cc
1 // Copyright 2019 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 "chrome/browser/unexpire_flags.h"
6
7 #include "base/no_destructor.h"
8 #include "chrome/browser/expired_flags_list.h"
9 #include "chrome/browser/unexpire_flags_gen.h"
10 #include "chrome/common/chrome_version.h"
11
12 namespace flags {
13
14 namespace {
15
16 class FlagPredicateSingleton {
17  public:
18   FlagPredicateSingleton() = default;
19   ~FlagPredicateSingleton() = default;
20
21   static const testing::FlagPredicate& GetPredicate() {
22     return GetInstance()->predicate_;
23   }
24   static void SetPredicate(testing::FlagPredicate predicate) {
25     GetInstance()->predicate_ = predicate;
26   }
27
28  private:
29   static FlagPredicateSingleton* GetInstance() {
30     static base::NoDestructor<FlagPredicateSingleton> instance;
31     return instance.get();
32   }
33
34   testing::FlagPredicate predicate_;
35 };
36
37 }  // namespace
38
39 bool IsFlagExpired(const char* internal_name) {
40   constexpr int kChromeVersion[] = {CHROME_VERSION};
41   constexpr int kChromeVersionMajor = kChromeVersion[0];
42
43   if (FlagPredicateSingleton::GetPredicate())
44     return FlagPredicateSingleton::GetPredicate().Run(internal_name);
45
46   for (int i = 0; kExpiredFlags[i].name; ++i) {
47     const ExpiredFlag* f = &kExpiredFlags[i];
48     if (strcmp(f->name, internal_name))
49       continue;
50
51     // To keep the size of the expired flags list down,
52     // //tools/flags/generate_expired_flags.py doesn't emit flags with expiry
53     // mstone -1; it makes no sense for these flags to be in the expiry list
54     // anyway. However, if a bug did cause that to happen, and this function
55     // didn't handle that case, all flags with expiration -1 would immediately
56     // expire, which would be very bad. As such there's an extra error-check
57     // here: a DCHECK to catch bugs in the script, and a regular if to ensure we
58     // never expire flags that should never expire.
59     DCHECK_NE(f->mstone, -1);
60     if (f->mstone == -1)
61       continue;
62
63     const base::Feature* expiry_feature =
64         GetUnexpireFeatureForMilestone(f->mstone);
65
66     // If there's an unexpiry feature, and the unexpiry feature is *disabled*,
67     // then the flag is expired. The double-negative is very unfortunate.
68     if (expiry_feature)
69       return !base::FeatureList::IsEnabled(*expiry_feature);
70     return f->mstone < kChromeVersionMajor;
71   }
72   return false;
73 }
74
75 namespace testing {
76
77 void SetFlagExpiredPredicate(FlagPredicate predicate) {
78   FlagPredicateSingleton::SetPredicate(predicate);
79 }
80
81 }  // namespace testing
82
83 }  // namespace flags