1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/pref_service_flags_storage.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/prefs/scoped_user_pref_update.h"
9 #include "base/values.h"
10 #include "chrome/common/pref_names.h"
12 namespace about_flags
{
14 PrefServiceFlagsStorage::PrefServiceFlagsStorage(
15 PrefService
*prefs
) : prefs_(prefs
) {}
17 PrefServiceFlagsStorage::~PrefServiceFlagsStorage() {}
19 std::set
<std::string
> PrefServiceFlagsStorage::GetFlags() {
20 const base::ListValue
* enabled_experiments
= prefs_
->GetList(
21 prefs::kEnabledLabsExperiments
);
22 std::set
<std::string
> flags
;
23 for (base::ListValue::const_iterator it
= enabled_experiments
->begin();
24 it
!= enabled_experiments
->end();
26 std::string experiment_name
;
27 if (!(*it
)->GetAsString(&experiment_name
)) {
28 LOG(WARNING
) << "Invalid entry in " << prefs::kEnabledLabsExperiments
;
31 flags
.insert(experiment_name
);
36 bool PrefServiceFlagsStorage::SetFlags(const std::set
<std::string
>& flags
) {
37 ListPrefUpdate
update(prefs_
, prefs::kEnabledLabsExperiments
);
38 base::ListValue
* experiments_list
= update
.Get();
40 experiments_list
->Clear();
41 for (std::set
<std::string
>::const_iterator it
= flags
.begin();
42 it
!= flags
.end(); ++it
) {
43 experiments_list
->Append(new base::StringValue(*it
));
49 } // namespace about_flags