| Index: chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
|
| diff --git a/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc b/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
|
| index 5c8b4e40bbacb6cb50f1b3630f8674904d528b45..1689fd8bb00307a6f0322b98589e348e8565bc9b 100644
|
| --- a/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
|
| +++ b/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
|
| @@ -48,6 +48,44 @@ bool ResetHomepageEnabled(const SettingsResetPromptModel& model) {
|
| SettingsResetPromptModel::RESET_REQUIRED;
|
| }
|
|
|
| +// Function that is passed the newly created |SettingsResetPromptModel| object
|
| +// as a result of a call to |MaybeShowSettingsResetPrompt()| below. Will display
|
| +// the settings reset prompt if required by the model and there is at least one
|
| +// non-incognito browser available for the corresponding profile.
|
| +void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) {
|
| + if (!model || !model->ShouldPromptForReset())
|
| + return;
|
| +
|
| + Profile* profile = model->profile();
|
| +
|
| + // Ensure that there is at least one non-incognito browser open for the
|
| + // profile before attempting to show the dialog.
|
| + if (!chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false))
|
| + return;
|
| +
|
| + chrome::ScopedTabbedBrowserDisplayer displayer(profile);
|
| + // The |SettingsResetPromptController| object will delete itself after the
|
| + // reset prompt dialog has been closed.
|
| + SettingsResetPromptController::ShowSettingsResetPrompt(
|
| + displayer.browser(), new SettingsResetPromptController(std::move(model)));
|
| +}
|
| +
|
| +void MaybeShowSettingsResetPrompt(
|
| + std::unique_ptr<SettingsResetPromptConfig> config) {
|
| + DCHECK(config);
|
| +
|
| + Browser* browser = chrome::FindLastActive();
|
| + if (!browser)
|
| + return;
|
| +
|
| + // Get the original profile in case the last active browser was incognito. We
|
| + // ensure that there is at least one non-incognito browser open before
|
| + // displaying the dialog.
|
| + Profile* profile = browser->profile()->GetOriginalProfile();
|
| + SettingsResetPromptModel::Create(profile, std::move(config),
|
| + base::Bind(OnModelCreated));
|
| +}
|
| +
|
| } // namespace.
|
|
|
| SettingsResetPromptController::SettingsResetPromptController(
|
| @@ -97,6 +135,10 @@ gfx::Range SettingsResetPromptController::GetMainTextUrlRange() const {
|
| return main_text_url_range_;
|
| }
|
|
|
| +void SettingsResetPromptController::DialogShown() {
|
| + model_->DialogShown();
|
| +}
|
| +
|
| void SettingsResetPromptController::Accept() {
|
| model_->PerformReset(
|
| base::Bind(&SettingsResetPromptController::OnInteractionDone,
|
| @@ -165,4 +207,17 @@ void SettingsResetPromptController::OnInteractionDone() {
|
| // TODO(alito): Add metrics reporting here.
|
| delete this;
|
| }
|
| +
|
| +void MaybeShowSettingsResetPromptWithDelay() {
|
| + std::unique_ptr<SettingsResetPromptConfig> config =
|
| + SettingsResetPromptConfig::Create();
|
| + if (!config)
|
| + return;
|
| +
|
| + base::TimeDelta delay = config->delay_before_prompt();
|
| + content::BrowserThread::PostDelayedTask(
|
| + content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(MaybeShowSettingsResetPrompt, base::Passed(&config)), delay);
|
| +}
|
| +
|
| } // namespace safe_browsing
|
|
|