| OLD | NEW |
| 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 #include "components/variations/study_filtering.h" | 5 #include "components/variations/study_filtering.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 filter.exclude_hardware_class(i)); | 99 filter.exclude_hardware_class(i)); |
| 100 if (position != std::string::npos) | 100 if (position != std::string::npos) |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // None of the exclusions match, so this accepts. | 104 // None of the exclusions match, so this accepts. |
| 105 return true; | 105 return true; |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool CheckStudyLocale(const Study_Filter& filter, const std::string& locale) { | 108 bool CheckStudyLocale(const Study_Filter& filter, const std::string& locale) { |
| 109 // An empty locale list matches all locales. | 109 // Empty locale and exclude_locale lists matches all locales. |
| 110 if (filter.locale_size() == 0) | 110 if (filter.locale_size() == 0 && filter.exclude_locale_size() == 0) |
| 111 return true; | 111 return true; |
| 112 | 112 |
| 113 for (int i = 0; i < filter.locale_size(); ++i) { | 113 // Check if we are supposed to filter for a specified set of countries. Note |
| 114 if (filter.locale(i) == locale) | 114 // that this means this overrides the exclude_locale in case that ever occurs |
| 115 return true; | 115 // (which it shouldn't). |
| 116 } | 116 if (filter.locale_size() > 0) |
| 117 return false; | 117 return base::ContainsValue(filter.locale(), locale); |
| 118 |
| 119 // Omit if matches any of the exclude entries. |
| 120 return !base::ContainsValue(filter.exclude_locale(), locale); |
| 118 } | 121 } |
| 119 | 122 |
| 120 bool CheckStudyPlatform(const Study_Filter& filter, Study_Platform platform) { | 123 bool CheckStudyPlatform(const Study_Filter& filter, Study_Platform platform) { |
| 121 // An empty platform list matches all platforms. | 124 // An empty platform list matches all platforms. |
| 122 if (filter.platform_size() == 0) | 125 if (filter.platform_size() == 0) |
| 123 return true; | 126 return true; |
| 124 | 127 |
| 125 for (int i = 0; i < filter.platform_size(); ++i) { | 128 for (int i = 0; i < filter.platform_size(); ++i) { |
| 126 if (filter.platform(i) == platform) | 129 if (filter.platform(i) == platform) |
| 127 return true; | 130 return true; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 299 |
| 297 for (size_t i = 0; i < expired_studies.size(); ++i) { | 300 for (size_t i = 0; i < expired_studies.size(); ++i) { |
| 298 if (!base::ContainsKey(created_studies, expired_studies[i]->name())) { | 301 if (!base::ContainsKey(created_studies, expired_studies[i]->name())) { |
| 299 ProcessedStudy::ValidateAndAppendStudy(expired_studies[i], true, | 302 ProcessedStudy::ValidateAndAppendStudy(expired_studies[i], true, |
| 300 filtered_studies); | 303 filtered_studies); |
| 301 } | 304 } |
| 302 } | 305 } |
| 303 } | 306 } |
| 304 | 307 |
| 305 } // namespace variations | 308 } // namespace variations |
| OLD | NEW |