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

Unified Diff: components/sync/driver/about_sync_util.cc

Issue 2823073003: Make Use of Value::GetList API
Patch Set: Further Usages Created 3 years, 8 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 | « components/ntp_snippets/pref_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/driver/about_sync_util.cc
diff --git a/components/sync/driver/about_sync_util.cc b/components/sync/driver/about_sync_util.cc
index b1863dcb08a7e56ad182d259cf16a1a688ba573b..3e8cfbf6ef60bc830eacf87b5d3b55f17638c9a9 100644
--- a/components/sync/driver/about_sync_util.cc
+++ b/components/sync/driver/about_sync_util.cc
@@ -22,7 +22,7 @@
#include "components/sync/protocol/proto_enum_conversions.h"
using base::DictionaryValue;
-using base::ListValue;
+using base::Value;
namespace syncer {
@@ -70,39 +70,38 @@ namespace {
// Creates a 'section' for display on about:sync, consisting of a title and a
// list of fields. Returns a pointer to the new section. Note that
// |parent_list|, not the caller, owns the newly added section.
-base::ListValue* AddSection(base::ListValue* parent_list,
- const std::string& title) {
- std::unique_ptr<base::DictionaryValue> section(new base::DictionaryValue());
- base::ListValue* section_contents = new base::ListValue();
- section->SetString("title", title);
- section->Set("data", section_contents);
- section->SetBoolean("is_sensitive", false);
+base::Value* AddSection(base::Value* parent_list, const std::string& title) {
+ base::DictionaryValue section;
+ base::Value* section_contents = new base::Value(base::Value::Type::LIST);
+ section.SetString("title", title);
+ section.Set("data", section_contents);
+ section.SetBoolean("is_sensitive", false);
// If the following |Append| results in a reallocation, pointers to the
// members of |parent_list| will be invalidated. This would result in
// use-after-free in |*SyncStat::SetValue|. This is why the following CHECK is
// necessary to ensure no reallocation takes place.
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- CHECK_LT(parent_list->GetSize(), parent_list->capacity());
- parent_list->Append(std::move(section));
+ CHECK_LT(parent_list->GetList().size(), parent_list->GetList().capacity());
+ parent_list->GetList().push_back(std::move(section));
return section_contents;
}
// Same as AddSection, but for data that should be elided when dumped into text
// form and posted in a public forum (e.g. unique identifiers).
-base::ListValue* AddSensitiveSection(base::ListValue* parent_list,
- const std::string& title) {
- std::unique_ptr<base::DictionaryValue> section(new base::DictionaryValue());
- base::ListValue* section_contents = new base::ListValue();
- section->SetString("title", title);
- section->Set("data", section_contents);
- section->SetBoolean("is_sensitive", true);
+base::Value* AddSensitiveSection(base::Value* parent_list,
+ const std::string& title) {
+ base::DictionaryValue section;
+ base::Value* section_contents = new base::Value(base::Value::Type::LIST);
+ section.SetString("title", title);
+ section.Set("data", section_contents);
+ section.SetBoolean("is_sensitive", true);
// If the following |Append| results in a reallocation, pointers to
// |parent_list| and its members will be invalidated. This would result in
// use-after-free in |*SyncStat::SetValue|. This is why the following CHECK is
// necessary to ensure no reallocation takes place.
- CHECK_LT(parent_list->GetSize(), parent_list->capacity());
+ CHECK_LT(parent_list->GetList().size(), parent_list->GetList().capacity());
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- parent_list->Append(std::move(section));
+ parent_list->GetList().push_back(std::move(section));
return section_contents;
}
@@ -115,7 +114,7 @@ base::ListValue* AddSensitiveSection(base::ListValue* parent_list,
class StringSyncStat {
public:
- StringSyncStat(base::ListValue* section, const std::string& key);
+ StringSyncStat(base::Value* section, const std::string& key);
void SetValue(const std::string& value);
void SetValue(const base::string16& value);
@@ -124,8 +123,7 @@ class StringSyncStat {
base::DictionaryValue* stat_;
};
-StringSyncStat::StringSyncStat(base::ListValue* section,
- const std::string& key) {
+StringSyncStat::StringSyncStat(base::Value* section, const std::string& key) {
stat_ = new base::DictionaryValue();
stat_->SetString("stat_name", key);
stat_->SetString("stat_value", "Uninitialized");
@@ -135,9 +133,9 @@ StringSyncStat::StringSyncStat(base::ListValue* section,
// other SyncStats will be invalidated. This is why the following check is
// necessary, so that it is guaranteed that a reallocation will not happen.
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- CHECK_LT(section->GetSize(), section->capacity());
- section->Append(base::WrapUnique(stat_));
- section->GetDictionary(section->GetSize() - 1, &stat_);
+ CHECK_LT(section->GetList().size(), section->GetList().capacity());
+ section->GetList().push_back(std::move(*stat_));
+ stat_ = static_cast<base::DictionaryValue*>(&section->GetList().back());
}
void StringSyncStat::SetValue(const std::string& value) {
@@ -152,7 +150,7 @@ void StringSyncStat::SetValue(const base::string16& value) {
class BoolSyncStat {
public:
- BoolSyncStat(base::ListValue* section, const std::string& key);
+ BoolSyncStat(base::Value* section, const std::string& key);
void SetValue(bool value);
private:
@@ -160,7 +158,7 @@ class BoolSyncStat {
base::DictionaryValue* stat_;
};
-BoolSyncStat::BoolSyncStat(base::ListValue* section, const std::string& key) {
+BoolSyncStat::BoolSyncStat(base::Value* section, const std::string& key) {
stat_ = new base::DictionaryValue();
stat_->SetString("stat_name", key);
stat_->SetBoolean("stat_value", false);
@@ -170,9 +168,9 @@ BoolSyncStat::BoolSyncStat(base::ListValue* section, const std::string& key) {
// other SyncStats will be invalidated. This is why the following check is
// necessary, so that it is guaranteed that a reallocation will not happen.
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- CHECK_LT(section->GetSize(), section->capacity());
- section->Append(base::WrapUnique(stat_));
- section->GetDictionary(section->GetSize() - 1, &stat_);
+ CHECK_LT(section->GetList().size(), section->GetList().capacity());
+ section->GetList().push_back(std::move(*stat_));
+ stat_ = static_cast<base::DictionaryValue*>(&section->GetList().back());
}
void BoolSyncStat::SetValue(bool value) {
@@ -182,7 +180,7 @@ void BoolSyncStat::SetValue(bool value) {
class IntSyncStat {
public:
- IntSyncStat(base::ListValue* section, const std::string& key);
+ IntSyncStat(base::Value* section, const std::string& key);
void SetValue(int value);
private:
@@ -190,7 +188,7 @@ class IntSyncStat {
base::DictionaryValue* stat_;
};
-IntSyncStat::IntSyncStat(base::ListValue* section, const std::string& key) {
+IntSyncStat::IntSyncStat(base::Value* section, const std::string& key) {
stat_ = new base::DictionaryValue();
stat_->SetString("stat_name", key);
stat_->SetInteger("stat_value", 0);
@@ -200,9 +198,9 @@ IntSyncStat::IntSyncStat(base::ListValue* section, const std::string& key) {
// other SyncStats will be invalidated. This is why the following check is
// necessary, so that it is guaranteed that a reallocation will not happen.
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- CHECK_LT(section->GetSize(), section->capacity());
- section->Append(base::WrapUnique(stat_));
- section->GetDictionary(section->GetSize() - 1, &stat_);
+ CHECK_LT(section->GetList().size(), section->GetList().capacity());
+ section->GetList().push_back(std::move(*stat_));
+ stat_ = static_cast<base::DictionaryValue*>(&section->GetList().back());
}
void IntSyncStat::SetValue(int value) {
@@ -284,44 +282,44 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
new base::DictionaryValue());
// 'details': A list of sections.
- base::ListValue* stats_list = new base::ListValue();
+ base::Value* stats_list = new base::Value(base::Value::Type::LIST);
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- stats_list->Reserve(12);
+ stats_list->GetList().reserve(12);
// The following lines define the sections and their fields. For each field,
// a class is instantiated, which allows us to reference the fields in
// 'setter' code later on in this function.
- base::ListValue* section_summary = AddSection(stats_list, "Summary");
+ base::Value* section_summary = AddSection(stats_list, "Summary");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_summary->Reserve(1);
+ section_summary->GetList().reserve(1);
StringSyncStat summary_string(section_summary, "Summary");
- base::ListValue* section_version = AddSection(stats_list, "Version Info");
+ base::Value* section_version = AddSection(stats_list, "Version Info");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_version->Reserve(2);
+ section_version->GetList().reserve(2);
StringSyncStat client_version(section_version, "Client Version");
StringSyncStat server_url(section_version, "Server URL");
- base::ListValue* section_identity =
+ base::Value* section_identity =
AddSensitiveSection(stats_list, kIdentityTitle);
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_identity->Reserve(3);
+ section_identity->GetList().reserve(3);
StringSyncStat sync_id(section_identity, "Sync Client ID");
StringSyncStat invalidator_id(section_identity, "Invalidator Client ID");
StringSyncStat username(section_identity, "Username");
- base::ListValue* section_credentials = AddSection(stats_list, "Credentials");
+ base::Value* section_credentials = AddSection(stats_list, "Credentials");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_credentials->Reserve(4);
+ section_credentials->GetList().reserve(4);
StringSyncStat request_token_time(section_credentials, "Requested Token");
StringSyncStat receive_token_time(section_credentials, "Received Token");
StringSyncStat token_request_status(section_credentials,
"Token Request Status");
StringSyncStat next_token_request(section_credentials, "Next Token Request");
- base::ListValue* section_local = AddSection(stats_list, "Local State");
+ base::Value* section_local = AddSection(stats_list, "Local State");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_local->Reserve(7);
+ section_local->GetList().reserve(7);
StringSyncStat server_connection(section_local, "Server Connection");
StringSyncStat last_synced(section_local, "Last Synced");
BoolSyncStat is_setup_complete(section_local,
@@ -333,17 +331,17 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
"Local sync backend enabled");
StringSyncStat local_backend_path(section_local, "Local backend path");
- base::ListValue* section_network = AddSection(stats_list, "Network");
+ base::Value* section_network = AddSection(stats_list, "Network");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_network->Reserve(3);
+ section_network->GetList().reserve(3);
BoolSyncStat is_throttled(section_network, "Throttled");
StringSyncStat retry_time(section_network, "Retry time (maybe stale)");
BoolSyncStat are_notifications_enabled(section_network,
"Notifications Enabled");
- base::ListValue* section_encryption = AddSection(stats_list, "Encryption");
+ base::Value* section_encryption = AddSection(stats_list, "Encryption");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_encryption->Reserve(9);
+ section_encryption->GetList().reserve(9);
BoolSyncStat is_using_explicit_passphrase(section_encryption,
"Explicit Passphrase");
BoolSyncStat is_passphrase_required(section_encryption,
@@ -359,18 +357,18 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
StringSyncStat passphrase_type(section_encryption, "Passphrase Type");
StringSyncStat passphrase_time(section_encryption, "Passphrase Time");
- base::ListValue* section_last_session =
+ base::Value* section_last_session =
AddSection(stats_list, "Status from Last Completed Session");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_last_session->Reserve(4);
+ section_last_session->GetList().reserve(4);
StringSyncStat session_source(section_last_session, "Sync Source");
StringSyncStat get_key_result(section_last_session, "GetKey Step Result");
StringSyncStat download_result(section_last_session, "Download Step Result");
StringSyncStat commit_result(section_last_session, "Commit Step Result");
- base::ListValue* section_counters = AddSection(stats_list, "Running Totals");
+ base::Value* section_counters = AddSection(stats_list, "Running Totals");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_counters->Reserve(7);
+ section_counters->GetList().reserve(7);
IntSyncStat notifications_received(section_counters,
"Notifications Received");
IntSyncStat updates_received(section_counters, "Updates Downloaded");
@@ -382,27 +380,27 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
IntSyncStat conflicts_resolved_server_wins(section_counters,
"Conflicts Resolved: Server Wins");
- base::ListValue* section_this_cycle =
+ base::Value* section_this_cycle =
AddSection(stats_list, "Transient Counters (this cycle)");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_this_cycle->Reserve(4);
+ section_this_cycle->GetList().reserve(4);
IntSyncStat encryption_conflicts(section_this_cycle, "Encryption Conflicts");
IntSyncStat hierarchy_conflicts(section_this_cycle, "Hierarchy Conflicts");
IntSyncStat server_conflicts(section_this_cycle, "Server Conflicts");
IntSyncStat committed_items(section_this_cycle, "Committed Items");
- base::ListValue* section_that_cycle = AddSection(
+ base::Value* section_that_cycle = AddSection(
stats_list, "Transient Counters (last cycle of last completed session)");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_that_cycle->Reserve(3);
+ section_that_cycle->GetList().reserve(3);
IntSyncStat updates_downloaded(section_that_cycle, "Updates Downloaded");
IntSyncStat committed_count(section_that_cycle, "Committed Count");
IntSyncStat entries(section_that_cycle, "Entries");
- base::ListValue* section_nudge_info =
+ base::Value* section_nudge_info =
AddSection(stats_list, "Nudge Source Counters");
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- section_nudge_info->Reserve(3);
+ section_nudge_info->GetList().reserve(3);
IntSyncStat nudge_source_notification(section_nudge_info,
"Server Invalidations");
IntSyncStat nudge_source_local(section_nudge_info, "Local Changes");
@@ -550,9 +548,9 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
// NOTE: We won't bother showing any of the following values unless
// actionable_error_detected is set.
- base::ListValue* actionable_error = new base::ListValue();
+ base::Value* actionable_error = new base::Value(base::Value::Type::LIST);
// TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
- actionable_error->Reserve(4);
+ actionable_error->GetList().reserve(4);
about_info->Set("actionable_error", actionable_error);
StringSyncStat error_type(actionable_error, "Error Type");
« no previous file with comments | « components/ntp_snippets/pref_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698