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.
4
5#ifndef COMPONENTS_VARIATIONS_STUDY_FILTERING_H_
6#define COMPONENTS_VARIATIONS_STUDY_FILTERING_H_
7
8#include <string>
9#include <vector>
10
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"
17
18namespace variations {
19
20// Internal functions exposed for testing purposes only.
21namespace internal {
22
23// Checks whether a study is applicable for the given |channel| per |filter|.
24bool CheckStudyChannel(const Study_Filter& filter, Study_Channel channel);
25
26// Checks whether a study is applicable for the given |form_factor| per
27// |filter|.
28bool CheckStudyFormFactor(const Study_Filter& filter,
29                          Study_FormFactor form_factor);
30
31// Checks whether a study is applicable for the given |hardware_class| per
32// |filter|.
33bool CheckStudyHardwareClass(const Study_Filter& filter,
34                             const std::string& hardware_class);
35
36// Checks whether a study is applicable for the given |locale| per |filter|.
37bool CheckStudyLocale(const Study_Filter& filter, const std::string& locale);
38
39// Checks whether a study is applicable for the given |platform| per |filter|.
40bool CheckStudyPlatform(const Study_Filter& filter, Study_Platform platform);
41
42// Checks whether a study is applicable for the given date/time per |filter|.
43bool CheckStudyStartDate(const Study_Filter& filter,
44                         const base::Time& date_time);
45
46// Checks whether a study is applicable for the given version per |filter|.
47bool CheckStudyVersion(const Study_Filter& filter,
48                       const base::Version& version);
49
50// Checks whether |study| is expired using the given date/time.
51bool IsStudyExpired(const Study& study, const base::Time& date_time);
52
53// Returns whether |study| should be disabled according to its restriction
54// parameters.
55bool ShouldAddStudy(const Study& study,
56                    const std::string& locale,
57                    const base::Time& reference_date,
58                    const base::Version& version,
59                    Study_Channel channel,
60                    Study_FormFactor form_factor,
61                    const std::string& hardware_class);
62
63}  // namespace internal
64
65// Filters the list of studies in |seed| and validates and pre-processes them,
66// adding any kept studies to |filtered_studies| list. Ensures that the
67// resulting list will not have more than one study with the same name.
68void FilterAndValidateStudies(const VariationsSeed& seed,
69                              const std::string& locale,
70                              const base::Time& reference_date,
71                              const base::Version& version,
72                              Study_Channel channel,
73                              Study_FormFactor form_factor,
74                              const std::string& hardware_class,
75                              std::vector<ProcessedStudy>* filtered_studies);
76
77}  // namespace variations
78
79#endif  // COMPONENTS_VARIATIONS_STUDY_FILTERING_H_
80