| 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/metrics/histogram_macros.h" |
| 14 #include "base/metrics/user_metrics.h" |
| 15 #include "base/metrics/user_metrics_action.h" |
| 13 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" | 18 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" |
| 16 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_model.h" | 19 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_model.h" |
| 17 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 20 #include "chrome/grit/chromium_strings.h" | 23 #include "chrome/grit/chromium_strings.h" |
| 21 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 22 #include "components/url_formatter/elide_url.h" | 25 #include "components/url_formatter/elide_url.h" |
| 23 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 26 | 29 |
| 27 namespace safe_browsing { | 30 namespace safe_browsing { |
| 28 | 31 |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| 34 // These values are used for reporting UMA metrics. New enum values can be |
| 35 // added, but existing enums must never be renumbered or deleted and reused. |
| 36 enum DialogState { |
| 37 DIALOG_STATE_SHOWN = 1, |
| 38 DIALOG_STATE_ACCEPTED = 2, |
| 39 DIALOG_STATE_DECLINED = 3, |
| 40 DIALOG_STATE_MAX = 4, |
| 41 }; |
| 42 |
| 31 base::string16 FormatUrlForDisplay(const GURL& url) { | 43 base::string16 FormatUrlForDisplay(const GURL& url) { |
| 32 return url_formatter::FormatUrlForSecurityDisplay( | 44 return url_formatter::FormatUrlForSecurityDisplay( |
| 33 url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS); | 45 url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS); |
| 34 } | 46 } |
| 35 | 47 |
| 36 bool ResetSearchEnabled(const SettingsResetPromptModel& model) { | 48 bool ResetSearchEnabled(const SettingsResetPromptModel& model) { |
| 37 return model.default_search_reset_state() == | 49 return model.default_search_reset_state() == |
| 38 SettingsResetPromptModel::RESET_REQUIRED; | 50 SettingsResetPromptModel::RESET_REQUIRED; |
| 39 } | 51 } |
| 40 | 52 |
| 41 bool ResetStartupUrlsEnabled(const SettingsResetPromptModel& model) { | 53 bool ResetStartupUrlsEnabled(const SettingsResetPromptModel& model) { |
| 42 return model.startup_urls_reset_state() == | 54 return model.startup_urls_reset_state() == |
| 43 SettingsResetPromptModel::RESET_REQUIRED; | 55 SettingsResetPromptModel::RESET_REQUIRED; |
| 44 } | 56 } |
| 45 | 57 |
| 46 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) { | 58 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) { |
| 47 return model.homepage_reset_state() == | 59 return model.homepage_reset_state() == |
| 48 SettingsResetPromptModel::RESET_REQUIRED; | 60 SettingsResetPromptModel::RESET_REQUIRED; |
| 49 } | 61 } |
| 50 | 62 |
| 51 // Function that is passed the newly created |SettingsResetPromptModel| object | 63 // Function that is passed the newly created |SettingsResetPromptModel| object |
| 52 // as a result of a call to |MaybeShowSettingsResetPrompt()| below. Will display | 64 // 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 | 65 // the settings reset prompt if required by the model and there is at least one |
| 54 // non-incognito browser available for the corresponding profile. | 66 // non-incognito browser available for the corresponding profile. |
| 55 void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) { | 67 void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) { |
| 56 if (!model || !model->ShouldPromptForReset()) | 68 if (!model) |
| 69 return; |
| 70 |
| 71 model->ReportUmaMetrics(); |
| 72 |
| 73 if (!model->ShouldPromptForReset()) |
| 57 return; | 74 return; |
| 58 | 75 |
| 59 Profile* profile = model->profile(); | 76 Profile* profile = model->profile(); |
| 60 | 77 |
| 61 // Ensure that there is at least one non-incognito browser open for the | 78 // Ensure that there is at least one non-incognito browser open for the |
| 62 // profile before attempting to show the dialog. | 79 // profile before attempting to show the dialog. |
| 63 if (!chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false)) | 80 if (!chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false)) |
| 64 return; | 81 return; |
| 65 | 82 |
| 66 chrome::ScopedTabbedBrowserDisplayer displayer(profile); | 83 chrome::ScopedTabbedBrowserDisplayer displayer(profile); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 DCHECK(!main_text_.empty()); | 147 DCHECK(!main_text_.empty()); |
| 131 return main_text_; | 148 return main_text_; |
| 132 } | 149 } |
| 133 | 150 |
| 134 gfx::Range SettingsResetPromptController::GetMainTextUrlRange() const { | 151 gfx::Range SettingsResetPromptController::GetMainTextUrlRange() const { |
| 135 return main_text_url_range_; | 152 return main_text_url_range_; |
| 136 } | 153 } |
| 137 | 154 |
| 138 void SettingsResetPromptController::DialogShown() { | 155 void SettingsResetPromptController::DialogShown() { |
| 139 model_->DialogShown(); | 156 model_->DialogShown(); |
| 157 time_dialog_shown_ = base::Time::Now(); |
| 158 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Shown")); |
| 159 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.DialogState", |
| 160 DIALOG_STATE_SHOWN, DIALOG_STATE_MAX); |
| 140 } | 161 } |
| 141 | 162 |
| 142 void SettingsResetPromptController::Accept() { | 163 void SettingsResetPromptController::Accept() { |
| 164 DCHECK(!time_dialog_shown_.is_null()); |
| 165 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Accepted")); |
| 166 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilAccepted", |
| 167 base::Time::Now() - time_dialog_shown_); |
| 168 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.DialogState", |
| 169 DIALOG_STATE_ACCEPTED, DIALOG_STATE_MAX); |
| 143 model_->PerformReset( | 170 model_->PerformReset( |
| 144 base::Bind(&SettingsResetPromptController::OnInteractionDone, | 171 base::Bind(&SettingsResetPromptController::OnInteractionDone, |
| 145 base::Unretained(this))); | 172 base::Unretained(this))); |
| 146 } | 173 } |
| 147 | 174 |
| 148 void SettingsResetPromptController::Cancel() { | 175 void SettingsResetPromptController::Cancel() { |
| 176 DCHECK(!time_dialog_shown_.is_null()); |
| 177 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Declined")); |
| 178 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilDeclined", |
| 179 base::Time::Now() - time_dialog_shown_); |
| 180 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.DialogState", |
| 181 DIALOG_STATE_DECLINED, DIALOG_STATE_MAX); |
| 149 OnInteractionDone(); | 182 OnInteractionDone(); |
| 150 } | 183 } |
| 151 | 184 |
| 152 void SettingsResetPromptController::InitMainText() { | 185 void SettingsResetPromptController::InitMainText() { |
| 153 DCHECK(main_text_.empty()); | 186 DCHECK(main_text_.empty()); |
| 154 | 187 |
| 155 // Get the URL string to be displayed in the dialog message. | 188 // Get the URL string to be displayed in the dialog message. |
| 156 base::string16 url_string; | 189 base::string16 url_string; |
| 157 if (ResetSearchEnabled(*model_)) { | 190 if (ResetSearchEnabled(*model_)) { |
| 158 url_string = FormatUrlForDisplay(model_->default_search()); | 191 url_string = FormatUrlForDisplay(model_->default_search()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 url_string, &offset); | 230 url_string, &offset); |
| 198 } else { | 231 } else { |
| 199 NOTREACHED(); | 232 NOTREACHED(); |
| 200 } | 233 } |
| 201 | 234 |
| 202 main_text_url_range_.set_start(offset); | 235 main_text_url_range_.set_start(offset); |
| 203 main_text_url_range_.set_end(offset + url_string.length()); | 236 main_text_url_range_.set_end(offset + url_string.length()); |
| 204 } | 237 } |
| 205 | 238 |
| 206 void SettingsResetPromptController::OnInteractionDone() { | 239 void SettingsResetPromptController::OnInteractionDone() { |
| 207 // TODO(alito): Add metrics reporting here. | |
| 208 delete this; | 240 delete this; |
| 209 } | 241 } |
| 210 | 242 |
| 211 void MaybeShowSettingsResetPromptWithDelay() { | 243 void MaybeShowSettingsResetPromptWithDelay() { |
| 212 std::unique_ptr<SettingsResetPromptConfig> config = | 244 std::unique_ptr<SettingsResetPromptConfig> config = |
| 213 SettingsResetPromptConfig::Create(); | 245 SettingsResetPromptConfig::Create(); |
| 214 if (!config) | 246 if (!config) |
| 215 return; | 247 return; |
| 216 | 248 |
| 217 base::TimeDelta delay = config->delay_before_prompt(); | 249 base::TimeDelta delay = config->delay_before_prompt(); |
| 218 content::BrowserThread::PostDelayedTask( | 250 content::BrowserThread::PostDelayedTask( |
| 219 content::BrowserThread::UI, FROM_HERE, | 251 content::BrowserThread::UI, FROM_HERE, |
| 220 base::Bind(MaybeShowSettingsResetPrompt, base::Passed(&config)), delay); | 252 base::Bind(MaybeShowSettingsResetPrompt, base::Passed(&config)), delay); |
| 221 } | 253 } |
| 222 | 254 |
| 223 } // namespace safe_browsing | 255 } // namespace safe_browsing |
| OLD | NEW |