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

Unified Diff: extensions/browser/computed_hashes.cc

Issue 2899743002: Remove raw base::DictionaryValue::Set in //extensions (Closed)
Patch Set: Addressed nit Created 3 years, 6 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 | « extensions/browser/app_window/app_window.cc ('k') | extensions/browser/event_listener_map_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/computed_hashes.cc
diff --git a/extensions/browser/computed_hashes.cc b/extensions/browser/computed_hashes.cc
index 0758506bfc30a12694187fb001de60784b69ad71..47f5d1e02b1fc8653be3427164d26bb9ca60bad0 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>();
+ block_hashes->GetList().reserve(hashes.size());
+ for (const auto& hash : hashes) {
+ std::string encoded;
+ base::Base64Encode(hash, &encoded);
+ block_hashes->GetList().emplace_back(std::move(encoded));
+ }
+
+ 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;
« no previous file with comments | « extensions/browser/app_window/app_window.cc ('k') | extensions/browser/event_listener_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698