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

Side by Side Diff: chrome/browser/ui/startup/default_browser_prompt.cc

Issue 1426663005: Make the histograms for setting the default browser consistent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments 2 Created 5 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/startup/default_browser_prompt.h" 5 #include "chrome/browser/ui/startup/default_browser_prompt.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/user_metrics_action.h"
12 #include "base/prefs/pref_registry_simple.h" 13 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
16 #include "base/version.h" 17 #include "base/version.h"
17 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/infobars/infobar_service.h" 19 #include "chrome/browser/infobars/infobar_service.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/shell_integration.h"
22 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_finder.h" 23 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "chrome/grit/chromium_strings.h" 26 #include "chrome/grit/chromium_strings.h"
27 #include "chrome/grit/generated_resources.h" 27 #include "chrome/grit/generated_resources.h"
28 #include "components/infobars/core/confirm_infobar_delegate.h" 28 #include "components/infobars/core/confirm_infobar_delegate.h"
29 #include "components/infobars/core/infobar.h" 29 #include "components/infobars/core/infobar.h"
30 #include "components/version_info/version_info.h" 30 #include "components/version_info/version_info.h"
31 #include "content/public/browser/navigation_details.h" 31 #include "content/public/browser/navigation_details.h"
32 #include "content/public/browser/user_metrics.h"
32 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
33 #include "grit/theme_resources.h" 34 #include "grit/theme_resources.h"
34 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/gfx/vector_icons_public.h" 36 #include "ui/gfx/vector_icons_public.h"
36 37
37 namespace { 38 namespace {
38 39
39 // A ShellIntegration::DefaultWebClientObserver that records user metrics for
40 // the result of making Chrome the default browser.
41 class SetDefaultBrowserObserver
42 : public ShellIntegration::DefaultWebClientObserver {
43 public:
44 SetDefaultBrowserObserver();
45 ~SetDefaultBrowserObserver() override;
46
47 private:
48 void SetDefaultWebClientUIState(
49 ShellIntegration::DefaultWebClientUIState state) override;
50 void OnSetAsDefaultConcluded(bool succeeded) override;
51 bool IsOwnedByWorker() override;
52 bool IsInteractiveSetDefaultPermitted() override;
53
54 // True if an interactive flow will be used (i.e., Windows 8+).
55 bool interactive_;
56
57 // The result of the call to ShellIntegration::SetAsDefaultBrowser() or
58 // ShellIntegration::SetAsDefaultBrowserInteractive().
59 bool interaction_succeeded_ = false;
60
61 DISALLOW_COPY_AND_ASSIGN(SetDefaultBrowserObserver);
62 };
63
64 SetDefaultBrowserObserver::SetDefaultBrowserObserver()
65 : interactive_(ShellIntegration::CanSetAsDefaultBrowser() ==
66 ShellIntegration::SET_DEFAULT_INTERACTIVE) {
67 // Log that an attempt is about to be made to set one way or the other.
68 if (interactive_)
69 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.SetAsDefaultUI", true);
70 else
71 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.SetAsDefault", true);
72 }
73
74 SetDefaultBrowserObserver::~SetDefaultBrowserObserver() {}
75
76 void SetDefaultBrowserObserver::SetDefaultWebClientUIState(
77 ShellIntegration::DefaultWebClientUIState state) {
78 if (interactive_ && interaction_succeeded_ &&
79 state == ShellIntegration::STATE_NOT_DEFAULT) {
80 // The interactive flow succeeded, yet Chrome is not the default browser.
81 // This likely means that the user selected another browser from the panel.
82 // Consider this the same as canceling the infobar.
83 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.DontSetAsDefault", true);
84 }
85 }
86
87 void SetDefaultBrowserObserver::OnSetAsDefaultConcluded(bool succeeded) {
88 interaction_succeeded_ = succeeded;
89 if (interactive_ && !succeeded) {
90 // Log that the interactive flow failed.
91 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.SetAsDefaultUIFailed", true);
92 }
93 }
94
95 bool SetDefaultBrowserObserver::IsOwnedByWorker() {
96 // Instruct the DefaultBrowserWorker to delete this instance when it is done.
97 return true;
98 }
99
100 bool SetDefaultBrowserObserver::IsInteractiveSetDefaultPermitted() {
101 return true;
102 }
103
104 // The delegate for the infobar shown when Chrome is not the default browser. 40 // The delegate for the infobar shown when Chrome is not the default browser.
105 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { 41 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
106 public: 42 public:
107 // Creates a default browser infobar and delegate and adds the infobar to 43 // Creates a default browser infobar and delegate and adds the infobar to
108 // |infobar_service|. 44 // |infobar_service|.
109 static void Create(InfoBarService* infobar_service, PrefService* prefs); 45 static void Create(InfoBarService* infobar_service, PrefService* prefs);
110 46
111 private: 47 private:
112 explicit DefaultBrowserInfoBarDelegate(PrefService* prefs); 48 explicit DefaultBrowserInfoBarDelegate(PrefService* prefs);
113 ~DefaultBrowserInfoBarDelegate() override; 49 ~DefaultBrowserInfoBarDelegate() override;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // We want the info-bar to stick-around for few seconds and then be hidden 93 // We want the info-bar to stick-around for few seconds and then be hidden
158 // on the next navigation after that. 94 // on the next navigation after that.
159 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 95 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
160 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, 96 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry,
161 weak_factory_.GetWeakPtr()), 97 weak_factory_.GetWeakPtr()),
162 base::TimeDelta::FromSeconds(8)); 98 base::TimeDelta::FromSeconds(8));
163 } 99 }
164 100
165 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { 101 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() {
166 if (!action_taken_) 102 if (!action_taken_)
167 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.Ignored", true); 103 UMA_HISTOGRAM_BOOLEAN("DefaultBrowser.InfoBar.Ignored", true);
168 } 104 }
169 105
170 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType() 106 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType()
171 const { 107 const {
172 #if defined(OS_WIN) 108 #if defined(OS_WIN)
173 return WARNING_TYPE; 109 return WARNING_TYPE;
174 #else 110 #else
175 return PAGE_ACTION_TYPE; 111 return PAGE_ACTION_TYPE;
176 #endif 112 #endif
177 } 113 }
(...skipping 28 matching lines...) Expand all
206 142
207 // Setting an app as the default browser doesn't require elevation directly, but 143 // Setting an app as the default browser doesn't require elevation directly, but
208 // it does require registering it as the protocol handler for "http", so if 144 // it does require registering it as the protocol handler for "http", so if
209 // protocol registration in general requires elevation, this does as well. 145 // protocol registration in general requires elevation, this does as well.
210 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { 146 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const {
211 return ShellIntegration::IsElevationNeededForSettingDefaultProtocolClient(); 147 return ShellIntegration::IsElevationNeededForSettingDefaultProtocolClient();
212 } 148 }
213 149
214 bool DefaultBrowserInfoBarDelegate::Accept() { 150 bool DefaultBrowserInfoBarDelegate::Accept() {
215 action_taken_ = true; 151 action_taken_ = true;
152 content::RecordAction(
153 base::UserMetricsAction("DefaultBrowserInfoBar_Accept"));
154 UMA_HISTOGRAM_COUNTS("DefaultBrowser.InfoBar.StartSetAsDefault", 1);
rkaplow 2015/11/13 15:56:14 would be consistant within these histograms, proba
Patrick Monette 2015/11/16 17:29:05 Done.
216 scoped_refptr<ShellIntegration::DefaultBrowserWorker>( 155 scoped_refptr<ShellIntegration::DefaultBrowserWorker>(
217 new ShellIntegration::DefaultBrowserWorker(new SetDefaultBrowserObserver)) 156 new ShellIntegration::DefaultBrowserWorker(nullptr))
218 ->StartSetAsDefault(); 157 ->StartSetAsDefault();
219 return true; 158 return true;
220 } 159 }
221 160
222 bool DefaultBrowserInfoBarDelegate::Cancel() { 161 bool DefaultBrowserInfoBarDelegate::Cancel() {
223 action_taken_ = true; 162 action_taken_ = true;
224 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.DontSetAsDefault", true); 163 content::RecordAction(
164 base::UserMetricsAction("DefaultBrowserInfoBar_DontAskAgain"));
165 UMA_HISTOGRAM_COUNTS("DefaultBrowser.InfoBar.DontAskAgain", 1);
225 // User clicked "Don't ask me again", remember that. 166 // User clicked "Don't ask me again", remember that.
226 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); 167 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false);
227 return true; 168 return true;
228 } 169 }
229 170
230 // A ShellIntegration::DefaultWebClientObserver that handles the check to 171 // A ShellIntegration::DefaultWebClientObserver that handles the check to
231 // determine whether or not to show the default browser prompt. If Chrome is the 172 // determine whether or not to show the default browser prompt. If Chrome is the
232 // default browser, then the kCheckDefaultBrowser pref is reset. Otherwise, the 173 // default browser, then the kCheckDefaultBrowser pref is reset. Otherwise, the
233 // prompt is shown. 174 // prompt is shown.
234 class CheckDefaultBrowserObserver 175 class CheckDefaultBrowserObserver
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 ->StartCheckIsDefault(); 295 ->StartCheckIsDefault();
355 } 296 }
356 297
357 #if !defined(OS_WIN) 298 #if !defined(OS_WIN)
358 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { 299 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
359 return false; 300 return false;
360 } 301 }
361 #endif 302 #endif
362 303
363 } // namespace chrome 304 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698