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

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

Issue 1974153002: Add an experiment for the default browser infobar on Windows 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <limits>
Patrick Monette 2016/05/12 23:43:25 This fixes a lint error.
7 #include <string> 8 #include <string>
8 9
9 #include "base/location.h" 10 #include "base/location.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
13 #include "base/metrics/user_metrics_action.h" 14 #include "base/metrics/user_metrics_action.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
(...skipping 15 matching lines...) Expand all
32 #include "components/prefs/pref_registry_simple.h" 33 #include "components/prefs/pref_registry_simple.h"
33 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
34 #include "components/variations/variations_associated_data.h" 35 #include "components/variations/variations_associated_data.h"
35 #include "components/version_info/version_info.h" 36 #include "components/version_info/version_info.h"
36 #include "content/public/browser/user_metrics.h" 37 #include "content/public/browser/user_metrics.h"
37 #include "grit/theme_resources.h" 38 #include "grit/theme_resources.h"
38 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/gfx/vector_icons_public.h" 40 #include "ui/gfx/vector_icons_public.h"
40 41
41 #if defined(OS_WIN) 42 #if defined(OS_WIN)
43 #include "base/feature_list.h"
42 #include "base/win/windows_version.h" 44 #include "base/win/windows_version.h"
43 #endif 45 #endif
44 46
45 namespace { 47 namespace {
46 48
49 bool IsStickyDefaultBrowserInfobarEnabled() {
50 #if defined(OS_WIN)
51 static const base::Feature kStickyDefaultBrowserInfobar{
Peter Kasting 2016/05/17 03:07:37 Nit: Can be constexpr
Patrick Monette 2016/05/31 15:19:41 I can't manage to make it constexpr now that I'm d
52 "StickyDefaultBrowserInfobar", base::FEATURE_DISABLED_BY_DEFAULT};
53
54 // The flow to set the default browser is only asynchronous on Windows 10+.
55 return base::win::GetVersion() >= base::win::VERSION_WIN10 &&
56 base::FeatureList::IsEnabled(kStickyDefaultBrowserInfobar);
57 #else
58 return false;
59 #endif
60 }
61
47 // The delegate for the infobar shown when Chrome is not the default browser. 62 // The delegate for the infobar shown when Chrome is not the default browser.
48 // Ownership of the delegate is given to the infobar itself, the lifetime of 63 // Ownership of the delegate is given to the infobar itself, the lifetime of
49 // which is bound to the containing WebContents. 64 // which is bound to the containing WebContents.
50 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { 65 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
51 public: 66 public:
52 // Creates a default browser infobar and delegate and adds the infobar to 67 // Creates a default browser infobar and delegate and adds the infobar to
53 // |infobar_service|. 68 // |infobar_service|.
54 static void Create(InfoBarService* infobar_service, Profile* profile); 69 static void Create(InfoBarService* infobar_service, Profile* profile);
55 70
56 private: 71 private:
(...skipping 22 matching lines...) Expand all
79 bool ShouldExpire(const NavigationDetails& details) const override; 94 bool ShouldExpire(const NavigationDetails& details) const override;
80 void InfoBarDismissed() override; 95 void InfoBarDismissed() override;
81 96
82 // ConfirmInfoBarDelegate: 97 // ConfirmInfoBarDelegate:
83 base::string16 GetMessageText() const override; 98 base::string16 GetMessageText() const override;
84 base::string16 GetButtonLabel(InfoBarButton button) const override; 99 base::string16 GetButtonLabel(InfoBarButton button) const override;
85 bool OKButtonTriggersUACPrompt() const override; 100 bool OKButtonTriggersUACPrompt() const override;
86 bool Accept() override; 101 bool Accept() override;
87 bool Cancel() override; 102 bool Cancel() override;
88 103
104 // Removes the infobar when the worker is finished setting the default
105 // browser. Only used if the StickyDefaultBrowserInfobar experiment is
106 // enabled.
107 void OnSetAsDefaultFinished(
108 shell_integration::DefaultWebClientState /* state */);
Peter Kasting 2016/05/17 03:07:37 Nit: No /* */; put the name uncommented here and b
Patrick Monette 2016/05/31 15:19:41 Done.
109
89 // The WebContents's corresponding profile. 110 // The WebContents's corresponding profile.
90 Profile* profile_; 111 Profile* profile_;
91 112
92 // Whether the info-bar should be dismissed on the next navigation. 113 // Whether the info-bar should be dismissed on the next navigation.
93 bool should_expire_ = false; 114 bool should_expire_ = false;
94 115
95 // Used to delay the expiration of the info-bar. 116 // Used to delay the expiration of the info-bar.
96 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; 117 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_;
97 118
98 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); 119 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { 206 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const {
186 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient(); 207 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient();
187 } 208 }
188 209
189 bool DefaultBrowserInfoBarDelegate::Accept() { 210 bool DefaultBrowserInfoBarDelegate::Accept() {
190 content::RecordAction( 211 content::RecordAction(
191 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); 212 base::UserMetricsAction("DefaultBrowserInfoBar_Accept"));
192 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", 213 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
193 ACCEPT_INFO_BAR, 214 ACCEPT_INFO_BAR,
194 NUM_INFO_BAR_USER_INTERACTION_TYPES); 215 NUM_INFO_BAR_USER_INTERACTION_TYPES);
216
217 bool close_infobar = true;
218 shell_integration::DefaultWebClientWorkerCallback set_as_default_callback;
219
220 if (IsStickyDefaultBrowserInfobarEnabled()) {
221 // When the experiment is enabled, the infobar is only closed when the
222 // DefaultBrowserWorker is finished.
223 set_as_default_callback =
224 base::Bind(&DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished,
225 weak_factory_.GetWeakPtr());
226 close_infobar = false;
227 }
228
195 // The worker pointer is reference counted. While it is running, the 229 // The worker pointer is reference counted. While it is running, the
196 // message loops of the FILE and UI thread will hold references to it 230 // message loops of the FILE and UI thread will hold references to it
197 // and it will be automatically freed once all its tasks have finished. 231 // and it will be automatically freed once all its tasks have finished.
198 scoped_refptr<shell_integration::DefaultBrowserWorker>( 232 scoped_refptr<shell_integration::DefaultBrowserWorker>(
199 new shell_integration::DefaultBrowserWorker( 233 new shell_integration::DefaultBrowserWorker(set_as_default_callback))
200 shell_integration::DefaultWebClientWorkerCallback()))
201 ->StartSetAsDefault(); 234 ->StartSetAsDefault();
202 return true; 235 return close_infobar;
203 } 236 }
204 237
205 bool DefaultBrowserInfoBarDelegate::Cancel() { 238 bool DefaultBrowserInfoBarDelegate::Cancel() {
206 chrome::DefaultBrowserPromptDeclined(profile_); 239 chrome::DefaultBrowserPromptDeclined(profile_);
207 content::RecordAction( 240 content::RecordAction(
208 base::UserMetricsAction("DefaultBrowserInfoBar_Cancel")); 241 base::UserMetricsAction("DefaultBrowserInfoBar_Cancel"));
209 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", 242 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
210 CANCEL_INFO_BAR, 243 CANCEL_INFO_BAR,
211 NUM_INFO_BAR_USER_INTERACTION_TYPES); 244 NUM_INFO_BAR_USER_INTERACTION_TYPES);
212 return true; 245 return true;
213 } 246 }
214 247
248 void DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished(
249 shell_integration::DefaultWebClientState /* state */) {
250 infobar()->owner()->RemoveInfoBar(infobar());
251 }
252
215 void ResetCheckDefaultBrowserPref(const base::FilePath& profile_path) { 253 void ResetCheckDefaultBrowserPref(const base::FilePath& profile_path) {
216 Profile* profile = 254 Profile* profile =
217 g_browser_process->profile_manager()->GetProfileByPath(profile_path); 255 g_browser_process->profile_manager()->GetProfileByPath(profile_path);
218 if (profile) 256 if (profile)
219 chrome::ResetDefaultBrowserPrompt(profile); 257 chrome::ResetDefaultBrowserPrompt(profile);
220 } 258 }
221 259
222 void ShowPrompt() { 260 void ShowPrompt() {
223 Browser* browser = chrome::FindLastActive(); 261 Browser* browser = chrome::FindLastActive();
224 if (!browser) 262 if (!browser)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 profile->GetPrefs()->ClearPref(prefs::kDefaultBrowserLastDeclined); 365 profile->GetPrefs()->ClearPref(prefs::kDefaultBrowserLastDeclined);
328 } 366 }
329 367
330 #if !defined(OS_WIN) 368 #if !defined(OS_WIN)
331 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { 369 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
332 return false; 370 return false;
333 } 371 }
334 #endif 372 #endif
335 373
336 } // namespace chrome 374 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698