Skip to content

Commit

Permalink
Add reset all button to flags page
Browse files Browse the repository at this point in the history
Adds a "Reset all to default" button at the top of the flags page to simplify
getting all experiments back to their default state.

BUG=139307


Review URL: https://chromiumcodereview.appspot.com/12276012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183357 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jryans@chromium.org committed Feb 20, 2013
1 parent 270f034 commit cb93bf5
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,4 @@ Sylvain Zimmer <sylvinus@gmail.com>
Sungmann Cho <sungmann.cho@gmail.com>
方觉 (Fang Jue) <fangjue23303@gmail.com>
Evan Peterson <evan.peterson.ep@gmail.com>
J. Ryan Stinnett <jryans@chromium.org>
3 changes: 3 additions & 0 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -6126,6 +6126,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
Restart Now
</message>
</if>
<message name="IDS_FLAGS_RESET_ALL_BUTTON" desc="Text on a button that resets all experiments to their default state when clicked.">
Reset all to default
</message>
<message name="IDS_FLAGS_DISABLE" desc="The link for disabling a labs experiment.">
Disable
</message>
Expand Down
12 changes: 12 additions & 0 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ class FlagsState {
PrefService* prefs, const std::string& internal_name, bool enable);
void RemoveFlagsSwitches(
std::map<std::string, CommandLine::StringType>* switch_list);
void ResetAllFlags(PrefService* prefs);
void reset();

// Returns the singleton instance of this class
Expand Down Expand Up @@ -1530,6 +1531,10 @@ void RemoveFlagsSwitches(
FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
}

void ResetAllFlags(PrefService* prefs) {
FlagsState::GetInstance()->ResetAllFlags(prefs);
}

int GetCurrentPlatform() {
#if defined(OS_MACOSX)
return kOsMac;
Expand Down Expand Up @@ -1695,6 +1700,13 @@ void FlagsState::RemoveFlagsSwitches(
}
}

void FlagsState::ResetAllFlags(PrefService* prefs) {
needs_restart_ = true;

std::set<std::string> no_experiments;
SetEnabledFlags(prefs, no_experiments);
}

void FlagsState::reset() {
needs_restart_ = false;
flags_switches_.clear();
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/about_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ void SetExperimentEnabled(
void RemoveFlagsSwitches(
std::map<std::string, CommandLine::StringType>* switch_list);

// Reset all flags to the default state by clearing all flags.
void ResetAllFlags(PrefService* prefs);

// Returns the value for the current platform. This is one of the values defined
// by the OS enum above.
// This is exposed only for testing.
Expand Down
13 changes: 10 additions & 3 deletions chrome/browser/resources/flags.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ div.content {
}

.section-header {
-webkit-padding-start: 5px;
background: rgb(235, 239, 249);
border-top: 1px solid rgb(181, 199, 222);
font-size: 99%;
padding-bottom: 2px;
padding-top: 3px;
padding: 2px 5px 3px;
width: 100%;
}

Expand All @@ -82,6 +80,15 @@ div.content {

.section-header-title {
font-weight: bold;
line-height: 200%;
}

#experiment-reset-all {
float: right;
}

html[dir=rtl] #experiment-reset-all {
float: left;
}

.vbox-container {
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/resources/flags.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<td>
<span class="section-header-title" i18n-content="flagsTableTitle"
>TITLE</span>
<button id="experiment-reset-all" type="button"
i18n-content="resetAllButton"></button>
</td>
</tr></table>
</div>
Expand Down
11 changes: 11 additions & 0 deletions chrome/browser/resources/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ function renderTemplate(flagsExperimentsData) {
for (var i = 0; i < elements.length; ++i) {
elements[i].onclick = restartBrowser;
}

$('experiment-reset-all').onclick = resetAllFlags;
}

/**
Expand All @@ -67,6 +69,15 @@ function restartBrowser() {
chrome.send('restartBrowser');
}

/**
* Reset all flags to their default values and refresh the UI.
*/
function resetAllFlags() {
// Asks the C++ FlagsDOMHandler to reset all flags to default values.
chrome.send('resetAllFlags');
requestFlagsExperimentsData();
}

/**
* Called by the WebUI to re-populate the page with data representing the
* current state of installed experiments.
Expand Down
11 changes: 11 additions & 0 deletions chrome/browser/ui/webui/flags_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ content::WebUIDataSource* CreateFlagsUIHTMLSource() {
source->AddLocalizedString("flagsNotSupported", IDS_FLAGS_NOT_AVAILABLE);
source->AddLocalizedString("flagsRestartNotice", IDS_FLAGS_RELAUNCH_NOTICE);
source->AddLocalizedString("flagsRestartButton", IDS_FLAGS_RELAUNCH_BUTTON);
source->AddLocalizedString("resetAllButton", IDS_FLAGS_RESET_ALL_BUTTON);
source->AddLocalizedString("disable", IDS_FLAGS_DISABLE);
source->AddLocalizedString("enable", IDS_FLAGS_ENABLE);
#if defined(OS_CHROMEOS)
Expand Down Expand Up @@ -101,6 +102,9 @@ class FlagsDOMHandler : public WebUIMessageHandler {
// Callback for the "restartBrowser" message. Restores all tabs on restart.
void HandleRestartBrowser(const ListValue* args);

// Callback for the "resetAllFlags" message.
void HandleResetAllFlags(const ListValue* args);

private:
DISALLOW_COPY_AND_ASSIGN(FlagsDOMHandler);
};
Expand All @@ -115,6 +119,9 @@ void FlagsDOMHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("restartBrowser",
base::Bind(&FlagsDOMHandler::HandleRestartBrowser,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("resetAllFlags",
base::Bind(&FlagsDOMHandler::HandleResetAllFlags,
base::Unretained(this)));
}

void FlagsDOMHandler::HandleRequestFlagsExperiments(const ListValue* args) {
Expand Down Expand Up @@ -149,6 +156,10 @@ void FlagsDOMHandler::HandleRestartBrowser(const ListValue* args) {
chrome::AttemptRestart();
}

void FlagsDOMHandler::HandleResetAllFlags(const ListValue* args) {
about_flags::ResetAllFlags(g_browser_process->local_state());
}

} // namespace

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit cb93bf5

Please sign in to comment.