| 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 "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" | 5 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 host = host.substr(next_start_pos); | 94 host = host.substr(next_start_pos); |
| 95 } | 95 } |
| 96 | 96 |
| 97 return -1; | 97 return -1; |
| 98 } | 98 } |
| 99 | 99 |
| 100 base::TimeDelta SettingsResetPromptConfig::delay_before_prompt() const { | 100 base::TimeDelta SettingsResetPromptConfig::delay_before_prompt() const { |
| 101 return delay_before_prompt_; | 101 return delay_before_prompt_; |
| 102 } | 102 } |
| 103 | 103 |
| 104 int SettingsResetPromptConfig::prompt_wave() const { |
| 105 return prompt_wave_; |
| 106 } |
| 107 |
| 108 base::TimeDelta SettingsResetPromptConfig::time_between_prompts() const { |
| 109 return time_between_prompts_; |
| 110 } |
| 111 |
| 104 // Implements the hash function for SHA256Hash objects. Simply uses the | 112 // Implements the hash function for SHA256Hash objects. Simply uses the |
| 105 // first bytes of the SHA256 hash as its own hash. | 113 // first bytes of the SHA256 hash as its own hash. |
| 106 size_t SettingsResetPromptConfig::SHA256HashHasher::operator()( | 114 size_t SettingsResetPromptConfig::SHA256HashHasher::operator()( |
| 107 const SHA256Hash& key) const { | 115 const SHA256Hash& key) const { |
| 108 DCHECK_EQ(crypto::kSHA256Length, key.size()); | 116 DCHECK_EQ(crypto::kSHA256Length, key.size()); |
| 109 // This is safe because |key| contains 32 bytes while a size_t is | 117 // This is safe because |key| contains 32 bytes while a size_t is |
| 110 // either 4 or 8 bytes. | 118 // either 4 or 8 bytes. |
| 111 return *reinterpret_cast<const size_t*>(key.data()); | 119 return *reinterpret_cast<const size_t*>(key.data()); |
| 112 } | 120 } |
| 113 | 121 |
| 114 // These values are written to logs. New enum values can be added, but | 122 // These values are written to logs. New enum values can be added, but |
| 115 // existing enums must never be renumbered or deleted and reused. If you | 123 // existing enums must never be renumbered or deleted and reused. If you |
| 116 // do add values, also update the corresponding enum definition in the | 124 // do add values, also update the corresponding enum definition in the |
| 117 // histograms.xml file. | 125 // histograms.xml file. |
| 118 enum SettingsResetPromptConfig::ConfigError : int { | 126 enum SettingsResetPromptConfig::ConfigError : int { |
| 119 CONFIG_ERROR_OK = 1, | 127 CONFIG_ERROR_OK = 1, |
| 120 CONFIG_ERROR_MISSING_DOMAIN_HASHES_PARAM = 2, | 128 CONFIG_ERROR_MISSING_DOMAIN_HASHES_PARAM = 2, |
| 121 CONFIG_ERROR_BAD_DOMAIN_HASHES_PARAM = 3, | 129 CONFIG_ERROR_BAD_DOMAIN_HASHES_PARAM = 3, |
| 122 CONFIG_ERROR_BAD_DOMAIN_HASH = 4, | 130 CONFIG_ERROR_BAD_DOMAIN_HASH = 4, |
| 123 CONFIG_ERROR_BAD_DOMAIN_ID = 5, | 131 CONFIG_ERROR_BAD_DOMAIN_ID = 5, |
| 124 CONFIG_ERROR_DUPLICATE_DOMAIN_HASH = 6, | 132 CONFIG_ERROR_DUPLICATE_DOMAIN_HASH = 6, |
| 125 CONFIG_ERROR_BAD_DELAY_BEFORE_PROMPT_SECONDS_PARAM = 7, | 133 CONFIG_ERROR_BAD_DELAY_BEFORE_PROMPT_SECONDS_PARAM = 7, |
| 134 CONFIG_ERROR_BAD_PROMPT_WAVE_PARAM = 8, |
| 135 CONFIG_ERROR_BAD_TIME_BETWEEN_PROMPTS_SECONDS_PARAM = 9, |
| 126 CONFIG_ERROR_MAX | 136 CONFIG_ERROR_MAX |
| 127 }; | 137 }; |
| 128 | 138 |
| 129 bool SettingsResetPromptConfig::Init() { | 139 bool SettingsResetPromptConfig::Init() { |
| 130 if (!IsPromptEnabled()) | 140 if (!IsPromptEnabled()) |
| 131 return false; | 141 return false; |
| 132 | 142 |
| 133 // Parse the domain_hashes feature parameter. | 143 // Parse the domain_hashes feature parameter. |
| 134 std::string domain_hashes_json = base::GetFieldTrialParamValueByFeature( | 144 std::string domain_hashes_json = base::GetFieldTrialParamValueByFeature( |
| 135 kSettingsResetPrompt, "domain_hashes"); | 145 kSettingsResetPrompt, "domain_hashes"); |
| 136 ConfigError error = ParseDomainHashes(domain_hashes_json); | 146 ConfigError error = ParseDomainHashes(domain_hashes_json); |
| 137 if (error != CONFIG_ERROR_OK) { | 147 if (error != CONFIG_ERROR_OK) { |
| 138 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.ConfigError", error, | 148 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.ConfigError", error, |
| 139 CONFIG_ERROR_MAX); | 149 CONFIG_ERROR_MAX); |
| 140 return false; | 150 return false; |
| 141 } | 151 } |
| 142 | 152 |
| 143 // Get the delay_before_prompt feature parameter. | 153 // Get the delay_before_prompt feature parameter. |
| 144 int delay_before_prompt_seconds = base::GetFieldTrialParamByFeatureAsInt( | 154 int delay_before_prompt_seconds = base::GetFieldTrialParamByFeatureAsInt( |
| 145 kSettingsResetPrompt, "delay_before_prompt_seconds", -1); | 155 kSettingsResetPrompt, "delay_before_prompt_seconds", -1); |
| 146 if (delay_before_prompt_seconds < 0) { | 156 if (delay_before_prompt_seconds < 0) { |
| 147 UMA_HISTOGRAM_ENUMERATION( | 157 UMA_HISTOGRAM_ENUMERATION( |
| 148 "SettingsResetPrompt.ConfigError", | 158 "SettingsResetPrompt.ConfigError", |
| 149 CONFIG_ERROR_BAD_DELAY_BEFORE_PROMPT_SECONDS_PARAM, CONFIG_ERROR_MAX); | 159 CONFIG_ERROR_BAD_DELAY_BEFORE_PROMPT_SECONDS_PARAM, CONFIG_ERROR_MAX); |
| 150 return false; | 160 return false; |
| 151 } | 161 } |
| 152 delay_before_prompt_ = | 162 delay_before_prompt_ = |
| 153 base::TimeDelta::FromSeconds(delay_before_prompt_seconds); | 163 base::TimeDelta::FromSeconds(delay_before_prompt_seconds); |
| 154 | 164 |
| 165 // Get the prompt_wave feature paramter. |
| 166 prompt_wave_ = base::GetFieldTrialParamByFeatureAsInt(kSettingsResetPrompt, |
| 167 "prompt_wave", 0); |
| 168 if (prompt_wave_ <= 0) { |
| 169 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.ConfigError", |
| 170 CONFIG_ERROR_BAD_PROMPT_WAVE_PARAM, |
| 171 CONFIG_ERROR_MAX); |
| 172 return false; |
| 173 } |
| 174 |
| 175 // Get the time_between_prompts_seconds feature parameter. |
| 176 int time_between_prompts_seconds = base::GetFieldTrialParamByFeatureAsInt( |
| 177 kSettingsResetPrompt, "time_between_prompts_seconds", -1); |
| 178 if (time_between_prompts_seconds < 0) { |
| 179 UMA_HISTOGRAM_ENUMERATION( |
| 180 "SettingsResetPrompt.ConfigError", |
| 181 CONFIG_ERROR_BAD_TIME_BETWEEN_PROMPTS_SECONDS_PARAM, CONFIG_ERROR_MAX); |
| 182 return false; |
| 183 } |
| 184 time_between_prompts_ = |
| 185 base::TimeDelta::FromSeconds(time_between_prompts_seconds); |
| 186 |
| 155 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.ConfigError", CONFIG_ERROR_OK, | 187 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.ConfigError", CONFIG_ERROR_OK, |
| 156 CONFIG_ERROR_MAX); | 188 CONFIG_ERROR_MAX); |
| 157 return true; | 189 return true; |
| 158 } | 190 } |
| 159 | 191 |
| 160 SettingsResetPromptConfig::ConfigError | 192 SettingsResetPromptConfig::ConfigError |
| 161 SettingsResetPromptConfig::ParseDomainHashes( | 193 SettingsResetPromptConfig::ParseDomainHashes( |
| 162 const std::string& domain_hashes_json) { | 194 const std::string& domain_hashes_json) { |
| 163 if (domain_hashes_json.empty()) | 195 if (domain_hashes_json.empty()) |
| 164 return CONFIG_ERROR_MISSING_DOMAIN_HASHES_PARAM; | 196 return CONFIG_ERROR_MISSING_DOMAIN_HASHES_PARAM; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 231 |
| 200 if (!domain_hashes_.insert(std::make_pair(std::move(hash), domain_id)) | 232 if (!domain_hashes_.insert(std::make_pair(std::move(hash), domain_id)) |
| 201 .second) | 233 .second) |
| 202 return CONFIG_ERROR_DUPLICATE_DOMAIN_HASH; | 234 return CONFIG_ERROR_DUPLICATE_DOMAIN_HASH; |
| 203 } | 235 } |
| 204 | 236 |
| 205 return CONFIG_ERROR_OK; | 237 return CONFIG_ERROR_OK; |
| 206 } | 238 } |
| 207 | 239 |
| 208 } // namespace safe_browsing. | 240 } // namespace safe_browsing. |
| OLD | NEW |