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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 #if defined(ENABLE_MESSAGE_CENTER) | 37 #if defined(ENABLE_MESSAGE_CENTER) |
38 #include "ui/message_center/message_center_switches.h" | 38 #include "ui/message_center/message_center_switches.h" |
39 #endif | 39 #endif |
40 | 40 |
41 #if defined(USE_ASH) | 41 #if defined(USE_ASH) |
42 #include "ash/ash_switches.h" | 42 #include "ash/ash_switches.h" |
43 #endif | 43 #endif |
44 | 44 |
45 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
| 46 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 47 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
46 #include "chromeos/chromeos_switches.h" | 48 #include "chromeos/chromeos_switches.h" |
47 #endif | 49 #endif |
48 | 50 |
49 using content::UserMetricsAction; | 51 using content::UserMetricsAction; |
50 | 52 |
51 namespace about_flags { | 53 namespace about_flags { |
52 | 54 |
53 // Macros to simplify specifying the type. | 55 // Macros to simplify specifying the type. |
54 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ | 56 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ |
55 Experiment::SINGLE_VALUE, \ | 57 Experiment::SINGLE_VALUE, \ |
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 return Singleton<FlagsState>::get(); | 1312 return Singleton<FlagsState>::get(); |
1311 } | 1313 } |
1312 | 1314 |
1313 private: | 1315 private: |
1314 bool needs_restart_; | 1316 bool needs_restart_; |
1315 std::map<std::string, std::string> flags_switches_; | 1317 std::map<std::string, std::string> flags_switches_; |
1316 | 1318 |
1317 DISALLOW_COPY_AND_ASSIGN(FlagsState); | 1319 DISALLOW_COPY_AND_ASSIGN(FlagsState); |
1318 }; | 1320 }; |
1319 | 1321 |
| 1322 #if defined(OS_CHROMEOS) |
| 1323 // Extracts the list of enabled lab experiments from device settings and stores |
| 1324 // them in a set. |
| 1325 void GetEnabledFlagsFromDeviceSettings(std::set<std::string>* result) { |
| 1326 const ListValue* enabled_experiments; |
| 1327 if (!chromeos::CrosSettings::Get()->GetList(chromeos::kStartUpFlags, |
| 1328 &enabled_experiments)) { |
| 1329 return; |
| 1330 } |
| 1331 |
| 1332 for (ListValue::const_iterator it = enabled_experiments->begin(); |
| 1333 it != enabled_experiments->end(); |
| 1334 ++it) { |
| 1335 std::string experiment_name; |
| 1336 if (!(*it)->GetAsString(&experiment_name)) { |
| 1337 LOG(WARNING) << "Invalid entry in " << chromeos::kStartUpFlags; |
| 1338 continue; |
| 1339 } |
| 1340 result->insert(experiment_name); |
| 1341 } |
| 1342 } |
| 1343 |
| 1344 // Takes a set of enabled lab experiments and saves it into the device settings |
| 1345 // storage on ChromeOS. |
| 1346 void SetEnabledFlagsToDeviceSettings( |
| 1347 const std::set<std::string>& enabled_experiments) { |
| 1348 scoped_ptr<base::ListValue> experiments_list(new base::ListValue()); |
| 1349 |
| 1350 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
| 1351 it != enabled_experiments.end(); |
| 1352 ++it) { |
| 1353 experiments_list->Append(new StringValue(*it)); |
| 1354 } |
| 1355 chromeos::CrosSettings::Get()->Set(chromeos::kStartUpFlags, |
| 1356 *experiments_list); |
| 1357 } |
| 1358 #endif |
| 1359 |
1320 // Extracts the list of enabled lab experiments from preferences and stores them | 1360 // Extracts the list of enabled lab experiments from preferences and stores them |
1321 // in a set. | 1361 // in a set. On ChromeOS |prefs| can be NULL when reading machine level flags. |
1322 void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { | 1362 void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
| 1363 #if defined(OS_CHROMEOS) |
| 1364 // On ChromeOS flags are stored in the device settings blob. |
| 1365 if (!prefs) { |
| 1366 GetEnabledFlagsFromDeviceSettings(result); |
| 1367 return; |
| 1368 } |
| 1369 #else |
| 1370 // Never allow |prefs| to be NULL on other platforms. |
| 1371 CHECK(prefs); |
| 1372 #endif |
| 1373 |
1323 const ListValue* enabled_experiments = prefs->GetList( | 1374 const ListValue* enabled_experiments = prefs->GetList( |
1324 prefs::kEnabledLabsExperiments); | 1375 prefs::kEnabledLabsExperiments); |
1325 if (!enabled_experiments) | 1376 if (!enabled_experiments) |
1326 return; | 1377 return; |
1327 | 1378 |
1328 for (ListValue::const_iterator it = enabled_experiments->begin(); | 1379 for (ListValue::const_iterator it = enabled_experiments->begin(); |
1329 it != enabled_experiments->end(); | 1380 it != enabled_experiments->end(); |
1330 ++it) { | 1381 ++it) { |
1331 std::string experiment_name; | 1382 std::string experiment_name; |
1332 if (!(*it)->GetAsString(&experiment_name)) { | 1383 if (!(*it)->GetAsString(&experiment_name)) { |
1333 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; | 1384 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; |
1334 continue; | 1385 continue; |
1335 } | 1386 } |
1336 result->insert(experiment_name); | 1387 result->insert(experiment_name); |
1337 } | 1388 } |
1338 } | 1389 } |
1339 | 1390 |
1340 // Takes a set of enabled lab experiments | 1391 // Takes a set of enabled lab experiments. On ChromeOS |prefs| can be NULL when |
| 1392 // setting machine level flags. |
1341 void SetEnabledFlags( | 1393 void SetEnabledFlags( |
1342 PrefService* prefs, const std::set<std::string>& enabled_experiments) { | 1394 PrefService* prefs, const std::set<std::string>& enabled_experiments) { |
| 1395 #if defined(OS_CHROMEOS) |
| 1396 // On ChromeOS flags are stored in the device settings blob. |
| 1397 if (!prefs) { |
| 1398 SetEnabledFlagsToDeviceSettings(enabled_experiments); |
| 1399 return; |
| 1400 } |
| 1401 #else |
| 1402 // Never allow |prefs| to be NULL on other platforms. |
| 1403 CHECK(prefs); |
| 1404 #endif |
| 1405 |
1343 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); | 1406 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); |
1344 ListValue* experiments_list = update.Get(); | 1407 ListValue* experiments_list = update.Get(); |
1345 | 1408 |
1346 experiments_list->Clear(); | 1409 experiments_list->Clear(); |
1347 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); | 1410 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
1348 it != enabled_experiments.end(); | 1411 it != enabled_experiments.end(); |
1349 ++it) { | 1412 ++it) { |
1350 experiments_list->Append(new StringValue(*it)); | 1413 experiments_list->Append(new StringValue(*it)); |
1351 } | 1414 } |
1352 } | 1415 } |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 } | 1835 } |
1773 | 1836 |
1774 const Experiment* GetExperiments(size_t* count) { | 1837 const Experiment* GetExperiments(size_t* count) { |
1775 *count = num_experiments; | 1838 *count = num_experiments; |
1776 return experiments; | 1839 return experiments; |
1777 } | 1840 } |
1778 | 1841 |
1779 } // namespace testing | 1842 } // namespace testing |
1780 | 1843 |
1781 } // namespace about_flags | 1844 } // namespace about_flags |
OLD | NEW |