Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(855)

Side by Side Diff: components/variations/study_filtering.h

Issue 2924983003: [Variations] Refactor all state used for study filtering into a container struct. (Closed)
Patch Set: A bit more cleanup Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #ifndef COMPONENTS_VARIATIONS_STUDY_FILTERING_H_ 5 #ifndef COMPONENTS_VARIATIONS_STUDY_FILTERING_H_
6 #define COMPONENTS_VARIATIONS_STUDY_FILTERING_H_ 6 #define COMPONENTS_VARIATIONS_STUDY_FILTERING_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "base/version.h" 13 #include "base/version.h"
14 #include "components/variations/processed_study.h" 14 #include "components/variations/processed_study.h"
15 #include "components/variations/proto/study.pb.h" 15 #include "components/variations/proto/study.pb.h"
16 #include "components/variations/proto/variations_seed.pb.h" 16 #include "components/variations/proto/variations_seed.pb.h"
17 17
18 namespace variations { 18 namespace variations {
19 19
20 struct ClientFilterableState;
21
20 // Internal functions exposed for testing purposes only. 22 // Internal functions exposed for testing purposes only.
21 namespace internal { 23 namespace internal {
22 24
23 // Checks whether a study is applicable for the given |channel| per |filter|. 25 // Checks whether a study is applicable for the given |channel| per |filter|.
24 bool CheckStudyChannel(const Study_Filter& filter, Study_Channel channel); 26 bool CheckStudyChannel(const Study::Filter& filter, Study::Channel channel);
25 27
26 // Checks whether a study is applicable for the given |form_factor| per 28 // Checks whether a study is applicable for the given |form_factor| per
27 // |filter|. 29 // |filter|.
28 bool CheckStudyFormFactor(const Study_Filter& filter, 30 bool CheckStudyFormFactor(const Study::Filter& filter,
29 Study_FormFactor form_factor); 31 Study::FormFactor form_factor);
30 32
31 // Checks whether a study is applicable for the given |hardware_class| per 33 // Checks whether a study is applicable for the given |hardware_class| per
32 // |filter|. 34 // |filter|.
33 bool CheckStudyHardwareClass(const Study_Filter& filter, 35 bool CheckStudyHardwareClass(const Study::Filter& filter,
34 const std::string& hardware_class); 36 const std::string& hardware_class);
35 37
36 // Checks whether a study is applicable for the given |locale| per |filter|. 38 // Checks whether a study is applicable for the given |locale| per |filter|.
37 bool CheckStudyLocale(const Study_Filter& filter, const std::string& locale); 39 bool CheckStudyLocale(const Study::Filter& filter, const std::string& locale);
38 40
39 // Checks whether a study is applicable for the given |platform| per |filter|. 41 // Checks whether a study is applicable for the given |platform| per |filter|.
40 bool CheckStudyPlatform(const Study_Filter& filter, Study_Platform platform); 42 bool CheckStudyPlatform(const Study::Filter& filter, Study::Platform platform);
41 43
42 // Checks whether a study is applicable for the given date/time per |filter|. 44 // Checks whether a study is applicable for the given date/time per |filter|.
43 bool CheckStudyStartDate(const Study_Filter& filter, 45 bool CheckStudyStartDate(const Study::Filter& filter,
44 const base::Time& date_time); 46 const base::Time& date_time);
45 47
46 // Checks whether a study is applicable for the given date/time per |filter|. 48 // Checks whether a study is applicable for the given date/time per |filter|.
47 bool CheckStudyEndDate(const Study_Filter& filter, const base::Time& date_time); 49 bool CheckStudyEndDate(const Study::Filter& filter,
50 const base::Time& date_time);
48 51
49 // Checks whether a study is applicable for the given version per |filter|. 52 // Checks whether a study is applicable for the given version per |filter|.
50 bool CheckStudyVersion(const Study_Filter& filter, 53 bool CheckStudyVersion(const Study::Filter& filter,
51 const base::Version& version); 54 const base::Version& version);
52 55
53 // Checks whether a study is applicable for the given |country| per |filter|. 56 // Checks whether a study is applicable for the given |country| per |filter|.
54 bool CheckStudyCountry(const Study_Filter& filter, const std::string& country); 57 bool CheckStudyCountry(const Study::Filter& filter, const std::string& country);
58
59 // Returns the country that should be used for filtering this study, depending
60 // on whether the study has session or permanent consistency.
61 const std::string& GetClientCountryForStudy(
62 const Study& study,
63 const ClientFilterableState& client_state);
55 64
56 // Checks whether |study| is expired using the given date/time. 65 // Checks whether |study| is expired using the given date/time.
57 bool IsStudyExpired(const Study& study, const base::Time& date_time); 66 bool IsStudyExpired(const Study& study, const base::Time& date_time);
58 67
59 // Returns whether |study| should be disabled according to its restriction 68 // Returns whether |study| should be disabled according to the restriction
60 // parameters. 69 // parameters in the |config|.
61 bool ShouldAddStudy(const Study& study, 70 bool ShouldAddStudy(const Study& study,
62 const std::string& locale, 71 const ClientFilterableState& client_state);
63 const base::Time& reference_date,
64 const base::Version& version,
65 Study_Channel channel,
66 Study_FormFactor form_factor,
67 const std::string& hardware_class,
68 const std::string& country);
69 72
70 } // namespace internal 73 } // namespace internal
71 74
72 // Filters the list of studies in |seed| and validates and pre-processes them, 75 // Filters the list of studies in |seed| according ot the |client_state|, and
73 // adding any kept studies to |filtered_studies| list. Ensures that the 76 // validates and pre-processes them, adding any kept studies to the
74 // resulting list will not have more than one study with the same name. 77 // |filtered_studies| list. Ensures that the resulting list will not have more
78 // than one study with the same name.
75 void FilterAndValidateStudies(const VariationsSeed& seed, 79 void FilterAndValidateStudies(const VariationsSeed& seed,
76 const std::string& locale, 80 const ClientFilterableState& client_state,
77 const base::Time& reference_date,
78 const base::Version& version,
79 Study_Channel channel,
80 Study_FormFactor form_factor,
81 const std::string& hardware_class,
82 const std::string& session_consistency_country,
83 const std::string& permanent_consistency_country,
84 std::vector<ProcessedStudy>* filtered_studies); 81 std::vector<ProcessedStudy>* filtered_studies);
85 82
86 } // namespace variations 83 } // namespace variations
87 84
88 #endif // COMPONENTS_VARIATIONS_STUDY_FILTERING_H_ 85 #endif // COMPONENTS_VARIATIONS_STUDY_FILTERING_H_
OLDNEW
« no previous file with comments | « components/variations/service/variations_service.cc ('k') | components/variations/study_filtering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698