blob: 3932ded4a22125f1a39cd9382a091f486c0ac84b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// 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/values.h"
#include "build/build_config.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 base::ListValue* enabled_experiments =
prefs_->GetList(prefs::kEnabledLabsExperiments);
std::set<std::string> flags;
for (base::ListValue::const_iterator it = enabled_experiments->begin();
it != enabled_experiments->end(); ++it) {
std::string experiment_name;
if (!(*it)->GetAsString(&experiment_name)) {
LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
continue;
}
flags.insert(experiment_name);
}
return flags;
}
bool PrefServiceFlagsStorage::SetFlags(const std::set<std::string>& flags) {
ListPrefUpdate update(prefs_, prefs::kEnabledLabsExperiments);
base::ListValue* experiments_list = update.Get();
experiments_list->Clear();
for (std::set<std::string>::const_iterator it = flags.begin();
it != flags.end(); ++it) {
experiments_list->Append(new base::StringValue(*it));
}
return true;
}
// static
void PrefServiceFlagsStorage::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterListPref(prefs::kEnabledLabsExperiments);
}
#if defined(OS_CHROMEOS)
// static
void PrefServiceFlagsStorage::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterListPref(prefs::kEnabledLabsExperiments);
}
#endif // defined(OS_CHROMEOS)
} // namespace flags_ui
|