Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/browser/about_flags.cc

Issue 23983031: Owner flags storage should not save the flags names but the actual switches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/about_flags.h ('k') | chrome/browser/about_flags_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 }; 1660 };
1661 1661
1662 const Experiment* experiments = kExperiments; 1662 const Experiment* experiments = kExperiments;
1663 size_t num_experiments = arraysize(kExperiments); 1663 size_t num_experiments = arraysize(kExperiments);
1664 1664
1665 // Stores and encapsulates the little state that about:flags has. 1665 // Stores and encapsulates the little state that about:flags has.
1666 class FlagsState { 1666 class FlagsState {
1667 public: 1667 public:
1668 FlagsState() : needs_restart_(false) {} 1668 FlagsState() : needs_restart_(false) {}
1669 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, 1669 void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
1670 CommandLine* command_line); 1670 CommandLine* command_line,
1671 SentinelsMode sentinels);
1671 bool IsRestartNeededToCommitChanges(); 1672 bool IsRestartNeededToCommitChanges();
1672 void SetExperimentEnabled( 1673 void SetExperimentEnabled(
1673 FlagsStorage* flags_storage, 1674 FlagsStorage* flags_storage,
1674 const std::string& internal_name, 1675 const std::string& internal_name,
1675 bool enable); 1676 bool enable);
1676 void RemoveFlagsSwitches( 1677 void RemoveFlagsSwitches(
1677 std::map<std::string, CommandLine::StringType>* switch_list); 1678 std::map<std::string, CommandLine::StringType>* switch_list);
1678 void ResetAllFlags(FlagsStorage* flags_storage); 1679 void ResetAllFlags(FlagsStorage* flags_storage);
1679 void reset(); 1680 void reset();
1680 1681
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED, 1827 IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
1827 }; 1828 };
1828 description_id = kEnableDisableDescriptionIds[index]; 1829 description_id = kEnableDisableDescriptionIds[index];
1829 } else { 1830 } else {
1830 description_id = choices[index].description_id; 1831 description_id = choices[index].description_id;
1831 } 1832 }
1832 return l10n_util::GetStringUTF16(description_id); 1833 return l10n_util::GetStringUTF16(description_id);
1833 } 1834 }
1834 1835
1835 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, 1836 void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
1836 CommandLine* command_line) { 1837 CommandLine* command_line,
1838 SentinelsMode sentinels) {
1837 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage, 1839 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage,
1838 command_line); 1840 command_line,
1841 sentinels);
1839 } 1842 }
1840 1843
1841 bool AreSwitchesIdenticalToCurrentCommandLine( 1844 bool AreSwitchesIdenticalToCurrentCommandLine(
1842 const CommandLine& new_cmdline, const CommandLine& active_cmdline) { 1845 const CommandLine& new_cmdline, const CommandLine& active_cmdline) {
1843 std::set<CommandLine::StringType> new_flags = 1846 std::set<CommandLine::StringType> new_flags =
1844 ExtractFlagsFromCommandLine(new_cmdline); 1847 ExtractFlagsFromCommandLine(new_cmdline);
1845 std::set<CommandLine::StringType> active_flags = 1848 std::set<CommandLine::StringType> active_flags =
1846 ExtractFlagsFromCommandLine(active_cmdline); 1849 ExtractFlagsFromCommandLine(active_cmdline);
1847 1850
1848 // Needed because std::equal doesn't check if the 2nd set is empty. 1851 // Needed because std::equal doesn't check if the 2nd set is empty.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 NameToSwitchAndValueMap; 1967 NameToSwitchAndValueMap;
1965 1968
1966 void SetFlagToSwitchMapping(const std::string& key, 1969 void SetFlagToSwitchMapping(const std::string& key,
1967 const std::string& switch_name, 1970 const std::string& switch_name,
1968 const std::string& switch_value, 1971 const std::string& switch_value,
1969 NameToSwitchAndValueMap* name_to_switch_map) { 1972 NameToSwitchAndValueMap* name_to_switch_map) {
1970 DCHECK(name_to_switch_map->end() == name_to_switch_map->find(key)); 1973 DCHECK(name_to_switch_map->end() == name_to_switch_map->find(key));
1971 (*name_to_switch_map)[key] = std::make_pair(switch_name, switch_value); 1974 (*name_to_switch_map)[key] = std::make_pair(switch_name, switch_value);
1972 } 1975 }
1973 1976
1974 void FlagsState::ConvertFlagsToSwitches( 1977 void FlagsState::ConvertFlagsToSwitches(FlagsStorage* flags_storage,
1975 FlagsStorage* flags_storage, CommandLine* command_line) { 1978 CommandLine* command_line,
1979 SentinelsMode sentinels) {
1976 if (command_line->HasSwitch(switches::kNoExperiments)) 1980 if (command_line->HasSwitch(switches::kNoExperiments))
1977 return; 1981 return;
1978 1982
1979 std::set<std::string> enabled_experiments; 1983 std::set<std::string> enabled_experiments;
1980 1984
1981 GetSanitizedEnabledFlagsForCurrentPlatform(flags_storage, 1985 GetSanitizedEnabledFlagsForCurrentPlatform(flags_storage,
1982 &enabled_experiments); 1986 &enabled_experiments);
1983 1987
1984 NameToSwitchAndValueMap name_to_switch_map; 1988 NameToSwitchAndValueMap name_to_switch_map;
1985 for (size_t i = 0; i < num_experiments; ++i) { 1989 for (size_t i = 0; i < num_experiments; ++i) {
(...skipping 12 matching lines...) Expand all
1998 DCHECK_EQ(e.type, Experiment::ENABLE_DISABLE_VALUE); 2002 DCHECK_EQ(e.type, Experiment::ENABLE_DISABLE_VALUE);
1999 SetFlagToSwitchMapping(e.NameForChoice(0), std::string(), std::string(), 2003 SetFlagToSwitchMapping(e.NameForChoice(0), std::string(), std::string(),
2000 &name_to_switch_map); 2004 &name_to_switch_map);
2001 SetFlagToSwitchMapping(e.NameForChoice(1), e.command_line_switch, 2005 SetFlagToSwitchMapping(e.NameForChoice(1), e.command_line_switch,
2002 e.command_line_value, &name_to_switch_map); 2006 e.command_line_value, &name_to_switch_map);
2003 SetFlagToSwitchMapping(e.NameForChoice(2), e.disable_command_line_switch, 2007 SetFlagToSwitchMapping(e.NameForChoice(2), e.disable_command_line_switch,
2004 e.disable_command_line_value, &name_to_switch_map); 2008 e.disable_command_line_value, &name_to_switch_map);
2005 } 2009 }
2006 } 2010 }
2007 2011
2008 command_line->AppendSwitch(switches::kFlagSwitchesBegin); 2012 if (sentinels == kAddSentinels) {
2009 flags_switches_.insert( 2013 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
2010 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin, 2014 flags_switches_.insert(
2011 std::string())); 2015 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
2016 std::string()));
2017 }
2012 for (std::set<std::string>::iterator it = enabled_experiments.begin(); 2018 for (std::set<std::string>::iterator it = enabled_experiments.begin();
2013 it != enabled_experiments.end(); 2019 it != enabled_experiments.end();
2014 ++it) { 2020 ++it) {
2015 const std::string& experiment_name = *it; 2021 const std::string& experiment_name = *it;
2016 NameToSwitchAndValueMap::const_iterator name_to_switch_it = 2022 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
2017 name_to_switch_map.find(experiment_name); 2023 name_to_switch_map.find(experiment_name);
2018 if (name_to_switch_it == name_to_switch_map.end()) { 2024 if (name_to_switch_it == name_to_switch_map.end()) {
2019 NOTREACHED(); 2025 NOTREACHED();
2020 continue; 2026 continue;
2021 } 2027 }
2022 2028
2023 const std::pair<std::string, std::string>& 2029 const std::pair<std::string, std::string>&
2024 switch_and_value_pair = name_to_switch_it->second; 2030 switch_and_value_pair = name_to_switch_it->second;
2025 2031
2026 CHECK(!switch_and_value_pair.first.empty()); 2032 CHECK(!switch_and_value_pair.first.empty());
2027 command_line->AppendSwitchASCII(switch_and_value_pair.first, 2033 command_line->AppendSwitchASCII(switch_and_value_pair.first,
2028 switch_and_value_pair.second); 2034 switch_and_value_pair.second);
2029 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second; 2035 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
2030 } 2036 }
2031 command_line->AppendSwitch(switches::kFlagSwitchesEnd); 2037 if (sentinels == kAddSentinels) {
2032 flags_switches_.insert( 2038 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
2033 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd, 2039 flags_switches_.insert(
2034 std::string())); 2040 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
2041 std::string()));
2042 }
2035 } 2043 }
2036 2044
2037 bool FlagsState::IsRestartNeededToCommitChanges() { 2045 bool FlagsState::IsRestartNeededToCommitChanges() {
2038 return needs_restart_; 2046 return needs_restart_;
2039 } 2047 }
2040 2048
2041 void FlagsState::SetExperimentEnabled(FlagsStorage* flags_storage, 2049 void FlagsState::SetExperimentEnabled(FlagsStorage* flags_storage,
2042 const std::string& internal_name, 2050 const std::string& internal_name,
2043 bool enable) { 2051 bool enable) {
2044 size_t at_index = internal_name.find(testing::kMultiSeparator); 2052 size_t at_index = internal_name.find(testing::kMultiSeparator);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 } 2150 }
2143 2151
2144 const Experiment* GetExperiments(size_t* count) { 2152 const Experiment* GetExperiments(size_t* count) {
2145 *count = num_experiments; 2153 *count = num_experiments;
2146 return experiments; 2154 return experiments;
2147 } 2155 }
2148 2156
2149 } // namespace testing 2157 } // namespace testing
2150 2158
2151 } // namespace about_flags 2159 } // namespace about_flags
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.h ('k') | chrome/browser/about_flags_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698