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

Unified Diff: chrome/browser/ui/webui/policy_ui_handler.cc

Issue 1940153002: Use std::unique_ptr to express ownership of base::Value in PolicyMap::Entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another-fix Created 4 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
Index: chrome/browser/ui/webui/policy_ui_handler.cc
diff --git a/chrome/browser/ui/webui/policy_ui_handler.cc b/chrome/browser/ui/webui/policy_ui_handler.cc
index c676d66d08a0168a5d117bac62d54136b3d25491..b26b7d94d6f967197ca2affa5f732bd71250b891 100644
--- a/chrome/browser/ui/webui/policy_ui_handler.cc
+++ b/chrome/browser/ui/webui/policy_ui_handler.cc
@@ -6,6 +6,8 @@
#include <stddef.h>
+#include <utility>
+
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
@@ -182,12 +184,12 @@ std::unique_ptr<base::Value> CopyAndConvert(const base::Value* value) {
if (value->GetAsDictionary(&dict))
return DictionaryToJSONString(*dict);
- std::unique_ptr<base::Value> copy(value->DeepCopy());
+ std::unique_ptr<base::Value> copy = value->CreateDeepCopy();
base::ListValue* list = NULL;
if (copy->GetAsList(&list)) {
for (size_t i = 0; i < list->GetSize(); ++i) {
if (list->GetDictionary(i, &dict))
- list->Set(i, DictionaryToJSONString(*dict).release());
+ list->Set(i, DictionaryToJSONString(*dict));
}
}
@@ -651,23 +653,22 @@ void PolicyUIHandler::SendPolicyValues() const {
void PolicyUIHandler::GetPolicyValues(const policy::PolicyMap& map,
policy::PolicyErrorMap* errors,
base::DictionaryValue* values) const {
- for (policy::PolicyMap::const_iterator entry = map.begin();
- entry != map.end(); ++entry) {
- base::DictionaryValue* value = new base::DictionaryValue;
- value->Set("value", CopyAndConvert(entry->second.value).release());
- if (entry->second.scope == policy::POLICY_SCOPE_USER)
+ for (const auto& entry : map) {
+ std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
+ value->Set("value", CopyAndConvert(entry.second.value.get()));
+ if (entry.second.scope == policy::POLICY_SCOPE_USER)
value->SetString("scope", "user");
else
value->SetString("scope", "machine");
- if (entry->second.level == policy::POLICY_LEVEL_RECOMMENDED)
+ if (entry.second.level == policy::POLICY_LEVEL_RECOMMENDED)
value->SetString("level", "recommended");
else
value->SetString("level", "mandatory");
- value->SetString("source", kPolicySources[entry->second.source].key);
- base::string16 error = errors->GetErrors(entry->first);
+ value->SetString("source", kPolicySources[entry.second.source].key);
+ base::string16 error = errors->GetErrors(entry.first);
if (!error.empty())
value->SetString("error", error);
- values->Set(entry->first, value);
+ values->Set(entry.first, std::move(value));
}
}
« no previous file with comments | « chrome/browser/ui/webui/policy_ui_browsertest.cc ('k') | components/policy/core/browser/android/policy_converter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698