| 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/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 const char kVerdictProto[] = "verdict_proto"; | 32 const char kVerdictProto[] = "verdict_proto"; |
| 33 const int kRequestTimeoutMs = 10000; | 33 const int kRequestTimeoutMs = 10000; |
| 34 const char kPasswordProtectionRequestUrl[] = | 34 const char kPasswordProtectionRequestUrl[] = |
| 35 "https://sb-ssl.google.com/safebrowsing/clientreport/login"; | 35 "https://sb-ssl.google.com/safebrowsing/clientreport/login"; |
| 36 | 36 |
| 37 // Helper function to determine if the given origin matches content settings | 37 // Helper function to determine if the given origin matches content settings |
| 38 // map's patterns. | 38 // map's patterns. |
| 39 bool OriginMatchPrimaryPattern( | 39 bool OriginMatchPrimaryPattern( |
| 40 const GURL& origin, | 40 const GURL& origin, |
| 41 const ContentSettingsPattern& primary_pattern, | 41 const ContentSettingsPattern& primary_pattern, |
| 42 const ContentSettingsPattern& secondary_pattern_unused) { | 42 const ContentSettingsPattern& secondary_pattern_unused, |
| 43 base::Time last_modified_unused) { |
| 43 return ContentSettingsPattern::FromURLNoWildcard(origin) == primary_pattern; | 44 return ContentSettingsPattern::FromURLNoWildcard(origin) == primary_pattern; |
| 44 } | 45 } |
| 45 | 46 |
| 46 // Returns the number of path segments in |cache_expression_path|. | 47 // Returns the number of path segments in |cache_expression_path|. |
| 47 // For example, return 0 for "/", since there is no path after the leading | 48 // For example, return 0 for "/", since there is no path after the leading |
| 48 // slash; return 3 for "/abc/def/gh.html". | 49 // slash; return 3 for "/abc/def/gh.html". |
| 49 size_t GetPathDepth(const std::string& cache_expression_path) { | 50 size_t GetPathDepth(const std::string& cache_expression_path) { |
| 50 return base::SplitString(base::StringPiece(cache_expression_path), "/", | 51 return base::SplitString(base::StringPiece(cache_expression_path), "/", |
| 51 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY) | 52 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY) |
| 52 .size(); | 53 .size(); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 url_key, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 344 url_key, GURL(), CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 344 std::string(), nullptr)); | 345 std::string(), nullptr)); |
| 345 | 346 |
| 346 // Move on if we have no cached verdict for this deleted history row. | 347 // Move on if we have no cached verdict for this deleted history row. |
| 347 if (!verdict_dictionary.get() || verdict_dictionary->empty()) | 348 if (!verdict_dictionary.get() || verdict_dictionary->empty()) |
| 348 continue; | 349 continue; |
| 349 | 350 |
| 350 int verdict_count = static_cast<int>(verdict_dictionary->size()); | 351 int verdict_count = static_cast<int>(verdict_dictionary->size()); |
| 351 stored_verdict_count_ = GetStoredVerdictCount() - verdict_count; | 352 stored_verdict_count_ = GetStoredVerdictCount() - verdict_count; |
| 352 content_settings_->ClearSettingsForOneTypeWithPredicate( | 353 content_settings_->ClearSettingsForOneTypeWithPredicate( |
| 353 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 354 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, std::string(), |
| 354 base::Bind(&OriginMatchPrimaryPattern, url_key)); | 355 base::Bind(&OriginMatchPrimaryPattern, url_key)); |
| 355 } | 356 } |
| 356 } | 357 } |
| 357 | 358 |
| 358 // static | 359 // static |
| 359 bool PasswordProtectionService::ParseVerdictEntry( | 360 bool PasswordProtectionService::ParseVerdictEntry( |
| 360 base::DictionaryValue* verdict_entry, | 361 base::DictionaryValue* verdict_entry, |
| 361 int* out_verdict_received_time, | 362 int* out_verdict_received_time, |
| 362 LoginReputationClientResponse* out_verdict) { | 363 LoginReputationClientResponse* out_verdict) { |
| 363 base::Value* binary_value = nullptr; | 364 base::Value* binary_value = nullptr; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 const std::vector<char> verdict_blob(serialized_proto.begin(), | 451 const std::vector<char> verdict_blob(serialized_proto.begin(), |
| 451 serialized_proto.end()); | 452 serialized_proto.end()); |
| 452 std::unique_ptr<base::Value> binary_value = | 453 std::unique_ptr<base::Value> binary_value = |
| 453 base::MakeUnique<base::Value>(verdict_blob); | 454 base::MakeUnique<base::Value>(verdict_blob); |
| 454 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); | 455 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type()); |
| 455 result->Set(kVerdictProto, std::move(binary_value)); | 456 result->Set(kVerdictProto, std::move(binary_value)); |
| 456 return result; | 457 return result; |
| 457 } | 458 } |
| 458 | 459 |
| 459 } // namespace safe_browsing | 460 } // namespace safe_browsing |
| OLD | NEW |