OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/about_flags.h" | 5 #include "chrome/browser/about_flags.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 #if defined(ENABLE_MESSAGE_CENTER) | 36 #if defined(ENABLE_MESSAGE_CENTER) |
37 #include "ui/message_center/message_center_switches.h" | 37 #include "ui/message_center/message_center_switches.h" |
38 #endif | 38 #endif |
39 | 39 |
40 #if defined(USE_ASH) | 40 #if defined(USE_ASH) |
41 #include "ash/ash_switches.h" | 41 #include "ash/ash_switches.h" |
42 #endif | 42 #endif |
43 | 43 |
44 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
45 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
46 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | |
45 #include "chromeos/chromeos_switches.h" | 47 #include "chromeos/chromeos_switches.h" |
46 #endif | 48 #endif |
47 | 49 |
48 using content::UserMetricsAction; | 50 using content::UserMetricsAction; |
49 | 51 |
50 namespace about_flags { | 52 namespace about_flags { |
51 | 53 |
52 // Macros to simplify specifying the type. | 54 // Macros to simplify specifying the type. |
53 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ | 55 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ |
54 Experiment::SINGLE_VALUE, \ | 56 Experiment::SINGLE_VALUE, \ |
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1277 return Singleton<FlagsState>::get(); | 1279 return Singleton<FlagsState>::get(); |
1278 } | 1280 } |
1279 | 1281 |
1280 private: | 1282 private: |
1281 bool needs_restart_; | 1283 bool needs_restart_; |
1282 std::map<std::string, std::string> flags_switches_; | 1284 std::map<std::string, std::string> flags_switches_; |
1283 | 1285 |
1284 DISALLOW_COPY_AND_ASSIGN(FlagsState); | 1286 DISALLOW_COPY_AND_ASSIGN(FlagsState); |
1285 }; | 1287 }; |
1286 | 1288 |
1289 #if defined(OS_CHROMEOS) | |
1290 // Extracts the list of enabled lab experiments from device settings and stores | |
1291 // them in a set. | |
1292 void GetEnabledFlagsFromDeviceSettings(std::set<std::string>* result) { | |
1293 const ListValue* enabled_experiments; | |
1294 if (!chromeos::CrosSettings::Get()->GetList(chromeos::kStartUpFlags, | |
1295 &enabled_experiments)) { | |
1296 return; | |
1297 } | |
1298 | |
1299 for (ListValue::const_iterator it = enabled_experiments->begin(); | |
1300 it != enabled_experiments->end(); | |
1301 ++it) { | |
1302 std::string experiment_name; | |
1303 if (!(*it)->GetAsString(&experiment_name)) { | |
1304 LOG(WARNING) << "Invalid entry in " << chromeos::kStartUpFlags; | |
1305 continue; | |
1306 } | |
1307 result->insert(experiment_name); | |
1308 } | |
1309 } | |
1310 | |
1311 // Takes a set of enabled lab experiments and saves it into the device settings | |
1312 // storage on ChormeOS. | |
Joao da Silva
2013/03/05 17:46:30
*ChromeOS
pastarmovj
2013/03/06 17:28:31
Done.
| |
1313 void SetEnabledFlagsToDeviceSettings( | |
1314 const std::set<std::string>& enabled_experiments) { | |
1315 scoped_ptr<base::ListValue> experiments_list(new base::ListValue()); | |
1316 | |
1317 experiments_list->Clear(); | |
Joao da Silva
2013/03/05 17:46:30
This is unnecessary.
pastarmovj
2013/03/06 17:28:31
Good catch of typical copy/paste error ;)
| |
1318 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); | |
1319 it != enabled_experiments.end(); | |
1320 ++it) { | |
1321 experiments_list->Append(new StringValue(*it)); | |
1322 } | |
1323 chromeos::CrosSettings::Get()->Set(chromeos::kStartUpFlags, | |
1324 *experiments_list); | |
1325 } | |
1326 #endif | |
1327 | |
1287 // Extracts the list of enabled lab experiments from preferences and stores them | 1328 // Extracts the list of enabled lab experiments from preferences and stores them |
1288 // in a set. | 1329 // in a set. On ChormeOS |prefs| can be NULL when settings machine level flags. |
Joao da Silva
2013/03/05 17:46:30
*ChromeOS, *setting
This function gets flags, doe
pastarmovj
2013/03/06 17:28:31
Done.
| |
1289 void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { | 1330 void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
1331 #if defined(OS_CHROMEOS) | |
1332 // On ChromeOS flags are stored in the device settings blob. | |
1333 if (!prefs) { | |
1334 GetEnabledFlagsFromDeviceSettings(result); | |
1335 return; | |
1336 } | |
1337 #else | |
1338 // Never allow |prefs| to be NULL on other platforms. | |
1339 CHECK(prefs); | |
1340 #endif | |
1341 | |
1290 const ListValue* enabled_experiments = prefs->GetList( | 1342 const ListValue* enabled_experiments = prefs->GetList( |
1291 prefs::kEnabledLabsExperiments); | 1343 prefs::kEnabledLabsExperiments); |
1292 if (!enabled_experiments) | 1344 if (!enabled_experiments) |
1293 return; | 1345 return; |
1294 | 1346 |
1295 for (ListValue::const_iterator it = enabled_experiments->begin(); | 1347 for (ListValue::const_iterator it = enabled_experiments->begin(); |
1296 it != enabled_experiments->end(); | 1348 it != enabled_experiments->end(); |
1297 ++it) { | 1349 ++it) { |
1298 std::string experiment_name; | 1350 std::string experiment_name; |
1299 if (!(*it)->GetAsString(&experiment_name)) { | 1351 if (!(*it)->GetAsString(&experiment_name)) { |
1300 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; | 1352 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; |
1301 continue; | 1353 continue; |
1302 } | 1354 } |
1303 result->insert(experiment_name); | 1355 result->insert(experiment_name); |
1304 } | 1356 } |
1305 } | 1357 } |
1306 | 1358 |
1307 // Takes a set of enabled lab experiments | 1359 // Takes a set of enabled lab experiments. On ChormeOS |prefs| can be NULL when |
Joao da Silva
2013/03/05 17:46:30
*ChromeOS
pastarmovj
2013/03/06 17:28:31
Done.
| |
1360 // settings machine level flags. | |
Joao da Silva
2013/03/05 17:46:30
*setting
pastarmovj
2013/03/06 17:28:31
Done.
| |
1308 void SetEnabledFlags( | 1361 void SetEnabledFlags( |
1309 PrefService* prefs, const std::set<std::string>& enabled_experiments) { | 1362 PrefService* prefs, const std::set<std::string>& enabled_experiments) { |
1363 #if defined(OS_CHROMEOS) | |
1364 // On ChromeOS flags are stored in the device settings blob. | |
1365 if (!prefs) { | |
1366 SetEnabledFlagsToDeviceSettings(enabled_experiments); | |
1367 return; | |
1368 } | |
1369 #else | |
1370 // Never allow |prefs| to be NULL on other platforms. | |
1371 CHECK(prefs); | |
1372 #endif | |
1373 | |
1310 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); | 1374 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); |
1311 ListValue* experiments_list = update.Get(); | 1375 ListValue* experiments_list = update.Get(); |
1312 | 1376 |
1313 experiments_list->Clear(); | 1377 experiments_list->Clear(); |
1314 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); | 1378 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
1315 it != enabled_experiments.end(); | 1379 it != enabled_experiments.end(); |
1316 ++it) { | 1380 ++it) { |
1317 experiments_list->Append(new StringValue(*it)); | 1381 experiments_list->Append(new StringValue(*it)); |
1318 } | 1382 } |
1319 } | 1383 } |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1739 } | 1803 } |
1740 | 1804 |
1741 const Experiment* GetExperiments(size_t* count) { | 1805 const Experiment* GetExperiments(size_t* count) { |
1742 *count = num_experiments; | 1806 *count = num_experiments; |
1743 return experiments; | 1807 return experiments; |
1744 } | 1808 } |
1745 | 1809 |
1746 } // namespace testing | 1810 } // namespace testing |
1747 | 1811 |
1748 } // namespace about_flags | 1812 } // namespace about_flags |
OLD | NEW |