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 "components/safe_browsing/password_protection/password_protection_servi ce.h" | 5 #include "components/safe_browsing/password_protection/password_protection_servi ce.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 stored_verdict_count_ = GetStoredVerdictCount() + 1; | 194 stored_verdict_count_ = GetStoredVerdictCount() + 1; |
195 // If same cache_expression is already in this verdict_dictionary, we simply | 195 // If same cache_expression is already in this verdict_dictionary, we simply |
196 // override it. | 196 // override it. |
197 verdict_dictionary->SetWithoutPathExpansion(verdict->cache_expression(), | 197 verdict_dictionary->SetWithoutPathExpansion(verdict->cache_expression(), |
198 std::move(verdict_entry)); | 198 std::move(verdict_entry)); |
199 content_settings_->SetWebsiteSettingDefaultScope( | 199 content_settings_->SetWebsiteSettingDefaultScope( |
200 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 200 hostname, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
201 std::string(), std::move(verdict_dictionary)); | 201 std::string(), std::move(verdict_dictionary)); |
202 } | 202 } |
203 | 203 |
204 void PasswordProtectionService::CleanUpExpiredVerdicts() { | |
205 DCHECK(content_settings_); | |
206 if (GetStoredVerdictCount() <= 0) | |
207 return; | |
208 | |
209 ContentSettingsForOneType password_protection_settings; | |
210 content_settings_->GetSettingsForOneType( | |
211 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), | |
212 &password_protection_settings); | |
213 | |
214 for (const ContentSettingPatternSource& source : | |
215 password_protection_settings) { | |
216 GURL primary_pattern_url = GURL(source.primary_pattern.ToString()); | |
217 // Find all verdicts associated with this origin. | |
218 std::unique_ptr<base::DictionaryValue> verdict_dictionary = | |
219 base::DictionaryValue::From(content_settings_->GetWebsiteSetting( | |
220 primary_pattern_url, GURL(), | |
221 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), nullptr)); | |
222 std::vector<base::StringPiece> expired_keys; | |
223 for (base::DictionaryValue::Iterator it(*verdict_dictionary.get()); | |
224 !it.IsAtEnd(); it.Advance()) { | |
225 base::DictionaryValue* verdict_entry = nullptr; | |
226 CHECK(verdict_dictionary->GetDictionaryWithoutPathExpansion( | |
227 it.key(), &verdict_entry)); | |
lpz
2017/05/10 14:03:54
nit: align?
Jialiu Lin
2017/05/10 22:26:32
Acknowledged.
"git cl format" insists this is the
| |
228 int verdict_received_time; | |
229 LoginReputationClientResponse verdict; | |
230 CHECK(ParseVerdictEntry(verdict_entry, &verdict_received_time, &verdict)); | |
231 | |
232 if (IsCacheExpired(verdict_received_time, verdict.cache_duration_sec())) { | |
233 // Since DictionaryValue::Iterator cannot be used to modify the | |
234 // dictionary, we record the keys of expired verdicts in |expired_keys| | |
235 // and remove them in the next for-loop. | |
236 expired_keys.push_back(it.key()); | |
237 } | |
238 } | |
239 | |
240 for (const base::StringPiece& key : expired_keys) { | |
241 verdict_dictionary->RemoveWithoutPathExpansion(key, nullptr); | |
242 stored_verdict_count_--; | |
243 } | |
244 | |
245 if (verdict_dictionary->size() == 0u) { | |
246 content_settings_->ClearSettingsForOneTypeWithPredicate( | |
247 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, base::Time(), | |
248 base::Bind(&OriginMatchPrimaryPattern, primary_pattern_url)); | |
249 } else if (expired_keys.size() > 0u) { | |
250 // Set the website setting of this origin with the updated | |
251 // |verdict_diectionary|. | |
252 content_settings_->SetWebsiteSettingDefaultScope( | |
253 primary_pattern_url, GURL(), | |
254 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), | |
255 std::move(verdict_dictionary)); | |
256 } | |
257 } | |
258 } | |
259 | |
204 void PasswordProtectionService::StartRequest( | 260 void PasswordProtectionService::StartRequest( |
205 const GURL& main_frame_url, | 261 const GURL& main_frame_url, |
206 const GURL& password_form_action, | 262 const GURL& password_form_action, |
207 const GURL& password_form_frame_url, | 263 const GURL& password_form_frame_url, |
208 LoginReputationClientRequest::TriggerType type) { | 264 LoginReputationClientRequest::TriggerType type) { |
209 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 265 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
210 scoped_refptr<PasswordProtectionRequest> request( | 266 scoped_refptr<PasswordProtectionRequest> request( |
211 new PasswordProtectionRequest(main_frame_url, password_form_action, | 267 new PasswordProtectionRequest(main_frame_url, password_form_action, |
212 password_form_frame_url, type, this, | 268 password_form_frame_url, type, this, |
213 GetRequestTimeoutInMS())); | 269 GetRequestTimeoutInMS())); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 const std::vector<char> verdict_blob(serialized_proto.begin(), | 534 const std::vector<char> verdict_blob(serialized_proto.begin(), |
479 serialized_proto.end()); | 535 serialized_proto.end()); |
480 std::unique_ptr<base::Value> binary_value = | 536 std::unique_ptr<base::Value> binary_value = |
481 base::MakeUnique<base::Value>(verdict_blob); | 537 base::MakeUnique<base::Value>(verdict_blob); |
482 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); | 538 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); |
483 result->Set(kVerdictProto, std::move(binary_value)); | 539 result->Set(kVerdictProto, std::move(binary_value)); |
484 return result; | 540 return result; |
485 } | 541 } |
486 | 542 |
487 } // namespace safe_browsing | 543 } // namespace safe_browsing |
OLD | NEW |