12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- // Copyright 2013 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/flags_ui/pref_service_flags_storage.h"
- #include "base/logging.h"
- #include "base/values.h"
- #include "build/build_config.h"
- #include "build/chromeos_buildflags.h"
- #include "components/flags_ui/flags_ui_pref_names.h"
- #include "components/pref_registry/pref_registry_syncable.h"
- #include "components/prefs/pref_registry_simple.h"
- #include "components/prefs/pref_service.h"
- #include "components/prefs/scoped_user_pref_update.h"
- namespace flags_ui {
- PrefServiceFlagsStorage::PrefServiceFlagsStorage(PrefService* prefs)
- : prefs_(prefs) {}
- PrefServiceFlagsStorage::~PrefServiceFlagsStorage() {}
- std::set<std::string> PrefServiceFlagsStorage::GetFlags() const {
- const base::Value::List& enabled_experiments =
- prefs_->GetValueList(prefs::kAboutFlagsEntries);
- std::set<std::string> flags;
- for (const auto& entry : enabled_experiments) {
- if (!entry.is_string()) {
- LOG(WARNING) << "Invalid entry in " << prefs::kAboutFlagsEntries;
- continue;
- }
- flags.insert(entry.GetString());
- }
- return flags;
- }
- bool PrefServiceFlagsStorage::SetFlags(const std::set<std::string>& flags) {
- ListPrefUpdate update(prefs_, prefs::kAboutFlagsEntries);
- base::Value* experiments_list = update.Get();
- DCHECK(experiments_list->is_list());
- experiments_list->ClearList();
- for (const auto& flag : flags)
- experiments_list->Append(flag);
- return true;
- }
- std::string PrefServiceFlagsStorage::GetOriginListFlag(
- const std::string& internal_entry_name) const {
- const base::Value::Dict& origin_lists =
- prefs_->GetValueDict(prefs::kAboutFlagsOriginLists);
- if (const std::string* s = origin_lists.FindString(internal_entry_name))
- return *s;
- return std::string();
- }
- void PrefServiceFlagsStorage::SetOriginListFlag(
- const std::string& internal_entry_name,
- const std::string& origin_list_value) {
- DictionaryPrefUpdate update(prefs_, prefs::kAboutFlagsOriginLists);
- update->SetStringPath(internal_entry_name, origin_list_value);
- }
- void PrefServiceFlagsStorage::CommitPendingWrites() {
- prefs_->CommitPendingWrite();
- }
- // static
- void PrefServiceFlagsStorage::RegisterPrefs(PrefRegistrySimple* registry) {
- registry->RegisterListPref(prefs::kAboutFlagsEntries);
- registry->RegisterDictionaryPref(prefs::kAboutFlagsOriginLists);
- }
- #if BUILDFLAG(IS_CHROMEOS_ASH)
- // static
- void PrefServiceFlagsStorage::RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* registry) {
- registry->RegisterListPref(prefs::kAboutFlagsEntries);
- registry->RegisterDictionaryPref(prefs::kAboutFlagsOriginLists);
- }
- #endif // BUILDFLAG(IS_CHROMEOS_ASH)
- } // namespace flags_ui
|