| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/feature_engagement_tracker/internal/feature_config_conditio
n_validator.h" | 5 #include "components/feature_engagement_tracker/internal/feature_config_conditio
n_validator.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "components/feature_engagement_tracker/internal/availability_model.h" | 8 #include "components/feature_engagement_tracker/internal/availability_model.h" |
| 9 #include "components/feature_engagement_tracker/internal/configuration.h" | 9 #include "components/feature_engagement_tracker/internal/configuration.h" |
| 10 #include "components/feature_engagement_tracker/internal/model.h" | 10 #include "components/feature_engagement_tracker/internal/model.h" |
| 11 #include "components/feature_engagement_tracker/internal/proto/event.pb.h" | 11 #include "components/feature_engagement_tracker/internal/proto/event.pb.h" |
| 12 #include "components/feature_engagement_tracker/public/feature_list.h" | 12 #include "components/feature_engagement_tracker/public/feature_list.h" |
| 13 | 13 |
| 14 namespace feature_engagement_tracker { | 14 namespace feature_engagement_tracker { |
| 15 | 15 |
| 16 FeatureConfigConditionValidator::FeatureConfigConditionValidator() | 16 FeatureConfigConditionValidator::FeatureConfigConditionValidator() |
| 17 : currently_showing_(false), times_shown_(0u) {} | 17 : currently_showing_(false), times_shown_(0u) {} |
| 18 | 18 |
| 19 FeatureConfigConditionValidator::~FeatureConfigConditionValidator() = default; | 19 FeatureConfigConditionValidator::~FeatureConfigConditionValidator() = default; |
| 20 | 20 |
| 21 ConditionValidator::Result FeatureConfigConditionValidator::MeetsConditions( | 21 ConditionValidator::Result FeatureConfigConditionValidator::MeetsConditions( |
| 22 const base::Feature& feature, | 22 const base::Feature& feature, |
| 23 const FeatureConfig& config, | 23 const FeatureConfig& config, |
| 24 const Model& model, | 24 const Model& model, |
| 25 const AvailabilityModel& availability_model, | 25 const AvailabilityModel& availability_model, |
| 26 uint32_t current_day) const { | 26 uint32_t current_day) const { |
| 27 ConditionValidator::Result result(true); | 27 ConditionValidator::Result result(true); |
| 28 result.model_ready_ok = model.IsReady(); | 28 result.event_model_ready_ok = model.IsReady(); |
| 29 result.currently_showing_ok = !currently_showing_; | 29 result.currently_showing_ok = !currently_showing_; |
| 30 result.feature_enabled_ok = base::FeatureList::IsEnabled(feature); | 30 result.feature_enabled_ok = base::FeatureList::IsEnabled(feature); |
| 31 result.config_ok = config.valid; | 31 result.config_ok = config.valid; |
| 32 result.used_ok = EventConfigMeetsConditions(config.used, model, current_day); | 32 result.used_ok = EventConfigMeetsConditions(config.used, model, current_day); |
| 33 result.trigger_ok = | 33 result.trigger_ok = |
| 34 EventConfigMeetsConditions(config.trigger, model, current_day); | 34 EventConfigMeetsConditions(config.trigger, model, current_day); |
| 35 | 35 |
| 36 for (const auto& event_config : config.event_configs) { | 36 for (const auto& event_config : config.event_configs) { |
| 37 result.preconditions_ok &= | 37 result.preconditions_ok &= |
| 38 EventConfigMeetsConditions(event_config, model, current_day); | 38 EventConfigMeetsConditions(event_config, model, current_day); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 uint32_t days_available = current_day - availability_day.value(); | 112 uint32_t days_available = current_day - availability_day.value(); |
| 113 | 113 |
| 114 // Ensure that availability days never wrap around. | 114 // Ensure that availability days never wrap around. |
| 115 if (availability_day.value() > current_day) | 115 if (availability_day.value() > current_day) |
| 116 days_available = 0u; | 116 days_available = 0u; |
| 117 | 117 |
| 118 return comparator.MeetsCriteria(days_available); | 118 return comparator.MeetsCriteria(days_available); |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace feature_engagement_tracker | 121 } // namespace feature_engagement_tracker |
| OLD | NEW |