 Chromium Code Reviews
 Chromium Code Reviews Issue 2899743002:
  Remove raw base::DictionaryValue::Set in //extensions  (Closed)
    
  
    Issue 2899743002:
  Remove raw base::DictionaryValue::Set in //extensions  (Closed) 
  | Index: extensions/browser/computed_hashes.cc | 
| diff --git a/extensions/browser/computed_hashes.cc b/extensions/browser/computed_hashes.cc | 
| index 0758506bfc30a12694187fb001de60784b69ad71..33ac43dfeefbe8dc0f2468d34b733bd1dd76bf0a 100644 | 
| --- a/extensions/browser/computed_hashes.cc | 
| +++ b/extensions/browser/computed_hashes.cc | 
| @@ -12,6 +12,7 @@ | 
| #include "base/files/file_util.h" | 
| #include "base/json/json_reader.h" | 
| #include "base/json/json_writer.h" | 
| +#include "base/memory/ptr_util.h" | 
| #include "base/stl_util.h" | 
| #include "base/values.h" | 
| #include "crypto/secure_hash.h" | 
| @@ -136,28 +137,27 @@ ComputedHashes::Writer::~Writer() { | 
| void ComputedHashes::Writer::AddHashes(const base::FilePath& relative_path, | 
| int block_size, | 
| const std::vector<std::string>& hashes) { | 
| - std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 
| - base::ListValue* block_hashes = new base::ListValue(); | 
| + auto block_hashes = base::MakeUnique<base::ListValue>(); | 
| 
Devlin
2017/06/02 15:38:48
Since we're touching this code anyway, we should a
 
jdoerrie
2017/06/06 12:40:23
Done.
 | 
| + | 
| + for (const auto& hash : hashes) { | 
| + std::string encoded; | 
| + base::Base64Encode(hash, &encoded); | 
| + block_hashes->GetList().emplace_back(std::move(encoded)); | 
| 
Devlin
2017/06/02 15:38:48
Is this preferred over Append()/AppendString()?  (
 
jdoerrie
2017/06/06 12:40:23
Yes, Append* won't be part of the new API. To make
 | 
| + } | 
| + | 
| + auto dict = base::MakeUnique<base::DictionaryValue>(); | 
| dict->SetString(kPathKey, | 
| relative_path.NormalizePathSeparatorsTo('/').AsUTF8Unsafe()); | 
| dict->SetInteger(kBlockSizeKey, block_size); | 
| - dict->Set(kBlockHashesKey, block_hashes); | 
| + dict->Set(kBlockHashesKey, std::move(block_hashes)); | 
| file_list_->Append(std::move(dict)); | 
| - | 
| - for (std::vector<std::string>::const_iterator i = hashes.begin(); | 
| - i != hashes.end(); | 
| - ++i) { | 
| - std::string encoded; | 
| - base::Base64Encode(*i, &encoded); | 
| - block_hashes->AppendString(encoded); | 
| - } | 
| } | 
| bool ComputedHashes::Writer::WriteToFile(const base::FilePath& path) { | 
| std::string json; | 
| base::DictionaryValue top_dictionary; | 
| top_dictionary.SetInteger(kVersionKey, kVersion); | 
| - top_dictionary.Set(kFileHashesKey, file_list_.release()); | 
| + top_dictionary.Set(kFileHashesKey, std::move(file_list_)); | 
| if (!base::JSONWriter::Write(top_dictionary, &json)) | 
| return false; |