| 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" | |
| 48 #include "chromeos/chromeos_switches.h" | 46 #include "chromeos/chromeos_switches.h" |
| 49 #endif | 47 #endif |
| 50 | 48 |
| 51 using content::UserMetricsAction; | 49 using content::UserMetricsAction; |
| 52 | 50 |
| 53 namespace about_flags { | 51 namespace about_flags { |
| 54 | 52 |
| 55 // Macros to simplify specifying the type. | 53 // Macros to simplify specifying the type. |
| 56 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ | 54 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ |
| 57 Experiment::SINGLE_VALUE, \ | 55 Experiment::SINGLE_VALUE, \ |
| (...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 return Singleton<FlagsState>::get(); | 1299 return Singleton<FlagsState>::get(); |
| 1302 } | 1300 } |
| 1303 | 1301 |
| 1304 private: | 1302 private: |
| 1305 bool needs_restart_; | 1303 bool needs_restart_; |
| 1306 std::map<std::string, std::string> flags_switches_; | 1304 std::map<std::string, std::string> flags_switches_; |
| 1307 | 1305 |
| 1308 DISALLOW_COPY_AND_ASSIGN(FlagsState); | 1306 DISALLOW_COPY_AND_ASSIGN(FlagsState); |
| 1309 }; | 1307 }; |
| 1310 | 1308 |
| 1311 #if defined(OS_CHROMEOS) | |
| 1312 // Extracts the list of enabled lab experiments from device settings and stores | |
| 1313 // them in a set. | |
| 1314 void GetEnabledFlagsFromDeviceSettings(std::set<std::string>* result) { | |
| 1315 const ListValue* enabled_experiments; | |
| 1316 if (!chromeos::CrosSettings::Get()->GetList(chromeos::kStartUpFlags, | |
| 1317 &enabled_experiments)) { | |
| 1318 return; | |
| 1319 } | |
| 1320 | |
| 1321 for (ListValue::const_iterator it = enabled_experiments->begin(); | |
| 1322 it != enabled_experiments->end(); | |
| 1323 ++it) { | |
| 1324 std::string experiment_name; | |
| 1325 if (!(*it)->GetAsString(&experiment_name)) { | |
| 1326 LOG(WARNING) << "Invalid entry in " << chromeos::kStartUpFlags; | |
| 1327 continue; | |
| 1328 } | |
| 1329 result->insert(experiment_name); | |
| 1330 } | |
| 1331 } | |
| 1332 | |
| 1333 // Takes a set of enabled lab experiments and saves it into the device settings | |
| 1334 // storage on ChromeOS. | |
| 1335 void SetEnabledFlagsToDeviceSettings( | |
| 1336 const std::set<std::string>& enabled_experiments) { | |
| 1337 scoped_ptr<base::ListValue> experiments_list(new base::ListValue()); | |
| 1338 | |
| 1339 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); | |
| 1340 it != enabled_experiments.end(); | |
| 1341 ++it) { | |
| 1342 experiments_list->Append(new StringValue(*it)); | |
| 1343 } | |
| 1344 chromeos::CrosSettings::Get()->Set(chromeos::kStartUpFlags, | |
| 1345 *experiments_list); | |
| 1346 } | |
| 1347 #endif | |
| 1348 | |
| 1349 // Extracts the list of enabled lab experiments from preferences and stores them | 1309 // Extracts the list of enabled lab experiments from preferences and stores them |
| 1350 // in a set. On ChromeOS |prefs| can be NULL when reading machine level flags. | 1310 // in a set. |
| 1351 void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { | 1311 void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
| 1352 #if defined(OS_CHROMEOS) | |
| 1353 // On ChromeOS flags are stored in the device settings blob. | |
| 1354 if (!prefs) { | |
| 1355 GetEnabledFlagsFromDeviceSettings(result); | |
| 1356 return; | |
| 1357 } | |
| 1358 #else | |
| 1359 // Never allow |prefs| to be NULL on other platforms. | |
| 1360 CHECK(prefs); | |
| 1361 #endif | |
| 1362 | |
| 1363 const ListValue* enabled_experiments = prefs->GetList( | 1312 const ListValue* enabled_experiments = prefs->GetList( |
| 1364 prefs::kEnabledLabsExperiments); | 1313 prefs::kEnabledLabsExperiments); |
| 1365 if (!enabled_experiments) | 1314 if (!enabled_experiments) |
| 1366 return; | 1315 return; |
| 1367 | 1316 |
| 1368 for (ListValue::const_iterator it = enabled_experiments->begin(); | 1317 for (ListValue::const_iterator it = enabled_experiments->begin(); |
| 1369 it != enabled_experiments->end(); | 1318 it != enabled_experiments->end(); |
| 1370 ++it) { | 1319 ++it) { |
| 1371 std::string experiment_name; | 1320 std::string experiment_name; |
| 1372 if (!(*it)->GetAsString(&experiment_name)) { | 1321 if (!(*it)->GetAsString(&experiment_name)) { |
| 1373 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; | 1322 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; |
| 1374 continue; | 1323 continue; |
| 1375 } | 1324 } |
| 1376 result->insert(experiment_name); | 1325 result->insert(experiment_name); |
| 1377 } | 1326 } |
| 1378 } | 1327 } |
| 1379 | 1328 |
| 1380 // Takes a set of enabled lab experiments. On ChromeOS |prefs| can be NULL when | 1329 // Takes a set of enabled lab experiments |
| 1381 // setting machine level flags. | |
| 1382 void SetEnabledFlags( | 1330 void SetEnabledFlags( |
| 1383 PrefService* prefs, const std::set<std::string>& enabled_experiments) { | 1331 PrefService* prefs, const std::set<std::string>& enabled_experiments) { |
| 1384 #if defined(OS_CHROMEOS) | |
| 1385 // On ChromeOS flags are stored in the device settings blob. | |
| 1386 if (!prefs) { | |
| 1387 SetEnabledFlagsToDeviceSettings(enabled_experiments); | |
| 1388 return; | |
| 1389 } | |
| 1390 #else | |
| 1391 // Never allow |prefs| to be NULL on other platforms. | |
| 1392 CHECK(prefs); | |
| 1393 #endif | |
| 1394 | |
| 1395 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); | 1332 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); |
| 1396 ListValue* experiments_list = update.Get(); | 1333 ListValue* experiments_list = update.Get(); |
| 1397 | 1334 |
| 1398 experiments_list->Clear(); | 1335 experiments_list->Clear(); |
| 1399 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); | 1336 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
| 1400 it != enabled_experiments.end(); | 1337 it != enabled_experiments.end(); |
| 1401 ++it) { | 1338 ++it) { |
| 1402 experiments_list->Append(new StringValue(*it)); | 1339 experiments_list->Append(new StringValue(*it)); |
| 1403 } | 1340 } |
| 1404 } | 1341 } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 } | 1761 } |
| 1825 | 1762 |
| 1826 const Experiment* GetExperiments(size_t* count) { | 1763 const Experiment* GetExperiments(size_t* count) { |
| 1827 *count = num_experiments; | 1764 *count = num_experiments; |
| 1828 return experiments; | 1765 return experiments; |
| 1829 } | 1766 } |
| 1830 | 1767 |
| 1831 } // namespace testing | 1768 } // namespace testing |
| 1832 | 1769 |
| 1833 } // namespace about_flags | 1770 } // namespace about_flags |
| OLD | NEW |