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/chromeos/settings/owner_flags_storage.h"
7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/values.h"
10 #include "chrome/browser/about_flags.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/common/pref_names.h"
13 #include "chromeos/settings/cros_settings_names.h"
14 #include "components/ownership/owner_settings_service.h"
17 namespace about_flags
{
19 OwnerFlagsStorage::OwnerFlagsStorage(
21 ownership::OwnerSettingsService
* owner_settings_service
)
22 : ::about_flags::PrefServiceFlagsStorage(prefs
),
23 owner_settings_service_(owner_settings_service
) {
24 // Make this code more unit test friendly.
25 if (g_browser_process
->local_state()) {
26 const base::ListValue
* legacy_experiments
=
27 g_browser_process
->local_state()->GetList(
28 prefs::kEnabledLabsExperiments
);
29 if (!legacy_experiments
->empty()) {
30 // If there are any flags set in local state migrate them to the owner's
31 // prefs and device settings.
32 std::set
<std::string
> flags
;
33 for (base::ListValue::const_iterator it
= legacy_experiments
->begin();
34 it
!= legacy_experiments
->end(); ++it
) {
35 std::string experiment_name
;
36 if (!(*it
)->GetAsString(&experiment_name
)) {
37 LOG(WARNING
) << "Invalid entry in " << prefs::kEnabledLabsExperiments
;
40 flags
.insert(experiment_name
);
43 g_browser_process
->local_state()->ClearPref(
44 prefs::kEnabledLabsExperiments
);
49 OwnerFlagsStorage::~OwnerFlagsStorage() {}
51 bool OwnerFlagsStorage::SetFlags(const std::set
<std::string
>& flags
) {
52 PrefServiceFlagsStorage::SetFlags(flags
);
54 base::ListValue experiments_list
;
56 base::CommandLine
command_line(base::CommandLine::NO_PROGRAM
);
57 ::about_flags::ConvertFlagsToSwitches(this, &command_line
,
58 ::about_flags::kNoSentinels
);
59 base::CommandLine::StringVector switches
= command_line
.argv();
60 for (base::CommandLine::StringVector::const_iterator it
=
62 it
!= switches
.end(); ++it
) {
63 experiments_list
.Append(new base::StringValue(*it
));
65 owner_settings_service_
->Set(kStartUpFlags
, experiments_list
);
70 } // namespace about_flags
71 } // namespace chromeos