Mihai Sardarescu | 160ec66 | 2018-07-18 21:13:51 | [diff] [blame] | 1 | // Copyright 2018 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 "components/unified_consent/feature.h" |
| 6 | |
| 7 | #include "base/feature_list.h" |
| 8 | #include "base/metrics/field_trial_params.h" |
| 9 | #include "components/sync/driver/sync_driver_switches.h" |
| 10 | |
| 11 | namespace unified_consent { |
| 12 | |
| 13 | // base::Feature definitions. |
| 14 | const base::Feature kUnifiedConsent{"UnifiedConsent", |
| 15 | base::FEATURE_DISABLED_BY_DEFAULT}; |
| 16 | const char kUnifiedConsentShowBumpParameter[] = "show_consent_bump"; |
Jérôme Lebel | fe1b2e0 | 2018-08-03 12:26:20 | [diff] [blame] | 17 | const base::Feature kForceUnifiedConsentBump{"ForceUnifiedConsentBump", |
| 18 | base::FEATURE_DISABLED_BY_DEFAULT}; |
Mihai Sardarescu | 160ec66 | 2018-07-18 21:13:51 | [diff] [blame] | 19 | |
Mihai Sardarescu | 29a8cd8 | 2018-09-05 16:52:20 | [diff] [blame^] | 20 | namespace { |
Mihai Sardarescu | 160ec66 | 2018-07-18 21:13:51 | [diff] [blame] | 21 | UnifiedConsentFeatureState GetUnifiedConsentFeatureState() { |
| 22 | // Unified consent requires user consent to be recorded via its own |
| 23 | // sync model type.The reason is that when unified consent is enabled, |
| 24 | // |USER_EVENTS| sync model type is configurable and the user may disable it. |
| 25 | // Chromium needs to continue to record user consent even if the user |
| 26 | // manually disables |USER_EVENTS|. |
| 27 | if (!base::FeatureList::IsEnabled(switches::kSyncUserConsentSeparateType)) |
| 28 | return UnifiedConsentFeatureState::kDisabled; |
| 29 | |
| 30 | if (!base::FeatureList::IsEnabled(kUnifiedConsent)) |
| 31 | return UnifiedConsentFeatureState::kDisabled; |
| 32 | |
| 33 | std::string show_bump = base::GetFieldTrialParamValueByFeature( |
| 34 | kUnifiedConsent, kUnifiedConsentShowBumpParameter); |
| 35 | return show_bump.empty() ? UnifiedConsentFeatureState::kEnabledNoBump |
| 36 | : UnifiedConsentFeatureState::kEnabledWithBump; |
| 37 | } |
Mihai Sardarescu | 29a8cd8 | 2018-09-05 16:52:20 | [diff] [blame^] | 38 | } // namespace |
| 39 | |
| 40 | bool IsUnifiedConsentFeatureEnabled() { |
| 41 | return GetUnifiedConsentFeatureState() != |
| 42 | UnifiedConsentFeatureState::kDisabled; |
| 43 | } |
| 44 | |
| 45 | bool IsUnifiedConsentFeatureWithBumpEnabled() { |
| 46 | return GetUnifiedConsentFeatureState() == |
| 47 | UnifiedConsentFeatureState::kEnabledWithBump; |
| 48 | } |
Mihai Sardarescu | 160ec66 | 2018-07-18 21:13:51 | [diff] [blame] | 49 | |
| 50 | } // namespace unified_consent |