| 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/options/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" | |
| 15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h" | |
| 16 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" | 14 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" |
| 17 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" | 15 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" |
| 18 #include "chrome/browser/profile_resetter/profile_resetter.h" | 16 #include "chrome/browser/profile_resetter/profile_resetter.h" |
| 19 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" | 17 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 23 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 24 #include "content/public/browser/web_ui.h" | 22 #include "content/public/browser/web_ui.h" |
| 25 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 27 | 25 |
| 28 namespace options { | 26 namespace options { |
| 29 | 27 |
| 30 ResetProfileSettingsHandler::ResetProfileSettingsHandler() | 28 ResetProfileSettingsHandler::ResetProfileSettingsHandler() { |
| 31 : automatic_profile_resetter_(NULL), has_shown_confirmation_dialog_(false) { | |
| 32 google_brand::GetBrand(&brandcode_); | 29 google_brand::GetBrand(&brandcode_); |
| 33 } | 30 } |
| 34 | 31 |
| 35 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {} | 32 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {} |
| 36 | 33 |
| 37 void ResetProfileSettingsHandler::InitializeHandler() { | 34 void ResetProfileSettingsHandler::InitializeHandler() { |
| 38 Profile* profile = Profile::FromWebUI(web_ui()); | 35 Profile* profile = Profile::FromWebUI(web_ui()); |
| 39 resetter_.reset(new ProfileResetter(profile)); | 36 resetter_.reset(new ProfileResetter(profile)); |
| 40 automatic_profile_resetter_ = | |
| 41 AutomaticProfileResetterFactory::GetForBrowserContext(profile); | |
| 42 } | 37 } |
| 43 | 38 |
| 44 void ResetProfileSettingsHandler::InitializePage() { | 39 void ResetProfileSettingsHandler::InitializePage() { |
| 45 web_ui()->CallJavascriptFunction( | 40 web_ui()->CallJavascriptFunction( |
| 46 "ResetProfileSettingsOverlay.setResettingState", | 41 "ResetProfileSettingsOverlay.setResettingState", |
| 47 base::FundamentalValue(resetter_->IsActive())); | 42 base::FundamentalValue(resetter_->IsActive())); |
| 48 if (automatic_profile_resetter_ && | |
| 49 automatic_profile_resetter_->ShouldShowResetBanner()) | |
| 50 web_ui()->CallJavascriptFunction("ResetProfileSettingsBanner.show"); | |
| 51 } | |
| 52 | |
| 53 void ResetProfileSettingsHandler::Uninitialize() { | |
| 54 if (has_shown_confirmation_dialog_ && automatic_profile_resetter_) { | |
| 55 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( | |
| 56 false /*performed_reset*/); | |
| 57 } | |
| 58 } | 43 } |
| 59 | 44 |
| 60 void ResetProfileSettingsHandler::GetLocalizedValues( | 45 void ResetProfileSettingsHandler::GetLocalizedValues( |
| 61 base::DictionaryValue* localized_strings) { | 46 base::DictionaryValue* localized_strings) { |
| 62 DCHECK(localized_strings); | 47 DCHECK(localized_strings); |
| 63 | 48 |
| 64 static OptionsStringResource resources[] = { | 49 static OptionsStringResource resources[] = { |
| 65 { "resetProfileSettingsBannerText", | |
| 66 IDS_RESET_PROFILE_SETTINGS_BANNER_TEXT }, | |
| 67 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON }, | 50 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON }, |
| 68 { "resetProfileSettingsExplanation", | 51 { "resetProfileSettingsExplanation", |
| 69 IDS_RESET_PROFILE_SETTINGS_EXPLANATION }, | 52 IDS_RESET_PROFILE_SETTINGS_EXPLANATION }, |
| 70 { "resetProfileSettingsFeedback", IDS_RESET_PROFILE_SETTINGS_FEEDBACK } | 53 { "resetProfileSettingsFeedback", IDS_RESET_PROFILE_SETTINGS_FEEDBACK } |
| 71 }; | 54 }; |
| 72 | 55 |
| 73 RegisterStrings(localized_strings, resources, arraysize(resources)); | 56 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 74 RegisterTitle(localized_strings, "resetProfileSettingsOverlay", | 57 RegisterTitle(localized_strings, "resetProfileSettingsOverlay", |
| 75 IDS_RESET_PROFILE_SETTINGS_TITLE); | 58 IDS_RESET_PROFILE_SETTINGS_TITLE); |
| 76 localized_strings->SetString( | 59 localized_strings->SetString( |
| 77 "resetProfileSettingsLearnMoreUrl", | 60 "resetProfileSettingsLearnMoreUrl", |
| 78 chrome::kResetProfileSettingsLearnMoreURL); | 61 chrome::kResetProfileSettingsLearnMoreURL); |
| 79 } | 62 } |
| 80 | 63 |
| 81 void ResetProfileSettingsHandler::RegisterMessages() { | 64 void ResetProfileSettingsHandler::RegisterMessages() { |
| 82 // Setup handlers specific to this panel. | 65 // Setup handlers specific to this panel. |
| 83 web_ui()->RegisterMessageCallback("performResetProfileSettings", | 66 web_ui()->RegisterMessageCallback("performResetProfileSettings", |
| 84 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, | 67 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, |
| 85 base::Unretained(this))); | 68 base::Unretained(this))); |
| 86 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", | 69 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", |
| 87 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, | 70 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, |
| 88 base::Unretained(this))); | 71 base::Unretained(this))); |
| 89 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", | 72 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", |
| 90 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, | 73 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, |
| 91 base::Unretained(this))); | 74 base::Unretained(this))); |
| 92 web_ui()->RegisterMessageCallback("onDismissedResetProfileSettingsBanner", | |
| 93 base::Bind(&ResetProfileSettingsHandler:: | |
| 94 OnDismissedResetProfileSettingsBanner, | |
| 95 base::Unretained(this))); | |
| 96 } | 75 } |
| 97 | 76 |
| 98 void ResetProfileSettingsHandler::HandleResetProfileSettings( | 77 void ResetProfileSettingsHandler::HandleResetProfileSettings( |
| 99 const base::ListValue* value) { | 78 const base::ListValue* value) { |
| 100 bool send_settings = false; | 79 bool send_settings = false; |
| 101 if (!value->GetBoolean(0, &send_settings)) | 80 if (!value->GetBoolean(0, &send_settings)) |
| 102 NOTREACHED(); | 81 NOTREACHED(); |
| 103 | 82 |
| 104 DCHECK(brandcode_.empty() || config_fetcher_); | 83 DCHECK(brandcode_.empty() || config_fetcher_); |
| 105 if (config_fetcher_ && config_fetcher_->IsActive()) { | 84 if (config_fetcher_ && config_fetcher_->IsActive()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 117 bool send_feedback) { | 96 bool send_feedback) { |
| 118 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); | 97 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); |
| 119 if (send_feedback && setting_snapshot_) { | 98 if (send_feedback && setting_snapshot_) { |
| 120 Profile* profile = Profile::FromWebUI(web_ui()); | 99 Profile* profile = Profile::FromWebUI(web_ui()); |
| 121 ResettableSettingsSnapshot current_snapshot(profile); | 100 ResettableSettingsSnapshot current_snapshot(profile); |
| 122 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); | 101 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); |
| 123 if (difference) { | 102 if (difference) { |
| 124 setting_snapshot_->Subtract(current_snapshot); | 103 setting_snapshot_->Subtract(current_snapshot); |
| 125 std::string report = SerializeSettingsReport(*setting_snapshot_, | 104 std::string report = SerializeSettingsReport(*setting_snapshot_, |
| 126 difference); | 105 difference); |
| 127 bool is_reset_prompt_active = automatic_profile_resetter_ && | 106 SendSettingsFeedback(report, profile); |
| 128 automatic_profile_resetter_->IsResetPromptFlowActive(); | |
| 129 SendSettingsFeedback(report, profile, is_reset_prompt_active ? | |
| 130 PROFILE_RESET_PROMPT : PROFILE_RESET_WEBUI); | |
| 131 } | 107 } |
| 132 } | 108 } |
| 133 setting_snapshot_.reset(); | 109 setting_snapshot_.reset(); |
| 134 if (automatic_profile_resetter_) { | |
| 135 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( | |
| 136 true /*performed_reset*/); | |
| 137 } | |
| 138 } | 110 } |
| 139 | 111 |
| 140 void ResetProfileSettingsHandler::OnShowResetProfileDialog( | 112 void ResetProfileSettingsHandler::OnShowResetProfileDialog( |
| 141 const base::ListValue* value) { | 113 const base::ListValue* value) { |
| 142 if (!resetter_->IsActive()) { | 114 if (!resetter_->IsActive()) { |
| 143 setting_snapshot_.reset( | 115 setting_snapshot_.reset( |
| 144 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui()))); | 116 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui()))); |
| 145 setting_snapshot_->RequestShortcuts(base::Bind( | 117 setting_snapshot_->RequestShortcuts(base::Bind( |
| 146 &ResetProfileSettingsHandler::UpdateFeedbackUI, AsWeakPtr())); | 118 &ResetProfileSettingsHandler::UpdateFeedbackUI, AsWeakPtr())); |
| 147 UpdateFeedbackUI(); | 119 UpdateFeedbackUI(); |
| 148 } | 120 } |
| 149 | 121 |
| 150 if (automatic_profile_resetter_) | |
| 151 automatic_profile_resetter_->NotifyDidOpenWebUIResetDialog(); | |
| 152 has_shown_confirmation_dialog_ = true; | |
| 153 | |
| 154 if (brandcode_.empty()) | 122 if (brandcode_.empty()) |
| 155 return; | 123 return; |
| 156 config_fetcher_.reset(new BrandcodeConfigFetcher( | 124 config_fetcher_.reset(new BrandcodeConfigFetcher( |
| 157 base::Bind(&ResetProfileSettingsHandler::OnSettingsFetched, | 125 base::Bind(&ResetProfileSettingsHandler::OnSettingsFetched, |
| 158 Unretained(this)), | 126 Unretained(this)), |
| 159 GURL("https://tools.google.com/service/update2"), | 127 GURL("https://tools.google.com/service/update2"), |
| 160 brandcode_)); | 128 brandcode_)); |
| 161 } | 129 } |
| 162 | 130 |
| 163 void ResetProfileSettingsHandler::OnHideResetProfileDialog( | 131 void ResetProfileSettingsHandler::OnHideResetProfileDialog( |
| 164 const base::ListValue* value) { | 132 const base::ListValue* value) { |
| 165 if (!resetter_->IsActive()) | 133 if (!resetter_->IsActive()) |
| 166 setting_snapshot_.reset(); | 134 setting_snapshot_.reset(); |
| 167 } | 135 } |
| 168 | 136 |
| 169 void ResetProfileSettingsHandler::OnDismissedResetProfileSettingsBanner( | |
| 170 const base::ListValue* args) { | |
| 171 if (automatic_profile_resetter_) | |
| 172 automatic_profile_resetter_->NotifyDidCloseWebUIResetBanner(); | |
| 173 } | |
| 174 | |
| 175 void ResetProfileSettingsHandler::OnSettingsFetched() { | 137 void ResetProfileSettingsHandler::OnSettingsFetched() { |
| 176 DCHECK(config_fetcher_); | 138 DCHECK(config_fetcher_); |
| 177 DCHECK(!config_fetcher_->IsActive()); | 139 DCHECK(!config_fetcher_->IsActive()); |
| 178 // The master prefs is fetched. We are waiting for user pressing 'Reset'. | 140 // The master prefs is fetched. We are waiting for user pressing 'Reset'. |
| 179 } | 141 } |
| 180 | 142 |
| 181 void ResetProfileSettingsHandler::ResetProfile(bool send_settings) { | 143 void ResetProfileSettingsHandler::ResetProfile(bool send_settings) { |
| 182 DCHECK(resetter_); | 144 DCHECK(resetter_); |
| 183 DCHECK(!resetter_->IsActive()); | 145 DCHECK(!resetter_->IsActive()); |
| 184 | 146 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 213 Profile::FromWebUI(web_ui()), | 175 Profile::FromWebUI(web_ui()), |
| 214 *setting_snapshot_); | 176 *setting_snapshot_); |
| 215 base::DictionaryValue feedback_info; | 177 base::DictionaryValue feedback_info; |
| 216 feedback_info.Set("feedbackInfo", list.release()); | 178 feedback_info.Set("feedbackInfo", list.release()); |
| 217 web_ui()->CallJavascriptFunction( | 179 web_ui()->CallJavascriptFunction( |
| 218 "ResetProfileSettingsOverlay.setFeedbackInfo", | 180 "ResetProfileSettingsOverlay.setFeedbackInfo", |
| 219 feedback_info); | 181 feedback_info); |
| 220 } | 182 } |
| 221 | 183 |
| 222 } // namespace options | 184 } // namespace options |
| OLD | NEW |