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/chromeos/settings/owner_flags_storage.h" 6 7 #include "base/prefs/pref_service.h" 8 #include "base/values.h" 9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/chromeos/settings/cros_settings.h" 11 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 12 #include "chrome/common/pref_names.h" 13 14 namespace chromeos { 15 namespace about_flags { 16 17 OwnerFlagsStorage::OwnerFlagsStorage(PrefService *prefs, 18 CrosSettings *cros_settings) 19 : ::about_flags::PrefServiceFlagsStorage(prefs), 20 cros_settings_(cros_settings) { 21 // Make this code more unit test friendly. 22 if (g_browser_process->local_state()) { 23 const ListValue* legacy_experiments = 24 g_browser_process->local_state()->GetList( 25 prefs::kEnabledLabsExperiments); 26 if (!legacy_experiments->empty()) { 27 // If there are any flags set in local state migrate them to the owner's 28 // prefs and device settings. 29 std::set<std::string> flags; 30 for (ListValue::const_iterator it = legacy_experiments->begin(); 31 it != legacy_experiments->end(); ++it) { 32 std::string experiment_name; 33 if (!(*it)->GetAsString(&experiment_name)) { 34 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; 35 continue; 36 } 37 flags.insert(experiment_name); 38 } 39 SetFlags(flags); 40 g_browser_process->local_state()->ClearPref( 41 prefs::kEnabledLabsExperiments); 42 } 43 } 44 } 45 46 OwnerFlagsStorage::~OwnerFlagsStorage() {} 47 48 bool OwnerFlagsStorage::SetFlags(std::set<std::string> flags) { 49 PrefServiceFlagsStorage::SetFlags(flags); 50 51 base::ListValue experiments_list; 52 53 for (std::set<std::string>::const_iterator it = flags.begin(); 54 it != flags.end(); ++it) { 55 experiments_list.Append(new base::StringValue(*it)); 56 } 57 cros_settings_->Set(kStartUpFlags, experiments_list); 58 59 return true; 60 } 61 62 } // namespace about_flags 63 } // namespace chromeos 64