
GetList() will be reimplemented in a future CL with an updated signature, so existing uses need to be renamed out of the way. Unlike TakeList() and TakeDict(), GetList() is used quite widely. This CL migrates a number of uses using the following set of automated steps: sed -i "s|->GetList()|->GetListDeprecated()|g" \ $(git gs "GetList()" --name-only) git checkout -- base/values_unittest.cc third_party/dom_distiller_js git cl format Bug: 1291666 Change-Id: I1b7a92fcb4874e7afb82d4bd092c1c9de2cc3d05 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3430698 Reviewed-by: danakj chromium <danakj@chromium.org> Owners-Override: danakj chromium <danakj@chromium.org> Commit-Queue: Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/main@{#966487}
40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "components/ntp_snippets/pref_util.h"
|
|
|
|
#include <memory>
|
|
|
|
#include "base/values.h"
|
|
#include "components/prefs/pref_service.h"
|
|
|
|
namespace ntp_snippets {
|
|
namespace prefs {
|
|
|
|
std::set<std::string> ReadDismissedIDsFromPrefs(const PrefService& pref_service,
|
|
const std::string& pref_name) {
|
|
std::set<std::string> dismissed_ids;
|
|
const base::Value* list = pref_service.GetList(pref_name);
|
|
for (const base::Value& value : list->GetListDeprecated()) {
|
|
DCHECK(value.is_string())
|
|
<< "Failed to parse dismissed id from prefs param " << pref_name
|
|
<< " into string.";
|
|
dismissed_ids.insert(value.GetString());
|
|
}
|
|
return dismissed_ids;
|
|
}
|
|
|
|
void StoreDismissedIDsToPrefs(PrefService* pref_service,
|
|
const std::string& pref_name,
|
|
const std::set<std::string>& dismissed_ids) {
|
|
base::ListValue list;
|
|
for (const std::string& dismissed_id : dismissed_ids) {
|
|
list.Append(dismissed_id);
|
|
}
|
|
pref_service->Set(pref_name, list);
|
|
}
|
|
|
|
} // namespace prefs
|
|
} // namespace ntp_snippets
|