| 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" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 bool ResetStartupUrlsEnabled(const SettingsResetPromptModel& model) { | 41 bool ResetStartupUrlsEnabled(const SettingsResetPromptModel& model) { |
| 42 return model.startup_urls_reset_state() == | 42 return model.startup_urls_reset_state() == |
| 43 SettingsResetPromptModel::RESET_REQUIRED; | 43 SettingsResetPromptModel::RESET_REQUIRED; |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) { | 46 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) { |
| 47 return model.homepage_reset_state() == | 47 return model.homepage_reset_state() == |
| 48 SettingsResetPromptModel::RESET_REQUIRED; | 48 SettingsResetPromptModel::RESET_REQUIRED; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Function that is passed the newly created |SettingsResetPromptModel| object |
| 52 // as a result of a call to |MaybeShowSettingsResetPrompt()| below. Will display |
| 53 // the settings reset prompt if required by the model and there is at least one |
| 54 // non-incognito browser available for the corresponding profile. |
| 55 void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) { |
| 56 if (!model || !model->ShouldPromptForReset()) |
| 57 return; |
| 58 |
| 59 Profile* profile = model->profile(); |
| 60 |
| 61 // Ensure that there is at least one non-incognito browser open for the |
| 62 // profile before attempting to show the dialog. |
| 63 if (!chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false)) |
| 64 return; |
| 65 |
| 66 chrome::ScopedTabbedBrowserDisplayer displayer(profile); |
| 67 // The |SettingsResetPromptController| object will delete itself after the |
| 68 // reset prompt dialog has been closed. |
| 69 SettingsResetPromptController::ShowSettingsResetPrompt( |
| 70 displayer.browser(), new SettingsResetPromptController(std::move(model))); |
| 71 } |
| 72 |
| 73 void MaybeShowSettingsResetPrompt( |
| 74 std::unique_ptr<SettingsResetPromptConfig> config) { |
| 75 DCHECK(config); |
| 76 |
| 77 Browser* browser = chrome::FindLastActive(); |
| 78 if (!browser) |
| 79 return; |
| 80 |
| 81 // Get the original profile in case the last active browser was incognito. We |
| 82 // ensure that there is at least one non-incognito browser open before |
| 83 // displaying the dialog. |
| 84 Profile* profile = browser->profile()->GetOriginalProfile(); |
| 85 SettingsResetPromptModel::Create(profile, std::move(config), |
| 86 base::Bind(OnModelCreated)); |
| 87 } |
| 88 |
| 51 } // namespace. | 89 } // namespace. |
| 52 | 90 |
| 53 SettingsResetPromptController::SettingsResetPromptController( | 91 SettingsResetPromptController::SettingsResetPromptController( |
| 54 std::unique_ptr<SettingsResetPromptModel> model) | 92 std::unique_ptr<SettingsResetPromptModel> model) |
| 55 : model_(std::move(model)) { | 93 : model_(std::move(model)) { |
| 56 DCHECK(model_); | 94 DCHECK(model_); |
| 57 DCHECK(model_->ShouldPromptForReset()); | 95 DCHECK(model_->ShouldPromptForReset()); |
| 58 // In the current implementation of the reset dialog, we ask users to reset | 96 // In the current implementation of the reset dialog, we ask users to reset |
| 59 // one settings type. If more than one setting requires reset, the model will | 97 // one settings type. If more than one setting requires reset, the model will |
| 60 // choose which setting we should prompt the user for. | 98 // choose which setting we should prompt the user for. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 90 | 128 |
| 91 base::string16 SettingsResetPromptController::GetMainText() const { | 129 base::string16 SettingsResetPromptController::GetMainText() const { |
| 92 DCHECK(!main_text_.empty()); | 130 DCHECK(!main_text_.empty()); |
| 93 return main_text_; | 131 return main_text_; |
| 94 } | 132 } |
| 95 | 133 |
| 96 gfx::Range SettingsResetPromptController::GetMainTextUrlRange() const { | 134 gfx::Range SettingsResetPromptController::GetMainTextUrlRange() const { |
| 97 return main_text_url_range_; | 135 return main_text_url_range_; |
| 98 } | 136 } |
| 99 | 137 |
| 138 void SettingsResetPromptController::DialogShown() { |
| 139 model_->DialogShown(); |
| 140 } |
| 141 |
| 100 void SettingsResetPromptController::Accept() { | 142 void SettingsResetPromptController::Accept() { |
| 101 model_->PerformReset( | 143 model_->PerformReset( |
| 102 base::Bind(&SettingsResetPromptController::OnInteractionDone, | 144 base::Bind(&SettingsResetPromptController::OnInteractionDone, |
| 103 base::Unretained(this))); | 145 base::Unretained(this))); |
| 104 } | 146 } |
| 105 | 147 |
| 106 void SettingsResetPromptController::Cancel() { | 148 void SettingsResetPromptController::Cancel() { |
| 107 OnInteractionDone(); | 149 OnInteractionDone(); |
| 108 } | 150 } |
| 109 | 151 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 200 } |
| 159 | 201 |
| 160 main_text_url_range_.set_start(offset); | 202 main_text_url_range_.set_start(offset); |
| 161 main_text_url_range_.set_end(offset + url_string.length()); | 203 main_text_url_range_.set_end(offset + url_string.length()); |
| 162 } | 204 } |
| 163 | 205 |
| 164 void SettingsResetPromptController::OnInteractionDone() { | 206 void SettingsResetPromptController::OnInteractionDone() { |
| 165 // TODO(alito): Add metrics reporting here. | 207 // TODO(alito): Add metrics reporting here. |
| 166 delete this; | 208 delete this; |
| 167 } | 209 } |
| 210 |
| 211 void MaybeShowSettingsResetPromptWithDelay() { |
| 212 std::unique_ptr<SettingsResetPromptConfig> config = |
| 213 SettingsResetPromptConfig::Create(); |
| 214 if (!config) |
| 215 return; |
| 216 |
| 217 base::TimeDelta delay = config->delay_before_prompt(); |
| 218 content::BrowserThread::PostDelayedTask( |
| 219 content::BrowserThread::UI, FROM_HERE, |
| 220 base::Bind(MaybeShowSettingsResetPrompt, base::Passed(&config)), delay); |
| 221 } |
| 222 |
| 168 } // namespace safe_browsing | 223 } // namespace safe_browsing |
| OLD | NEW |