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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing/password_protection/password_protection_service.cc
diff --git a/components/safe_browsing/password_protection/password_protection_service.cc b/components/safe_browsing/password_protection/password_protection_service.cc
index d2ef322d9231a1f358fba401eebf118cb806a355..451a320cd69da0d6ab221407b50acab6a94789c0 100644
--- a/components/safe_browsing/password_protection/password_protection_service.cc
+++ b/components/safe_browsing/password_protection/password_protection_service.cc
@@ -4,6 +4,7 @@
#include "components/safe_browsing/password_protection/password_protection_service.h"
+#include "base/base64.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/memory/ptr_util.h"
@@ -469,18 +470,14 @@ bool PasswordProtectionService::ParseVerdictEntry(
base::DictionaryValue* verdict_entry,
int* out_verdict_received_time,
LoginReputationClientResponse* out_verdict) {
- base::Value* binary_value = nullptr;
- bool result = verdict_entry && out_verdict &&
- verdict_entry->GetInteger(kCacheCreationTime,
- out_verdict_received_time) &&
- verdict_entry->Get(kVerdictProto, &binary_value);
- if (!result)
- return false;
- DCHECK(result);
- DCHECK_EQ(base::Value::Type::BINARY, binary_value->type());
- const auto blob = binary_value->GetBlob();
- const std::string serialized_verdict_proto(blob.begin(), blob.end());
- return out_verdict->ParseFromString(serialized_verdict_proto);
+ std::string serialized_verdict_proto;
+ return verdict_entry && out_verdict &&
+ verdict_entry->GetInteger(kCacheCreationTime,
+ out_verdict_received_time) &&
+ verdict_entry->GetString(kVerdictProto, &serialized_verdict_proto) &&
+ base::Base64Decode(serialized_verdict_proto,
+ &serialized_verdict_proto) &&
+ out_verdict->ParseFromString(serialized_verdict_proto);
}
bool PasswordProtectionService::PathVariantsMatchCacheExpression(
@@ -542,15 +539,10 @@ PasswordProtectionService::CreateDictionaryFromVerdict(
base::MakeUnique<base::DictionaryValue>();
result->SetInteger(kCacheCreationTime,
static_cast<int>(receive_time.ToDoubleT()));
- // Because DictionaryValue cannot take non-UTF8 string, we need to store
- // serialized proto in its allowed binary format instead.
- const std::string serialized_proto(verdict->SerializeAsString());
- const std::vector<char> verdict_blob(serialized_proto.begin(),
- serialized_proto.end());
- std::unique_ptr<base::Value> binary_value =
- base::MakeUnique<base::Value>(verdict_blob);
- DCHECK_EQ(base::Value::Type::BINARY, binary_value->type());
- result->Set(kVerdictProto, std::move(binary_value));
+ std::string serialized_proto(verdict->SerializeAsString());
+ // Performs a base64 encoding on the serialized proto.
+ base::Base64Encode(serialized_proto, &serialized_proto);
+ result->SetString(kVerdictProto, serialized_proto);
return result;
}
« 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