| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_controller.h" | 5 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/user_metrics.h" | 15 #include "base/metrics/user_metrics.h" |
| 15 #include "base/metrics/user_metrics_action.h" | 16 #include "base/metrics/user_metrics_action.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" |
| 19 #include "chrome/browser/profile_resetter/profile_resetter.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/safe_browsing/settings_reset_prompt/default_settings_fe
tcher.h" |
| 18 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" | 22 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" |
| 19 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_model.h" | 23 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_model.h" |
| 20 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/grit/chromium_strings.h" | 27 #include "chrome/grit/chromium_strings.h" |
| 24 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 25 #include "components/url_formatter/elide_url.h" | 29 #include "components/url_formatter/elide_url.h" |
| 26 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 44 bool ResetStartupUrlsEnabled(const SettingsResetPromptModel& model) { | 48 bool ResetStartupUrlsEnabled(const SettingsResetPromptModel& model) { |
| 45 return model.startup_urls_reset_state() == | 49 return model.startup_urls_reset_state() == |
| 46 SettingsResetPromptModel::RESET_REQUIRED; | 50 SettingsResetPromptModel::RESET_REQUIRED; |
| 47 } | 51 } |
| 48 | 52 |
| 49 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) { | 53 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) { |
| 50 return model.homepage_reset_state() == | 54 return model.homepage_reset_state() == |
| 51 SettingsResetPromptModel::RESET_REQUIRED; | 55 SettingsResetPromptModel::RESET_REQUIRED; |
| 52 } | 56 } |
| 53 | 57 |
| 54 // Function that is passed the newly created |SettingsResetPromptModel| object | 58 void TryToShowSettingsResetPrompt( |
| 55 // as a result of a call to |MaybeShowSettingsResetPrompt()| below. Will display | 59 std::unique_ptr<SettingsResetPromptModel> model, |
| 56 // the settings reset prompt if required by the model and there is at least one | 60 std::unique_ptr<BrandcodedDefaultSettings> default_settings) { |
| 57 // non-incognito browser available for the corresponding profile. | 61 DCHECK(model); |
| 58 void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) { | 62 DCHECK(default_settings); |
| 59 if (!model) | |
| 60 return; | |
| 61 | |
| 62 model->ReportUmaMetrics(); | |
| 63 | |
| 64 if (!model->ShouldPromptForReset()) | |
| 65 return; | |
| 66 | |
| 67 Profile* profile = model->profile(); | |
| 68 | 63 |
| 69 // Ensure that there is at least one non-incognito browser open for the | 64 // Ensure that there is at least one non-incognito browser open for the |
| 70 // profile before attempting to show the dialog. | 65 // profile before attempting to show the dialog. |
| 71 Browser* browser = | 66 Browser* browser = chrome::FindTabbedBrowser( |
| 72 chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false); | 67 model->profile(), /*match_original_profiles=*/false); |
| 73 if (!browser) | 68 if (!browser) |
| 74 return; | 69 return; |
| 75 | 70 |
| 76 // First, show the browser window, and only then show the dialog so that the | 71 // First, show the browser window, and only then show the dialog so that the |
| 77 // dialog will have focus. | 72 // dialog will have focus. |
| 78 if (browser->window()->IsMinimized()) | 73 if (browser->window()->IsMinimized()) |
| 79 browser->window()->Restore(); | 74 browser->window()->Restore(); |
| 80 browser->window()->Show(); | 75 browser->window()->Show(); |
| 81 | 76 |
| 82 // The |SettingsResetPromptController| object will delete itself after the | 77 // The |SettingsResetPromptController| object will delete itself after the |
| 83 // reset prompt dialog has been closed. | 78 // reset prompt dialog has been closed. |
| 84 SettingsResetPromptController::ShowSettingsResetPrompt( | 79 SettingsResetPromptController::ShowSettingsResetPrompt( |
| 85 browser, new SettingsResetPromptController(std::move(model))); | 80 browser, new SettingsResetPromptController(std::move(model), |
| 81 std::move(default_settings))); |
| 86 } | 82 } |
| 87 | 83 |
| 84 // Will display the settings reset prompt if required and if there is at least |
| 85 // one non-incognito browser available for the corresponding profile. |
| 88 void MaybeShowSettingsResetPrompt( | 86 void MaybeShowSettingsResetPrompt( |
| 89 std::unique_ptr<SettingsResetPromptConfig> config) { | 87 std::unique_ptr<SettingsResetPromptConfig> config) { |
| 90 DCHECK(config); | 88 DCHECK(config); |
| 91 | 89 |
| 92 Browser* browser = chrome::FindLastActive(); | 90 Browser* browser = chrome::FindLastActive(); |
| 93 if (!browser) | 91 if (!browser) |
| 94 return; | 92 return; |
| 95 | 93 |
| 96 // Get the original profile in case the last active browser was incognito. We | 94 // Get the original profile in case the last active browser was incognito. We |
| 97 // ensure that there is at least one non-incognito browser open before | 95 // ensure that there is at least one non-incognito browser open before |
| 98 // displaying the dialog. | 96 // displaying the dialog. |
| 99 Profile* profile = browser->profile()->GetOriginalProfile(); | 97 Profile* profile = browser->profile()->GetOriginalProfile(); |
| 100 SettingsResetPromptModel::Create(profile, std::move(config), | 98 |
| 101 base::Bind(OnModelCreated)); | 99 auto model = base::MakeUnique<SettingsResetPromptModel>( |
| 100 profile, std::move(config), base::MakeUnique<ProfileResetter>(profile)); |
| 101 |
| 102 model->ReportUmaMetrics(); |
| 103 |
| 104 if (!model->ShouldPromptForReset()) |
| 105 return; |
| 106 |
| 107 DefaultSettingsFetcher::FetchDefaultSettings( |
| 108 base::Bind(&TryToShowSettingsResetPrompt, base::Passed(&model))); |
| 102 } | 109 } |
| 103 | 110 |
| 104 } // namespace. | 111 } // namespace. |
| 105 | 112 |
| 106 SettingsResetPromptController::SettingsResetPromptController( | 113 SettingsResetPromptController::SettingsResetPromptController( |
| 107 std::unique_ptr<SettingsResetPromptModel> model) | 114 std::unique_ptr<SettingsResetPromptModel> model, |
| 108 : model_(std::move(model)) { | 115 std::unique_ptr<BrandcodedDefaultSettings> default_settings) |
| 116 : model_(std::move(model)), default_settings_(std::move(default_settings)) { |
| 109 DCHECK(model_); | 117 DCHECK(model_); |
| 110 DCHECK(model_->ShouldPromptForReset()); | 118 DCHECK(model_->ShouldPromptForReset()); |
| 119 DCHECK(default_settings_); |
| 120 |
| 111 // In the current implementation of the reset dialog, we ask users to reset | 121 // In the current implementation of the reset dialog, we ask users to reset |
| 112 // one settings type. If more than one setting requires reset, the model will | 122 // one settings type. If more than one setting requires reset, the model will |
| 113 // choose which setting we should prompt the user for. | 123 // choose which setting we should prompt the user for. |
| 114 DCHECK_EQ(1, int{ResetSearchEnabled(*model_)} + | 124 DCHECK_EQ(1, int{ResetSearchEnabled(*model_)} + |
| 115 int{ResetStartupUrlsEnabled(*model_)} + | 125 int{ResetStartupUrlsEnabled(*model_)} + |
| 116 int{ResetHomepageEnabled(*model_)}); | 126 int{ResetHomepageEnabled(*model_)}); |
| 117 | 127 |
| 118 InitMainText(); | 128 InitMainText(); |
| 119 } | 129 } |
| 120 | 130 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 162 |
| 153 void SettingsResetPromptController::DialogShown() { | 163 void SettingsResetPromptController::DialogShown() { |
| 154 model_->DialogShown(); | 164 model_->DialogShown(); |
| 155 time_dialog_shown_ = base::Time::Now(); | 165 time_dialog_shown_ = base::Time::Now(); |
| 156 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Shown")); | 166 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Shown")); |
| 157 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.DialogShown", true); | 167 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.DialogShown", true); |
| 158 } | 168 } |
| 159 | 169 |
| 160 void SettingsResetPromptController::Accept() { | 170 void SettingsResetPromptController::Accept() { |
| 161 DCHECK(!time_dialog_shown_.is_null()); | 171 DCHECK(!time_dialog_shown_.is_null()); |
| 172 DCHECK(default_settings_); |
| 173 |
| 162 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Accepted")); | 174 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Accepted")); |
| 163 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilAccepted", | 175 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilAccepted", |
| 164 base::Time::Now() - time_dialog_shown_); | 176 base::Time::Now() - time_dialog_shown_); |
| 165 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.PromptAccepted", true); | 177 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.PromptAccepted", true); |
| 166 model_->PerformReset( | 178 model_->PerformReset( |
| 179 std::move(default_settings_), |
| 167 base::Bind(&SettingsResetPromptController::OnInteractionDone, | 180 base::Bind(&SettingsResetPromptController::OnInteractionDone, |
| 168 base::Unretained(this))); | 181 base::Unretained(this))); |
| 169 } | 182 } |
| 170 | 183 |
| 171 void SettingsResetPromptController::Cancel() { | 184 void SettingsResetPromptController::Cancel() { |
| 172 DCHECK(!time_dialog_shown_.is_null()); | 185 DCHECK(!time_dialog_shown_.is_null()); |
| 173 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Canceled")); | 186 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Canceled")); |
| 174 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilCanceled", | 187 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilCanceled", |
| 175 base::Time::Now() - time_dialog_shown_); | 188 base::Time::Now() - time_dialog_shown_); |
| 176 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.PromptAccepted", false); | 189 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.PromptAccepted", false); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 return; | 264 return; |
| 252 | 265 |
| 253 base::TimeDelta delay = config->delay_before_prompt(); | 266 base::TimeDelta delay = config->delay_before_prompt(); |
| 254 content::BrowserThread::PostDelayedTask( | 267 content::BrowserThread::PostDelayedTask( |
| 255 content::BrowserThread::UI, FROM_HERE, | 268 content::BrowserThread::UI, FROM_HERE, |
| 256 base::BindOnce(MaybeShowSettingsResetPrompt, base::Passed(&config)), | 269 base::BindOnce(MaybeShowSettingsResetPrompt, base::Passed(&config)), |
| 257 delay); | 270 delay); |
| 258 } | 271 } |
| 259 | 272 |
| 260 } // namespace safe_browsing | 273 } // namespace safe_browsing |
| OLD | NEW |