| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/webui/options/reset_profile_settings_handler.h" | 5 #include "chrome/browser/ui/webui/settings/reset_profile_settings_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/google/google_brand.h" | 13 #include "chrome/browser/google/google_brand.h" |
| 14 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" | 14 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" |
| 15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h" | 15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h" |
| 16 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" | 16 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" |
| 17 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" | 17 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" |
| 18 #include "chrome/browser/profile_resetter/profile_resetter.h" | 18 #include "chrome/browser/profile_resetter/profile_resetter.h" |
| 19 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" | 19 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "chrome/grit/chromium_strings.h" | 22 #include "chrome/grit/chromium_strings.h" |
| 23 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 24 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 25 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | |
| 27 | 26 |
| 28 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 29 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | 28 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" |
| 30 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" | 29 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" |
| 31 #endif // defined(OS_WIN) | 30 #endif // defined(OS_WIN) |
| 32 | 31 |
| 33 namespace options { | 32 namespace settings { |
| 34 | 33 |
| 35 ResetProfileSettingsHandler::ResetProfileSettingsHandler() | 34 ResetProfileSettingsHandler::ResetProfileSettingsHandler(content::WebUI* web_ui) |
| 36 : automatic_profile_resetter_(NULL), | 35 : automatic_profile_resetter_(NULL), |
| 37 has_shown_confirmation_dialog_(false) { | 36 has_shown_confirmation_dialog_(false) { |
| 38 google_brand::GetBrand(&brandcode_); | 37 google_brand::GetBrand(&brandcode_); |
| 39 } | 38 Profile* profile = Profile::FromWebUI(web_ui); |
| 40 | |
| 41 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {} | |
| 42 | |
| 43 void ResetProfileSettingsHandler::InitializeHandler() { | |
| 44 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 45 resetter_.reset(new ProfileResetter(profile)); | 39 resetter_.reset(new ProfileResetter(profile)); |
| 46 automatic_profile_resetter_ = | 40 automatic_profile_resetter_ = |
| 47 AutomaticProfileResetterFactory::GetForBrowserContext(profile); | 41 AutomaticProfileResetterFactory::GetForBrowserContext(profile); |
| 48 } | 42 } |
| 49 | 43 |
| 50 void ResetProfileSettingsHandler::InitializePage() { | 44 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() { |
| 51 web_ui()->CallJavascriptFunction( | |
| 52 "ResetProfileSettingsOverlay.setResettingState", | |
| 53 base::FundamentalValue(resetter_->IsActive())); | |
| 54 if (automatic_profile_resetter_ && | |
| 55 automatic_profile_resetter_->ShouldShowResetBanner()) { | |
| 56 web_ui()->CallJavascriptFunction("ResetProfileSettingsBanner.show"); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 void ResetProfileSettingsHandler::Uninitialize() { | |
| 61 if (has_shown_confirmation_dialog_ && automatic_profile_resetter_) { | 45 if (has_shown_confirmation_dialog_ && automatic_profile_resetter_) { |
| 62 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( | 46 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( |
| 63 false /*performed_reset*/); | 47 false /*performed_reset*/); |
| 64 } | 48 } |
| 65 } | 49 } |
| 66 | 50 |
| 67 void ResetProfileSettingsHandler::GetLocalizedValues( | |
| 68 base::DictionaryValue* localized_strings) { | |
| 69 DCHECK(localized_strings); | |
| 70 | |
| 71 static OptionsStringResource resources[] = { | |
| 72 { "resetProfileSettingsBannerText", | |
| 73 IDS_RESET_PROFILE_SETTINGS_BANNER_TEXT }, | |
| 74 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON }, | |
| 75 { "resetProfileSettingsExplanation", | |
| 76 IDS_RESET_PROFILE_SETTINGS_EXPLANATION }, | |
| 77 { "resetProfileSettingsFeedback", IDS_RESET_PROFILE_SETTINGS_FEEDBACK } | |
| 78 }; | |
| 79 | |
| 80 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
| 81 RegisterTitle(localized_strings, "resetProfileSettingsOverlay", | |
| 82 IDS_RESET_PROFILE_SETTINGS_TITLE); | |
| 83 localized_strings->SetString( | |
| 84 "resetProfileSettingsLearnMoreUrl", | |
| 85 chrome::kResetProfileSettingsLearnMoreURL); | |
| 86 | |
| 87 // Set up the localized strings for the triggered profile reset overlay. | |
| 88 // The reset tool name can currently only have a custom value on Windows. | |
| 89 base::string16 reset_tool_name; | |
| 90 #if defined(OS_WIN) | |
| 91 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 92 TriggeredProfileResetter* triggered_profile_resetter = | |
| 93 TriggeredProfileResetterFactory::GetForBrowserContext(profile); | |
| 94 // TriggeredProfileResetter instance will be nullptr for incognito profiles. | |
| 95 if (triggered_profile_resetter) | |
| 96 reset_tool_name = triggered_profile_resetter->GetResetToolName(); | |
| 97 #endif | |
| 98 | |
| 99 if (reset_tool_name.empty()) { | |
| 100 reset_tool_name = l10n_util::GetStringUTF16( | |
| 101 IDS_TRIGGERED_RESET_PROFILE_SETTINGS_DEFAULT_TOOL_NAME); | |
| 102 } | |
| 103 localized_strings->SetString( | |
| 104 "triggeredResetProfileSettingsOverlay", | |
| 105 l10n_util::GetStringFUTF16(IDS_TRIGGERED_RESET_PROFILE_SETTINGS_TITLE, | |
| 106 reset_tool_name)); | |
| 107 // Set the title manually since RegisterTitle() wants an id. | |
| 108 base::string16 title_string(l10n_util::GetStringFUTF16( | |
| 109 IDS_TRIGGERED_RESET_PROFILE_SETTINGS_TITLE, reset_tool_name)); | |
| 110 localized_strings->SetString("triggeredResetProfileSettingsOverlay", | |
| 111 title_string); | |
| 112 localized_strings->SetString( | |
| 113 "triggeredResetProfileSettingsOverlayTabTitle", | |
| 114 l10n_util::GetStringFUTF16(IDS_OPTIONS_TAB_TITLE, | |
| 115 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE), | |
| 116 title_string)); | |
| 117 localized_strings->SetString( | |
| 118 "triggeredResetProfileSettingsExplanation", | |
| 119 l10n_util::GetStringFUTF16( | |
| 120 IDS_TRIGGERED_RESET_PROFILE_SETTINGS_EXPLANATION, reset_tool_name)); | |
| 121 } | |
| 122 | |
| 123 void ResetProfileSettingsHandler::RegisterMessages() { | 51 void ResetProfileSettingsHandler::RegisterMessages() { |
| 124 // Setup handlers specific to this panel. | |
| 125 web_ui()->RegisterMessageCallback("performResetProfileSettings", | 52 web_ui()->RegisterMessageCallback("performResetProfileSettings", |
| 126 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, | 53 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, |
| 127 base::Unretained(this))); | 54 base::Unretained(this))); |
| 128 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", | 55 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", |
| 129 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, | 56 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, |
| 130 base::Unretained(this))); | 57 base::Unretained(this))); |
| 131 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", | 58 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", |
| 132 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, | 59 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, |
| 133 base::Unretained(this))); | 60 base::Unretained(this))); |
| 134 web_ui()->RegisterMessageCallback("onDismissedResetProfileSettingsBanner", | |
| 135 base::Bind(&ResetProfileSettingsHandler:: | |
| 136 OnDismissedResetProfileSettingsBanner, | |
| 137 base::Unretained(this))); | |
| 138 } | 61 } |
| 139 | 62 |
| 140 void ResetProfileSettingsHandler::HandleResetProfileSettings( | 63 void ResetProfileSettingsHandler::HandleResetProfileSettings( |
| 141 const base::ListValue* value) { | 64 const base::ListValue* value) { |
| 142 bool send_settings = false; | 65 bool send_settings = false; |
| 143 if (!value->GetBoolean(0, &send_settings)) | 66 bool success = value->GetBoolean(0, &send_settings); |
| 144 NOTREACHED(); | 67 DCHECK(success); |
| 145 | 68 |
| 146 DCHECK(brandcode_.empty() || config_fetcher_); | 69 DCHECK(brandcode_.empty() || config_fetcher_); |
| 147 if (config_fetcher_ && config_fetcher_->IsActive()) { | 70 if (config_fetcher_ && config_fetcher_->IsActive()) { |
| 148 // Reset once the prefs are fetched. | 71 // Reset once the prefs are fetched. |
| 149 config_fetcher_->SetCallback( | 72 config_fetcher_->SetCallback( |
| 150 base::Bind(&ResetProfileSettingsHandler::ResetProfile, | 73 base::Bind(&ResetProfileSettingsHandler::ResetProfile, |
| 151 Unretained(this), | 74 Unretained(this), |
| 152 send_settings)); | 75 send_settings)); |
| 153 } else { | 76 } else { |
| 154 ResetProfile(send_settings); | 77 ResetProfile(send_settings); |
| 155 } | 78 } |
| 156 } | 79 } |
| 157 | 80 |
| 158 void ResetProfileSettingsHandler::OnResetProfileSettingsDone( | 81 void ResetProfileSettingsHandler::OnResetProfileSettingsDone( |
| 159 bool send_feedback) { | 82 bool send_feedback) { |
| 160 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); | 83 web_ui()->CallJavascriptFunction("SettingsResetPage.doneResetting"); |
| 161 if (send_feedback && setting_snapshot_) { | 84 if (send_feedback && setting_snapshot_) { |
| 162 Profile* profile = Profile::FromWebUI(web_ui()); | 85 Profile* profile = Profile::FromWebUI(web_ui()); |
| 163 ResettableSettingsSnapshot current_snapshot(profile); | 86 ResettableSettingsSnapshot current_snapshot(profile); |
| 164 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); | 87 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); |
| 165 if (difference) { | 88 if (difference) { |
| 166 setting_snapshot_->Subtract(current_snapshot); | 89 setting_snapshot_->Subtract(current_snapshot); |
| 167 std::string report = SerializeSettingsReport(*setting_snapshot_, | 90 std::string report = SerializeSettingsReport(*setting_snapshot_, |
| 168 difference); | 91 difference); |
| 169 bool is_reset_prompt_active = automatic_profile_resetter_ && | 92 bool is_reset_prompt_active = automatic_profile_resetter_ && |
| 170 automatic_profile_resetter_->IsResetPromptFlowActive(); | 93 automatic_profile_resetter_->IsResetPromptFlowActive(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 201 GURL("https://tools.google.com/service/update2"), | 124 GURL("https://tools.google.com/service/update2"), |
| 202 brandcode_)); | 125 brandcode_)); |
| 203 } | 126 } |
| 204 | 127 |
| 205 void ResetProfileSettingsHandler::OnHideResetProfileDialog( | 128 void ResetProfileSettingsHandler::OnHideResetProfileDialog( |
| 206 const base::ListValue* value) { | 129 const base::ListValue* value) { |
| 207 if (!resetter_->IsActive()) | 130 if (!resetter_->IsActive()) |
| 208 setting_snapshot_.reset(); | 131 setting_snapshot_.reset(); |
| 209 } | 132 } |
| 210 | 133 |
| 211 void ResetProfileSettingsHandler::OnDismissedResetProfileSettingsBanner( | |
| 212 const base::ListValue* args) { | |
| 213 if (automatic_profile_resetter_) | |
| 214 automatic_profile_resetter_->NotifyDidCloseWebUIResetBanner(); | |
| 215 } | |
| 216 | |
| 217 void ResetProfileSettingsHandler::OnSettingsFetched() { | 134 void ResetProfileSettingsHandler::OnSettingsFetched() { |
| 218 DCHECK(config_fetcher_); | 135 DCHECK(config_fetcher_); |
| 219 DCHECK(!config_fetcher_->IsActive()); | 136 DCHECK(!config_fetcher_->IsActive()); |
| 220 // The master prefs is fetched. We are waiting for user pressing 'Reset'. | 137 // The master prefs is fetched. We are waiting for user pressing 'Reset'. |
| 221 } | 138 } |
| 222 | 139 |
| 223 void ResetProfileSettingsHandler::ResetProfile(bool send_settings) { | 140 void ResetProfileSettingsHandler::ResetProfile(bool send_settings) { |
| 224 DCHECK(resetter_); | 141 DCHECK(resetter_); |
| 225 DCHECK(!resetter_->IsActive()); | 142 DCHECK(!resetter_->IsActive()); |
| 226 | 143 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 250 | 167 |
| 251 void ResetProfileSettingsHandler::UpdateFeedbackUI() { | 168 void ResetProfileSettingsHandler::UpdateFeedbackUI() { |
| 252 if (!setting_snapshot_) | 169 if (!setting_snapshot_) |
| 253 return; | 170 return; |
| 254 scoped_ptr<base::ListValue> list = GetReadableFeedbackForSnapshot( | 171 scoped_ptr<base::ListValue> list = GetReadableFeedbackForSnapshot( |
| 255 Profile::FromWebUI(web_ui()), | 172 Profile::FromWebUI(web_ui()), |
| 256 *setting_snapshot_); | 173 *setting_snapshot_); |
| 257 base::DictionaryValue feedback_info; | 174 base::DictionaryValue feedback_info; |
| 258 feedback_info.Set("feedbackInfo", list.release()); | 175 feedback_info.Set("feedbackInfo", list.release()); |
| 259 web_ui()->CallJavascriptFunction( | 176 web_ui()->CallJavascriptFunction( |
| 260 "ResetProfileSettingsOverlay.setFeedbackInfo", | 177 "SettingsResetPage.setFeedbackInfo", feedback_info); |
| 261 feedback_info); | |
| 262 } | 178 } |
| 263 | 179 |
| 264 } // namespace options | 180 } // namespace settings |
| OLD | NEW |