Commit f70d1235 authored by Sungguk Lim's avatar Sungguk Lim Committed by Commit Bot

Convert away from JSONReader::ReadDeprecated in computed_hashes.cc

Use the new JSONReader::Read API that use the new API of
base::Value (move semantic) and convert the surrounding
code to the new API at the same time.

Bug: 646113, 925165
Change-Id: I6d0a9e4d1f2131b756eb55fceb192153541695f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1677846Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: Sungguk Lim <limasdf@gmail.com>
Cr-Commit-Position: refs/heads/master@{#672628}
parent a0f3d77c
...@@ -79,57 +79,60 @@ bool ComputedHashes::Reader::InitFromFile(const base::FilePath& path) { ...@@ -79,57 +79,60 @@ bool ComputedHashes::Reader::InitFromFile(const base::FilePath& path) {
if (!base::ReadFileToString(path, &contents)) if (!base::ReadFileToString(path, &contents))
return false; return false;
base::DictionaryValue* top_dictionary = NULL; base::Optional<base::Value> top_dictionary = base::JSONReader::Read(contents);
std::unique_ptr<base::Value> value( if (!top_dictionary || !top_dictionary->is_dict())
base::JSONReader::ReadDeprecated(contents));
if (!value.get() || !value->GetAsDictionary(&top_dictionary))
return false; return false;
// For now we don't support forwards or backwards compatability in the // For now we don't support forwards or backwards compatability in the
// format, so we return false on version mismatch. // format, so we return false on version mismatch.
int version = 0; base::Optional<int> version =
if (!top_dictionary->GetInteger(computed_hashes::kVersionKey, &version) || top_dictionary->FindIntKey(computed_hashes::kVersionKey);
version != computed_hashes::kVersion) if (!version || *version != computed_hashes::kVersion)
return false; return false;
base::ListValue* all_hashes = NULL; const base::Value* all_hashes =
if (!top_dictionary->GetList(computed_hashes::kFileHashesKey, &all_hashes)) top_dictionary->FindListKey(computed_hashes::kFileHashesKey);
if (!all_hashes)
return false; return false;
for (size_t i = 0; i < all_hashes->GetSize(); i++) { for (const base::Value& file_hash : all_hashes->GetList()) {
base::DictionaryValue* dictionary = NULL; if (!file_hash.is_dict())
if (!all_hashes->GetDictionary(i, &dictionary))
return false; return false;
std::string relative_path_utf8; const std::string* relative_path_utf8 =
if (!dictionary->GetString(computed_hashes::kPathKey, &relative_path_utf8)) file_hash.FindStringKey(computed_hashes::kPathKey);
if (!relative_path_utf8)
return false; return false;
int block_size; base::Optional<int> block_size =
if (!dictionary->GetInteger(computed_hashes::kBlockSizeKey, &block_size)) file_hash.FindIntKey(computed_hashes::kBlockSizeKey);
if (!block_size)
return false; return false;
if (block_size <= 0 || ((block_size % 1024) != 0)) { if (*block_size <= 0 || ((*block_size % 1024) != 0)) {
LOG(ERROR) << "Invalid block size: " << block_size; LOG(ERROR) << "Invalid block size: " << *block_size;
return false; return false;
} }
base::ListValue* hashes_list = NULL; const base::Value* block_hashes =
if (!dictionary->GetList(computed_hashes::kBlockHashesKey, &hashes_list)) file_hash.FindListKey(computed_hashes::kBlockHashesKey);
if (!block_hashes)
return false; return false;
const base::Value::ListStorage& hashes_list = block_hashes->GetList();
base::FilePath relative_path = base::FilePath relative_path =
base::FilePath::FromUTF8Unsafe(relative_path_utf8); base::FilePath::FromUTF8Unsafe(*relative_path_utf8);
relative_path = relative_path.NormalizePathSeparatorsTo('/'); relative_path = relative_path.NormalizePathSeparatorsTo('/');
data_[relative_path] = HashInfo(block_size, std::vector<std::string>()); data_[relative_path] = HashInfo(*block_size, std::vector<std::string>());
std::vector<std::string>* hashes = &(data_[relative_path].second); std::vector<std::string>* hashes = &(data_[relative_path].second);
for (size_t j = 0; j < hashes_list->GetSize(); j++) { for (const base::Value& value : hashes_list) {
std::string encoded; if (!value.is_string())
if (!hashes_list->GetString(j, &encoded))
return false; return false;
hashes->push_back(std::string()); hashes->push_back(std::string());
const std::string& encoded = value.GetString();
std::string* decoded = &hashes->back(); std::string* decoded = &hashes->back();
if (!base::Base64Decode(encoded, decoded)) { if (!base::Base64Decode(encoded, decoded)) {
hashes->clear(); hashes->clear();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment