Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(792)

Side by Side Diff: components/safe_browsing/password_protection/password_protection_service.cc

Issue 2895323002: Change string data instead of binary in content settings. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base64.h"
7 #include "base/bind.h" 8 #include "base/bind.h"
8 #include "base/callback.h" 9 #include "base/callback.h"
9 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
11 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "components/content_settings/core/browser/host_content_settings_map.h" 16 #include "components/content_settings/core/browser/host_content_settings_map.h"
16 #include "components/history/core/browser/history_service.h" 17 #include "components/history/core/browser/history_service.h"
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, base::Time(), 463 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, base::Time(),
463 base::Bind(&OriginMatchPrimaryPattern, url_key)); 464 base::Bind(&OriginMatchPrimaryPattern, url_key));
464 } 465 }
465 } 466 }
466 467
467 // static 468 // static
468 bool PasswordProtectionService::ParseVerdictEntry( 469 bool PasswordProtectionService::ParseVerdictEntry(
469 base::DictionaryValue* verdict_entry, 470 base::DictionaryValue* verdict_entry,
470 int* out_verdict_received_time, 471 int* out_verdict_received_time,
471 LoginReputationClientResponse* out_verdict) { 472 LoginReputationClientResponse* out_verdict) {
472 base::Value* binary_value = nullptr; 473 std::string serialized_verdict_proto;
473 bool result = verdict_entry && out_verdict && 474 return verdict_entry && out_verdict &&
474 verdict_entry->GetInteger(kCacheCreationTime, 475 verdict_entry->GetInteger(kCacheCreationTime,
475 out_verdict_received_time) && 476 out_verdict_received_time) &&
476 verdict_entry->Get(kVerdictProto, &binary_value); 477 verdict_entry->GetString(kVerdictProto, &serialized_verdict_proto) &&
477 if (!result) 478 base::Base64Decode(serialized_verdict_proto,
478 return false; 479 &serialized_verdict_proto) &&
479 DCHECK(result); 480 out_verdict->ParseFromString(serialized_verdict_proto);
480 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type());
481 const auto blob = binary_value->GetBlob();
482 const std::string serialized_verdict_proto(blob.begin(), blob.end());
483 return out_verdict->ParseFromString(serialized_verdict_proto);
484 } 481 }
485 482
486 bool PasswordProtectionService::PathVariantsMatchCacheExpression( 483 bool PasswordProtectionService::PathVariantsMatchCacheExpression(
487 const std::vector<std::string>& generated_paths, 484 const std::vector<std::string>& generated_paths,
488 const std::string& cache_expression_path) { 485 const std::string& cache_expression_path) {
489 for (const auto& path : generated_paths) { 486 for (const auto& path : generated_paths) {
490 if (cache_expression_path == path) 487 if (cache_expression_path == path)
491 return true; 488 return true;
492 } 489 }
493 return false; 490 return false;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 532
536 // Convert a LoginReputationClientResponse proto into a DictionaryValue. 533 // Convert a LoginReputationClientResponse proto into a DictionaryValue.
537 std::unique_ptr<base::DictionaryValue> 534 std::unique_ptr<base::DictionaryValue>
538 PasswordProtectionService::CreateDictionaryFromVerdict( 535 PasswordProtectionService::CreateDictionaryFromVerdict(
539 const LoginReputationClientResponse* verdict, 536 const LoginReputationClientResponse* verdict,
540 const base::Time& receive_time) { 537 const base::Time& receive_time) {
541 std::unique_ptr<base::DictionaryValue> result = 538 std::unique_ptr<base::DictionaryValue> result =
542 base::MakeUnique<base::DictionaryValue>(); 539 base::MakeUnique<base::DictionaryValue>();
543 result->SetInteger(kCacheCreationTime, 540 result->SetInteger(kCacheCreationTime,
544 static_cast<int>(receive_time.ToDoubleT())); 541 static_cast<int>(receive_time.ToDoubleT()));
545 // Because DictionaryValue cannot take non-UTF8 string, we need to store 542 std::string serialized_proto(verdict->SerializeAsString());
546 // serialized proto in its allowed binary format instead. 543 // Performs a base64 encoding on the serialized proto.
547 const std::string serialized_proto(verdict->SerializeAsString()); 544 base::Base64Encode(serialized_proto, &serialized_proto);
548 const std::vector<char> verdict_blob(serialized_proto.begin(), 545 result->SetString(kVerdictProto, serialized_proto);
549 serialized_proto.end());
550 std::unique_ptr<base::Value> binary_value =
551 base::MakeUnique<base::Value>(verdict_blob);
552 DCHECK_EQ(base::Value::Type::BINARY, binary_value->type());
553 result->Set(kVerdictProto, std::move(binary_value));
554 return result; 546 return result;
555 } 547 }
556 548
557 void PasswordProtectionService::RecordPingingDisabledReason( 549 void PasswordProtectionService::RecordPingingDisabledReason(
558 const base::Feature& feature, 550 const base::Feature& feature,
559 RequestOutcome reason) { 551 RequestOutcome reason) {
560 DCHECK(feature.name == kProtectedPasswordEntryPinging.name || 552 DCHECK(feature.name == kProtectedPasswordEntryPinging.name ||
561 feature.name == kPasswordFieldOnFocusPinging.name); 553 feature.name == kPasswordFieldOnFocusPinging.name);
562 554
563 bool is_password_entry_ping = 555 bool is_password_entry_ping =
564 feature.name == kProtectedPasswordEntryPinging.name; 556 feature.name == kProtectedPasswordEntryPinging.name;
565 557
566 if (is_password_entry_ping) { 558 if (is_password_entry_ping) {
567 UMA_HISTOGRAM_ENUMERATION(kPasswordEntryRequestOutcomeHistogramName, reason, 559 UMA_HISTOGRAM_ENUMERATION(kPasswordEntryRequestOutcomeHistogramName, reason,
568 MAX_OUTCOME); 560 MAX_OUTCOME);
569 } else { 561 } else {
570 UMA_HISTOGRAM_ENUMERATION(kPasswordOnFocusRequestOutcomeHistogramName, 562 UMA_HISTOGRAM_ENUMERATION(kPasswordOnFocusRequestOutcomeHistogramName,
571 reason, MAX_OUTCOME); 563 reason, MAX_OUTCOME);
572 } 564 }
573 } 565 }
574 566
575 } // namespace safe_browsing 567 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698