blob: 751ac1e1df6bb4dac7749602775d552b4aed4ac4 (
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
|
// 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 "chrome/browser/pref_service_flags_storage.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/values.h"
#include "chrome/common/pref_names.h"
namespace about_flags {
PrefServiceFlagsStorage::PrefServiceFlagsStorage(
PrefService *prefs) : prefs_(prefs) {}
PrefServiceFlagsStorage::~PrefServiceFlagsStorage() {}
std::set<std::string> PrefServiceFlagsStorage::GetFlags() {
const ListValue* enabled_experiments = prefs_->GetList(
prefs::kEnabledLabsExperiments);
std::set<std::string> flags;
for (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);
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 StringValue(*it));
}
return true;
}
} // namespace about_flags
|