Chromium Code Reviews| Index: chrome/browser/ui/startup/default_browser_prompt.cc |
| diff --git a/chrome/browser/ui/startup/default_browser_prompt.cc b/chrome/browser/ui/startup/default_browser_prompt.cc |
| index 8765d386d80a1a3dbbaa14a796fac3be68b70d32..b6dd2b002ca7c4092c5455159e8fb0490776490a 100644 |
| --- a/chrome/browser/ui/startup/default_browser_prompt.cc |
| +++ b/chrome/browser/ui/startup/default_browser_prompt.cc |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| +#include <limits> |
|
Patrick Monette
2016/05/12 23:43:25
This fixes a lint error.
|
| #include <string> |
| #include "base/location.h" |
| @@ -39,11 +40,25 @@ |
| #include "ui/gfx/vector_icons_public.h" |
| #if defined(OS_WIN) |
| +#include "base/feature_list.h" |
| #include "base/win/windows_version.h" |
| #endif |
| namespace { |
| +bool IsStickyDefaultBrowserInfobarEnabled() { |
| +#if defined(OS_WIN) |
| + 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
|
| + "StickyDefaultBrowserInfobar", base::FEATURE_DISABLED_BY_DEFAULT}; |
| + |
| + // The flow to set the default browser is only asynchronous on Windows 10+. |
| + return base::win::GetVersion() >= base::win::VERSION_WIN10 && |
| + base::FeatureList::IsEnabled(kStickyDefaultBrowserInfobar); |
| +#else |
| + return false; |
| +#endif |
| +} |
| + |
| // The delegate for the infobar shown when Chrome is not the default browser. |
| // Ownership of the delegate is given to the infobar itself, the lifetime of |
| // which is bound to the containing WebContents. |
| @@ -86,6 +101,12 @@ class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { |
| bool Accept() override; |
| bool Cancel() override; |
| + // Removes the infobar when the worker is finished setting the default |
| + // browser. Only used if the StickyDefaultBrowserInfobar experiment is |
| + // enabled. |
| + void OnSetAsDefaultFinished( |
| + 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.
|
| + |
| // The WebContents's corresponding profile. |
| Profile* profile_; |
| @@ -192,14 +213,26 @@ bool DefaultBrowserInfoBarDelegate::Accept() { |
| UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| ACCEPT_INFO_BAR, |
| NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| + |
| + bool close_infobar = true; |
| + shell_integration::DefaultWebClientWorkerCallback set_as_default_callback; |
| + |
| + if (IsStickyDefaultBrowserInfobarEnabled()) { |
| + // When the experiment is enabled, the infobar is only closed when the |
| + // DefaultBrowserWorker is finished. |
| + set_as_default_callback = |
| + base::Bind(&DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished, |
| + weak_factory_.GetWeakPtr()); |
| + close_infobar = false; |
| + } |
| + |
| // The worker pointer is reference counted. While it is running, the |
| // message loops of the FILE and UI thread will hold references to it |
| // and it will be automatically freed once all its tasks have finished. |
| scoped_refptr<shell_integration::DefaultBrowserWorker>( |
| - new shell_integration::DefaultBrowserWorker( |
| - shell_integration::DefaultWebClientWorkerCallback())) |
| + new shell_integration::DefaultBrowserWorker(set_as_default_callback)) |
| ->StartSetAsDefault(); |
| - return true; |
| + return close_infobar; |
| } |
| bool DefaultBrowserInfoBarDelegate::Cancel() { |
| @@ -212,6 +245,11 @@ bool DefaultBrowserInfoBarDelegate::Cancel() { |
| return true; |
| } |
| +void DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished( |
| + shell_integration::DefaultWebClientState /* state */) { |
| + infobar()->owner()->RemoveInfoBar(infobar()); |
| +} |
| + |
| void ResetCheckDefaultBrowserPref(const base::FilePath& profile_path) { |
| Profile* profile = |
| g_browser_process->profile_manager()->GetProfileByPath(profile_path); |