Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc

Issue 2739513002: Settings reset prompt: add UMA metrics reporting. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 enum DialogState {
robertshield 2017/03/07 07:43:19 Add a comment mentioning this is used for UMA repo
alito 2017/03/07 16:23:29 Done.
35 DIALOG_STATE_SHOWN = 1,
36 DIALOG_STATE_ACCEPTED = 2,
37 DIALOG_STATE_DECLINED = 3,
38 DIALOG_STATE_MAX = 4,
39 };
40
31 base::string16 FormatUrlForDisplay(const GURL& url) { 41 base::string16 FormatUrlForDisplay(const GURL& url) {
32 return url_formatter::FormatUrlForSecurityDisplay( 42 return url_formatter::FormatUrlForSecurityDisplay(
33 url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS); 43 url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
34 } 44 }
35 45
36 bool ResetSearchEnabled(const SettingsResetPromptModel& model) { 46 bool ResetSearchEnabled(const SettingsResetPromptModel& model) {
37 return model.default_search_reset_state() == 47 return model.default_search_reset_state() ==
38 SettingsResetPromptModel::RESET_REQUIRED; 48 SettingsResetPromptModel::RESET_REQUIRED;
39 } 49 }
40 50
41 bool ResetStartupUrlsEnabled(const SettingsResetPromptModel& model) { 51 bool ResetStartupUrlsEnabled(const SettingsResetPromptModel& model) {
42 return model.startup_urls_reset_state() == 52 return model.startup_urls_reset_state() ==
43 SettingsResetPromptModel::RESET_REQUIRED; 53 SettingsResetPromptModel::RESET_REQUIRED;
44 } 54 }
45 55
46 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) { 56 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) {
47 return model.homepage_reset_state() == 57 return model.homepage_reset_state() ==
48 SettingsResetPromptModel::RESET_REQUIRED; 58 SettingsResetPromptModel::RESET_REQUIRED;
49 } 59 }
50 60
51 // Function that is passed the newly created |SettingsResetPromptModel| object 61 // Function that is passed the newly created |SettingsResetPromptModel| object
52 // as a result of a call to |MaybeShowSettingsResetPrompt()| below. Will display 62 // 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 63 // the settings reset prompt if required by the model and there is at least one
54 // non-incognito browser available for the corresponding profile. 64 // non-incognito browser available for the corresponding profile.
55 void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) { 65 void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) {
66 if (model)
csharp 2017/03/07 14:39:40 nit: I wonder if this part would look a bit cleare
alito 2017/03/07 16:23:29 Done.
67 model->ReportUmaMetrics();
68
56 if (!model || !model->ShouldPromptForReset()) 69 if (!model || !model->ShouldPromptForReset())
57 return; 70 return;
58 71
59 Profile* profile = model->profile(); 72 Profile* profile = model->profile();
60 73
61 // Ensure that there is at least one non-incognito browser open for the 74 // Ensure that there is at least one non-incognito browser open for the
62 // profile before attempting to show the dialog. 75 // profile before attempting to show the dialog.
63 if (!chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false)) 76 if (!chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false))
64 return; 77 return;
65 78
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 DCHECK(!main_text_.empty()); 143 DCHECK(!main_text_.empty());
131 return main_text_; 144 return main_text_;
132 } 145 }
133 146
134 gfx::Range SettingsResetPromptController::GetMainTextUrlRange() const { 147 gfx::Range SettingsResetPromptController::GetMainTextUrlRange() const {
135 return main_text_url_range_; 148 return main_text_url_range_;
136 } 149 }
137 150
138 void SettingsResetPromptController::DialogShown() { 151 void SettingsResetPromptController::DialogShown() {
139 model_->DialogShown(); 152 model_->DialogShown();
153 time_dialog_shown_ = base::Time::Now();
154 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Shown"));
155 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.DialogState",
156 DIALOG_STATE_SHOWN, DIALOG_STATE_MAX);
140 } 157 }
141 158
142 void SettingsResetPromptController::Accept() { 159 void SettingsResetPromptController::Accept() {
160 DCHECK(!time_dialog_shown_.is_null());
161 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Accepted"));
162 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilAccepted",
163 base::Time::Now() - time_dialog_shown_);
164 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.DialogState",
165 DIALOG_STATE_ACCEPTED, DIALOG_STATE_MAX);
143 model_->PerformReset( 166 model_->PerformReset(
144 base::Bind(&SettingsResetPromptController::OnInteractionDone, 167 base::Bind(&SettingsResetPromptController::OnInteractionDone,
145 base::Unretained(this))); 168 base::Unretained(this)));
146 } 169 }
147 170
148 void SettingsResetPromptController::Cancel() { 171 void SettingsResetPromptController::Cancel() {
172 DCHECK(!time_dialog_shown_.is_null());
173 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Declined"));
174 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilDeclined",
175 base::Time::Now() - time_dialog_shown_);
176 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.DialogState",
177 DIALOG_STATE_DECLINED, DIALOG_STATE_MAX);
149 OnInteractionDone(); 178 OnInteractionDone();
150 } 179 }
151 180
152 void SettingsResetPromptController::InitMainText() { 181 void SettingsResetPromptController::InitMainText() {
153 DCHECK(main_text_.empty()); 182 DCHECK(main_text_.empty());
154 183
155 // Get the URL string to be displayed in the dialog message. 184 // Get the URL string to be displayed in the dialog message.
156 base::string16 url_string; 185 base::string16 url_string;
157 if (ResetSearchEnabled(*model_)) { 186 if (ResetSearchEnabled(*model_)) {
158 url_string = FormatUrlForDisplay(model_->default_search()); 187 url_string = FormatUrlForDisplay(model_->default_search());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 url_string, &offset); 226 url_string, &offset);
198 } else { 227 } else {
199 NOTREACHED(); 228 NOTREACHED();
200 } 229 }
201 230
202 main_text_url_range_.set_start(offset); 231 main_text_url_range_.set_start(offset);
203 main_text_url_range_.set_end(offset + url_string.length()); 232 main_text_url_range_.set_end(offset + url_string.length());
204 } 233 }
205 234
206 void SettingsResetPromptController::OnInteractionDone() { 235 void SettingsResetPromptController::OnInteractionDone() {
207 // TODO(alito): Add metrics reporting here.
208 delete this; 236 delete this;
209 } 237 }
210 238
211 void MaybeShowSettingsResetPromptWithDelay() { 239 void MaybeShowSettingsResetPromptWithDelay() {
212 std::unique_ptr<SettingsResetPromptConfig> config = 240 std::unique_ptr<SettingsResetPromptConfig> config =
213 SettingsResetPromptConfig::Create(); 241 SettingsResetPromptConfig::Create();
214 if (!config) 242 if (!config)
215 return; 243 return;
216 244
217 base::TimeDelta delay = config->delay_before_prompt(); 245 base::TimeDelta delay = config->delay_before_prompt();
218 content::BrowserThread::PostDelayedTask( 246 content::BrowserThread::PostDelayedTask(
219 content::BrowserThread::UI, FROM_HERE, 247 content::BrowserThread::UI, FROM_HERE,
220 base::Bind(MaybeShowSettingsResetPrompt, base::Passed(&config)), delay); 248 base::Bind(MaybeShowSettingsResetPrompt, base::Passed(&config)), delay);
221 } 249 }
222 250
223 } // namespace safe_browsing 251 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698