| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_infobar_delegate.h" | 5 #include "chrome/browser/ui/startup/default_browser_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/metrics/user_metrics.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "chrome/app/vector_icons/vector_icons.h" | 12 #include "chrome/app/vector_icons/vector_icons.h" |
| 12 #include "chrome/browser/ui/startup/default_browser_prompt.h" | 13 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 13 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
| 14 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/infobars/core/infobar.h" | 16 #include "components/infobars/core/infobar.h" |
| 16 #include "content/public/browser/user_metrics.h" | |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 | 18 |
| 19 namespace chrome { | 19 namespace chrome { |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service, | 22 void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 23 Profile* profile) { | 23 Profile* profile) { |
| 24 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | 24 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
| 25 std::unique_ptr<ConfirmInfoBarDelegate>( | 25 std::unique_ptr<ConfirmInfoBarDelegate>( |
| 26 new DefaultBrowserInfoBarDelegate(profile)))); | 26 new DefaultBrowserInfoBarDelegate(profile)))); |
| 27 } | 27 } |
| 28 | 28 |
| 29 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(Profile* profile) | 29 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(Profile* profile) |
| 30 : ConfirmInfoBarDelegate(), | 30 : ConfirmInfoBarDelegate(), |
| 31 profile_(profile), | 31 profile_(profile), |
| 32 should_expire_(false), | 32 should_expire_(false), |
| 33 action_taken_(false), | 33 action_taken_(false), |
| 34 weak_factory_(this) { | 34 weak_factory_(this) { |
| 35 // We want the info-bar to stick-around for few seconds and then be hidden | 35 // We want the info-bar to stick-around for few seconds and then be hidden |
| 36 // on the next navigation after that. | 36 // on the next navigation after that. |
| 37 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 37 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 38 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, | 38 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, |
| 39 weak_factory_.GetWeakPtr()), | 39 weak_factory_.GetWeakPtr()), |
| 40 base::TimeDelta::FromSeconds(8)); | 40 base::TimeDelta::FromSeconds(8)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { | 43 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { |
| 44 if (!action_taken_) { | 44 if (!action_taken_) { |
| 45 content::RecordAction( | 45 base::RecordAction(base::UserMetricsAction("DefaultBrowserInfoBar_Ignore")); |
| 46 base::UserMetricsAction("DefaultBrowserInfoBar_Ignore")); | |
| 47 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 46 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 48 IGNORE_INFO_BAR, | 47 IGNORE_INFO_BAR, |
| 49 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 48 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 50 } | 49 } |
| 51 } | 50 } |
| 52 | 51 |
| 53 void DefaultBrowserInfoBarDelegate::AllowExpiry() { | 52 void DefaultBrowserInfoBarDelegate::AllowExpiry() { |
| 54 should_expire_ = true; | 53 should_expire_ = true; |
| 55 } | 54 } |
| 56 | 55 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 71 bool DefaultBrowserInfoBarDelegate::ShouldExpire( | 70 bool DefaultBrowserInfoBarDelegate::ShouldExpire( |
| 72 const NavigationDetails& details) const { | 71 const NavigationDetails& details) const { |
| 73 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details); | 72 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details); |
| 74 } | 73 } |
| 75 | 74 |
| 76 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() { | 75 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() { |
| 77 action_taken_ = true; | 76 action_taken_ = true; |
| 78 // |profile_| may be null in tests. | 77 // |profile_| may be null in tests. |
| 79 if (profile_) | 78 if (profile_) |
| 80 chrome::DefaultBrowserPromptDeclined(profile_); | 79 chrome::DefaultBrowserPromptDeclined(profile_); |
| 81 content::RecordAction( | 80 base::RecordAction(base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss")); |
| 82 base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss")); | |
| 83 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 81 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 84 DISMISS_INFO_BAR, | 82 DISMISS_INFO_BAR, |
| 85 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 83 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 86 } | 84 } |
| 87 | 85 |
| 88 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const { | 86 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const { |
| 89 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT); | 87 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT); |
| 90 } | 88 } |
| 91 | 89 |
| 92 int DefaultBrowserInfoBarDelegate::GetButtons() const { | 90 int DefaultBrowserInfoBarDelegate::GetButtons() const { |
| 93 return BUTTON_OK; | 91 return BUTTON_OK; |
| 94 } | 92 } |
| 95 | 93 |
| 96 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel( | 94 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel( |
| 97 InfoBarButton button) const { | 95 InfoBarButton button) const { |
| 98 DCHECK_EQ(BUTTON_OK, button); | 96 DCHECK_EQ(BUTTON_OK, button); |
| 99 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL); | 97 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL); |
| 100 } | 98 } |
| 101 | 99 |
| 102 // Setting an app as the default browser doesn't require elevation directly, but | 100 // Setting an app as the default browser doesn't require elevation directly, but |
| 103 // it does require registering it as the protocol handler for "http", so if | 101 // it does require registering it as the protocol handler for "http", so if |
| 104 // protocol registration in general requires elevation, this does as well. | 102 // protocol registration in general requires elevation, this does as well. |
| 105 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { | 103 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { |
| 106 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient(); | 104 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient(); |
| 107 } | 105 } |
| 108 | 106 |
| 109 bool DefaultBrowserInfoBarDelegate::Accept() { | 107 bool DefaultBrowserInfoBarDelegate::Accept() { |
| 110 action_taken_ = true; | 108 action_taken_ = true; |
| 111 content::RecordAction( | 109 base::RecordAction(base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); |
| 112 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); | |
| 113 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 110 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 114 ACCEPT_INFO_BAR, | 111 ACCEPT_INFO_BAR, |
| 115 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 112 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 116 | 113 |
| 117 // The worker pointer is reference counted. While it is running, the | 114 // The worker pointer is reference counted. While it is running, the |
| 118 // message loops of the FILE and UI thread will hold references to it | 115 // message loops of the FILE and UI thread will hold references to it |
| 119 // and it will be automatically freed once all its tasks have finished. | 116 // and it will be automatically freed once all its tasks have finished. |
| 120 make_scoped_refptr(new shell_integration::DefaultBrowserWorker( | 117 make_scoped_refptr(new shell_integration::DefaultBrowserWorker( |
| 121 shell_integration::DefaultWebClientWorkerCallback())) | 118 shell_integration::DefaultWebClientWorkerCallback())) |
| 122 ->StartSetAsDefault(); | 119 ->StartSetAsDefault(); |
| 123 return true; | 120 return true; |
| 124 } | 121 } |
| 125 | 122 |
| 126 } // namespace chrome | 123 } // namespace chrome |
| OLD | NEW |