1 // Copyright 2014 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.
5 #ifndef COMPONENTS_VARIATIONS_STUDY_FILTERING_H_
6 #define COMPONENTS_VARIATIONS_STUDY_FILTERING_H_
11 #include "base/compiler_specific.h"
12 #include "base/time/time.h"
13 #include "base/version.h"
14 #include "components/variations/processed_study.h"
15 #include "components/variations/proto/study.pb.h"
16 #include "components/variations/proto/variations_seed.pb.h"
18 namespace variations
{
20 // Internal functions exposed for testing purposes only.
23 // Checks whether a study is applicable for the given |channel| per |filter|.
24 bool CheckStudyChannel(const Study_Filter
& filter
, Study_Channel channel
);
26 // Checks whether a study is applicable for the given |form_factor| per
28 bool CheckStudyFormFactor(const Study_Filter
& filter
,
29 Study_FormFactor form_factor
);
31 // Checks whether a study is applicable for the given |hardware_class| per
33 bool CheckStudyHardwareClass(const Study_Filter
& filter
,
34 const std::string
& hardware_class
);
36 // Checks whether a study is applicable for the given |locale| per |filter|.
37 bool CheckStudyLocale(const Study_Filter
& filter
, const std::string
& locale
);
39 // Checks whether a study is applicable for the given |platform| per |filter|.
40 bool CheckStudyPlatform(const Study_Filter
& filter
, Study_Platform platform
);
42 // Checks whether a study is applicable for the given date/time per |filter|.
43 bool CheckStudyStartDate(const Study_Filter
& filter
,
44 const base::Time
& date_time
);
46 // Checks whether a study is applicable for the given version per |filter|.
47 bool CheckStudyVersion(const Study_Filter
& filter
,
48 const base::Version
& version
);
50 // Checks whether a study is applicable for the given |country| per |filter|.
51 bool CheckStudyCountry(const Study_Filter
& filter
, const std::string
& country
);
53 // Checks whether |study| is expired using the given date/time.
54 bool IsStudyExpired(const Study
& study
, const base::Time
& date_time
);
56 // Returns whether |study| should be disabled according to its restriction
58 bool ShouldAddStudy(const Study
& study
,
59 const std::string
& locale
,
60 const base::Time
& reference_date
,
61 const base::Version
& version
,
62 Study_Channel channel
,
63 Study_FormFactor form_factor
,
64 const std::string
& hardware_class
,
65 const std::string
& country
);
67 } // namespace internal
69 // Filters the list of studies in |seed| and validates and pre-processes them,
70 // adding any kept studies to |filtered_studies| list. Ensures that the
71 // resulting list will not have more than one study with the same name.
72 void FilterAndValidateStudies(const VariationsSeed
& seed
,
73 const std::string
& locale
,
74 const base::Time
& reference_date
,
75 const base::Version
& version
,
76 Study_Channel channel
,
77 Study_FormFactor form_factor
,
78 const std::string
& hardware_class
,
79 const std::string
& session_consistency_country
,
80 const std::string
& permanent_consistency_country
,
81 std::vector
<ProcessedStudy
>* filtered_studies
);
83 } // namespace variations
85 #endif // COMPONENTS_VARIATIONS_STUDY_FILTERING_H_