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

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: Adds histograms to log what is reset when prompt is accepted 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"
(...skipping 23 matching lines...) Expand all
46 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) { 49 bool ResetHomepageEnabled(const SettingsResetPromptModel& model) {
47 return model.homepage_reset_state() == 50 return model.homepage_reset_state() ==
48 SettingsResetPromptModel::RESET_REQUIRED; 51 SettingsResetPromptModel::RESET_REQUIRED;
49 } 52 }
50 53
51 // Function that is passed the newly created |SettingsResetPromptModel| object 54 // Function that is passed the newly created |SettingsResetPromptModel| object
52 // as a result of a call to |MaybeShowSettingsResetPrompt()| below. Will display 55 // 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 56 // the settings reset prompt if required by the model and there is at least one
54 // non-incognito browser available for the corresponding profile. 57 // non-incognito browser available for the corresponding profile.
55 void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) { 58 void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) {
56 if (!model || !model->ShouldPromptForReset()) 59 if (!model)
60 return;
61
62 model->ReportUmaMetrics();
63
64 if (!model->ShouldPromptForReset())
57 return; 65 return;
58 66
59 Profile* profile = model->profile(); 67 Profile* profile = model->profile();
60 68
61 // Ensure that there is at least one non-incognito browser open for the 69 // Ensure that there is at least one non-incognito browser open for the
62 // profile before attempting to show the dialog. 70 // profile before attempting to show the dialog.
63 if (!chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false)) 71 if (!chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false))
64 return; 72 return;
65 73
66 chrome::ScopedTabbedBrowserDisplayer displayer(profile); 74 chrome::ScopedTabbedBrowserDisplayer displayer(profile);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 DCHECK(!main_text_.empty()); 138 DCHECK(!main_text_.empty());
131 return main_text_; 139 return main_text_;
132 } 140 }
133 141
134 gfx::Range SettingsResetPromptController::GetMainTextUrlRange() const { 142 gfx::Range SettingsResetPromptController::GetMainTextUrlRange() const {
135 return main_text_url_range_; 143 return main_text_url_range_;
136 } 144 }
137 145
138 void SettingsResetPromptController::DialogShown() { 146 void SettingsResetPromptController::DialogShown() {
139 model_->DialogShown(); 147 model_->DialogShown();
148 time_dialog_shown_ = base::Time::Now();
149 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Shown"));
150 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.DialogShown", true);
140 } 151 }
141 152
142 void SettingsResetPromptController::Accept() { 153 void SettingsResetPromptController::Accept() {
154 DCHECK(!time_dialog_shown_.is_null());
155 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Accepted"));
156 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilAccepted",
157 base::Time::Now() - time_dialog_shown_);
158 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.PromptAccepted", true);
143 model_->PerformReset( 159 model_->PerformReset(
144 base::Bind(&SettingsResetPromptController::OnInteractionDone, 160 base::Bind(&SettingsResetPromptController::OnInteractionDone,
145 base::Unretained(this))); 161 base::Unretained(this)));
146 } 162 }
147 163
148 void SettingsResetPromptController::Cancel() { 164 void SettingsResetPromptController::Cancel() {
165 DCHECK(!time_dialog_shown_.is_null());
166 base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Declined"));
167 UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilDeclined",
168 base::Time::Now() - time_dialog_shown_);
169 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.PromptAccepted", false);
149 OnInteractionDone(); 170 OnInteractionDone();
150 } 171 }
151 172
152 void SettingsResetPromptController::InitMainText() { 173 void SettingsResetPromptController::InitMainText() {
153 DCHECK(main_text_.empty()); 174 DCHECK(main_text_.empty());
154 175
155 // Get the URL string to be displayed in the dialog message. 176 // Get the URL string to be displayed in the dialog message.
156 base::string16 url_string; 177 base::string16 url_string;
157 if (ResetSearchEnabled(*model_)) { 178 if (ResetSearchEnabled(*model_)) {
158 url_string = FormatUrlForDisplay(model_->default_search()); 179 url_string = FormatUrlForDisplay(model_->default_search());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 url_string, &offset); 218 url_string, &offset);
198 } else { 219 } else {
199 NOTREACHED(); 220 NOTREACHED();
200 } 221 }
201 222
202 main_text_url_range_.set_start(offset); 223 main_text_url_range_.set_start(offset);
203 main_text_url_range_.set_end(offset + url_string.length()); 224 main_text_url_range_.set_end(offset + url_string.length());
204 } 225 }
205 226
206 void SettingsResetPromptController::OnInteractionDone() { 227 void SettingsResetPromptController::OnInteractionDone() {
207 // TODO(alito): Add metrics reporting here.
208 delete this; 228 delete this;
209 } 229 }
210 230
211 void MaybeShowSettingsResetPromptWithDelay() { 231 void MaybeShowSettingsResetPromptWithDelay() {
212 std::unique_ptr<SettingsResetPromptConfig> config = 232 std::unique_ptr<SettingsResetPromptConfig> config =
213 SettingsResetPromptConfig::Create(); 233 SettingsResetPromptConfig::Create();
214 if (!config) 234 if (!config)
215 return; 235 return;
216 236
217 base::TimeDelta delay = config->delay_before_prompt(); 237 base::TimeDelta delay = config->delay_before_prompt();
218 content::BrowserThread::PostDelayedTask( 238 content::BrowserThread::PostDelayedTask(
219 content::BrowserThread::UI, FROM_HERE, 239 content::BrowserThread::UI, FROM_HERE,
220 base::Bind(MaybeShowSettingsResetPrompt, base::Passed(&config)), delay); 240 base::Bind(MaybeShowSettingsResetPrompt, base::Passed(&config)), delay);
221 } 241 }
222 242
223 } // namespace safe_browsing 243 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698