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. 4 5 #include "chrome/browser/pref_service_flags_storage.h" 6 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" 11 12 namespace about_flags { 13 PrefServiceFlagsStorage(PrefService * prefs)14PrefServiceFlagsStorage::PrefServiceFlagsStorage( 15 PrefService *prefs) : prefs_(prefs) {} 16 ~PrefServiceFlagsStorage()17PrefServiceFlagsStorage::~PrefServiceFlagsStorage() {} 18 GetFlags()19std::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(); 25 ++it) { 26 std::string experiment_name; 27 if (!(*it)->GetAsString(&experiment_name)) { 28 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; 29 continue; 30 } 31 flags.insert(experiment_name); 32 } 33 return flags; 34 } 35 SetFlags(const std::set<std::string> & flags)36bool PrefServiceFlagsStorage::SetFlags(const std::set<std::string>& flags) { 37 ListPrefUpdate update(prefs_, prefs::kEnabledLabsExperiments); 38 base::ListValue* experiments_list = update.Get(); 39 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)); 44 } 45 46 return true; 47 } 48 49 } // namespace about_flags 50