| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 100 |
| 101 model->ReportUmaMetrics(); | 101 model->ReportUmaMetrics(); |
| 102 | 102 |
| 103 if (!model->ShouldPromptForReset()) | 103 if (!model->ShouldPromptForReset()) |
| 104 return; | 104 return; |
| 105 | 105 |
| 106 DefaultSettingsFetcher::FetchDefaultSettings( | 106 DefaultSettingsFetcher::FetchDefaultSettings( |
| 107 base::Bind(&TryToShowSettingsResetPrompt, base::Passed(&model))); | 107 base::Bind(&TryToShowSettingsResetPrompt, base::Passed(&model))); |
| 108 } | 108 } |
| 109 | 109 |
| 110 class SettingsResetPromptDelegateImpl : public SettingsResetPromptDelegate { |
| 111 public: |
| 112 SettingsResetPromptDelegateImpl(); |
| 113 ~SettingsResetPromptDelegateImpl() override; |
| 114 |
| 115 void ShowSettingsResetPromptWithDelay() const override; |
| 116 |
| 117 private: |
| 118 DISALLOW_COPY_AND_ASSIGN(SettingsResetPromptDelegateImpl); |
| 119 }; |
| 120 |
| 121 SettingsResetPromptDelegateImpl::SettingsResetPromptDelegateImpl() = default; |
| 122 |
| 123 SettingsResetPromptDelegateImpl::~SettingsResetPromptDelegateImpl() = default; |
| 124 |
| 125 void SettingsResetPromptDelegateImpl::ShowSettingsResetPromptWithDelay() const { |
| 126 std::unique_ptr<SettingsResetPromptConfig> config = |
| 127 SettingsResetPromptConfig::Create(); |
| 128 if (!config) |
| 129 return; |
| 130 |
| 131 base::TimeDelta delay = config->delay_before_prompt(); |
| 132 content::BrowserThread::PostDelayedTask( |
| 133 content::BrowserThread::UI, FROM_HERE, |
| 134 base::BindOnce(MaybeShowSettingsResetPrompt, base::Passed(&config)), |
| 135 delay); |
| 136 } |
| 137 |
| 138 SettingsResetPromptDelegate* g_settings_reset_prompt_delegate = nullptr; |
| 139 |
| 110 } // namespace. | 140 } // namespace. |
| 111 | 141 |
| 112 SettingsResetPromptController::SettingsResetPromptController( | 142 SettingsResetPromptController::SettingsResetPromptController( |
| 113 std::unique_ptr<SettingsResetPromptModel> model, | 143 std::unique_ptr<SettingsResetPromptModel> model, |
| 114 std::unique_ptr<BrandcodedDefaultSettings> default_settings) | 144 std::unique_ptr<BrandcodedDefaultSettings> default_settings) |
| 115 : model_(std::move(model)), default_settings_(std::move(default_settings)) { | 145 : model_(std::move(model)), default_settings_(std::move(default_settings)) { |
| 116 DCHECK(model_); | 146 DCHECK(model_); |
| 117 DCHECK(model_->ShouldPromptForReset()); | 147 DCHECK(model_->ShouldPromptForReset()); |
| 118 DCHECK(default_settings_); | 148 DCHECK(default_settings_); |
| 119 | 149 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 280 |
| 251 main_text_url_range_.set_start(offset); | 281 main_text_url_range_.set_start(offset); |
| 252 main_text_url_range_.set_end(offset + url_string.length()); | 282 main_text_url_range_.set_end(offset + url_string.length()); |
| 253 } | 283 } |
| 254 | 284 |
| 255 void SettingsResetPromptController::OnInteractionDone() { | 285 void SettingsResetPromptController::OnInteractionDone() { |
| 256 delete this; | 286 delete this; |
| 257 } | 287 } |
| 258 | 288 |
| 259 void MaybeShowSettingsResetPromptWithDelay() { | 289 void MaybeShowSettingsResetPromptWithDelay() { |
| 260 std::unique_ptr<SettingsResetPromptConfig> config = | 290 if (g_settings_reset_prompt_delegate) { |
| 261 SettingsResetPromptConfig::Create(); | 291 g_settings_reset_prompt_delegate->ShowSettingsResetPromptWithDelay(); |
| 262 if (!config) | 292 } else { |
| 263 return; | 293 SettingsResetPromptDelegateImpl().ShowSettingsResetPromptWithDelay(); |
| 294 } |
| 295 } |
| 264 | 296 |
| 265 base::TimeDelta delay = config->delay_before_prompt(); | 297 SettingsResetPromptDelegate::SettingsResetPromptDelegate() = default; |
| 266 content::BrowserThread::PostDelayedTask( | 298 |
| 267 content::BrowserThread::UI, FROM_HERE, | 299 SettingsResetPromptDelegate::~SettingsResetPromptDelegate() = default; |
| 268 base::BindOnce(MaybeShowSettingsResetPrompt, base::Passed(&config)), | 300 |
| 269 delay); | 301 void SetSettingsResetPromptDelegate(SettingsResetPromptDelegate* delegate) { |
| 302 g_settings_reset_prompt_delegate = delegate; |
| 270 } | 303 } |
| 271 | 304 |
| 272 } // namespace safe_browsing | 305 } // namespace safe_browsing |
| OLD | NEW |