| 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 "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "chrome/browser/ui/startup/default_browser_prompt.h" | 9 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 10 #include "chrome/grit/chromium_strings.h" | 10 #include "chrome/grit/chromium_strings.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 Profile* profile) { | 50 Profile* profile) { |
| 51 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | 51 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
| 52 std::unique_ptr<ConfirmInfoBarDelegate>( | 52 std::unique_ptr<ConfirmInfoBarDelegate>( |
| 53 new DefaultBrowserInfoBarDelegate(profile)))); | 53 new DefaultBrowserInfoBarDelegate(profile)))); |
| 54 } | 54 } |
| 55 | 55 |
| 56 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(Profile* profile) | 56 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(Profile* profile) |
| 57 : ConfirmInfoBarDelegate(), | 57 : ConfirmInfoBarDelegate(), |
| 58 profile_(profile), | 58 profile_(profile), |
| 59 should_expire_(false), | 59 should_expire_(false), |
| 60 action_taken_(false), |
| 60 weak_factory_(this) { | 61 weak_factory_(this) { |
| 61 // We want the info-bar to stick-around for few seconds and then be hidden | 62 // We want the info-bar to stick-around for few seconds and then be hidden |
| 62 // on the next navigation after that. | 63 // on the next navigation after that. |
| 63 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 64 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 64 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, | 65 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, |
| 65 weak_factory_.GetWeakPtr()), | 66 weak_factory_.GetWeakPtr()), |
| 66 base::TimeDelta::FromSeconds(8)); | 67 base::TimeDelta::FromSeconds(8)); |
| 67 } | 68 } |
| 68 | 69 |
| 69 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() = default; | 70 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { |
| 71 if (!action_taken_) { |
| 72 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 73 IGNORE_INFO_BAR, |
| 74 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 75 } |
| 76 } |
| 70 | 77 |
| 71 void DefaultBrowserInfoBarDelegate::AllowExpiry() { | 78 void DefaultBrowserInfoBarDelegate::AllowExpiry() { |
| 72 should_expire_ = true; | 79 should_expire_ = true; |
| 73 } | 80 } |
| 74 | 81 |
| 75 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType() | 82 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType() |
| 76 const { | 83 const { |
| 77 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
| 78 std::string infobar_type = variations::GetVariationParamValue( | 85 std::string infobar_type = variations::GetVariationParamValue( |
| 79 kDefaultBrowserPromptStyle, "InfoBarType"); | 86 kDefaultBrowserPromptStyle, "InfoBarType"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 return ConfirmInfoBarDelegate::GetIcon(); | 127 return ConfirmInfoBarDelegate::GetIcon(); |
| 121 } | 128 } |
| 122 #endif // defined(OS_WIN) | 129 #endif // defined(OS_WIN) |
| 123 | 130 |
| 124 bool DefaultBrowserInfoBarDelegate::ShouldExpire( | 131 bool DefaultBrowserInfoBarDelegate::ShouldExpire( |
| 125 const NavigationDetails& details) const { | 132 const NavigationDetails& details) const { |
| 126 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details); | 133 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details); |
| 127 } | 134 } |
| 128 | 135 |
| 129 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() { | 136 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() { |
| 137 action_taken_ = true; |
| 130 content::RecordAction( | 138 content::RecordAction( |
| 131 base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss")); | 139 base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss")); |
| 132 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 140 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 133 IGNORE_INFO_BAR, | 141 DISMISS_INFO_BAR, |
| 134 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 142 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 135 } | 143 } |
| 136 | 144 |
| 137 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const { | 145 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const { |
| 138 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT); | 146 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT); |
| 139 } | 147 } |
| 140 | 148 |
| 141 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel( | 149 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel( |
| 142 InfoBarButton button) const { | 150 InfoBarButton button) const { |
| 143 #if defined(OS_WIN) | 151 #if defined(OS_WIN) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 157 } | 165 } |
| 158 | 166 |
| 159 // Setting an app as the default browser doesn't require elevation directly, but | 167 // Setting an app as the default browser doesn't require elevation directly, but |
| 160 // it does require registering it as the protocol handler for "http", so if | 168 // it does require registering it as the protocol handler for "http", so if |
| 161 // protocol registration in general requires elevation, this does as well. | 169 // protocol registration in general requires elevation, this does as well. |
| 162 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { | 170 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { |
| 163 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient(); | 171 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient(); |
| 164 } | 172 } |
| 165 | 173 |
| 166 bool DefaultBrowserInfoBarDelegate::Accept() { | 174 bool DefaultBrowserInfoBarDelegate::Accept() { |
| 175 action_taken_ = true; |
| 167 content::RecordAction( | 176 content::RecordAction( |
| 168 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); | 177 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); |
| 169 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 178 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 170 ACCEPT_INFO_BAR, | 179 ACCEPT_INFO_BAR, |
| 171 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 180 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 172 | 181 |
| 173 bool close_infobar = true; | 182 bool close_infobar = true; |
| 174 shell_integration::DefaultWebClientWorkerCallback set_as_default_callback; | 183 shell_integration::DefaultWebClientWorkerCallback set_as_default_callback; |
| 175 | 184 |
| 176 if (IsStickyDefaultBrowserPromptEnabled()) { | 185 if (IsStickyDefaultBrowserPromptEnabled()) { |
| 177 // When the experiment is enabled, the infobar is only closed when the | 186 // When the experiment is enabled, the infobar is only closed when the |
| 178 // DefaultBrowserWorker is finished. | 187 // DefaultBrowserWorker is finished. |
| 179 set_as_default_callback = | 188 set_as_default_callback = |
| 180 base::Bind(&DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished, | 189 base::Bind(&DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished, |
| 181 weak_factory_.GetWeakPtr()); | 190 weak_factory_.GetWeakPtr()); |
| 182 close_infobar = false; | 191 close_infobar = false; |
| 183 } | 192 } |
| 184 | 193 |
| 185 // The worker pointer is reference counted. While it is running, the | 194 // The worker pointer is reference counted. While it is running, the |
| 186 // message loops of the FILE and UI thread will hold references to it | 195 // message loops of the FILE and UI thread will hold references to it |
| 187 // and it will be automatically freed once all its tasks have finished. | 196 // and it will be automatically freed once all its tasks have finished. |
| 188 CreateDefaultBrowserWorker(set_as_default_callback)->StartSetAsDefault(); | 197 CreateDefaultBrowserWorker(set_as_default_callback)->StartSetAsDefault(); |
| 189 return close_infobar; | 198 return close_infobar; |
| 190 } | 199 } |
| 191 | 200 |
| 192 bool DefaultBrowserInfoBarDelegate::Cancel() { | 201 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 202 action_taken_ = true; |
| 193 // This can get reached in tests where profile_ is null. | 203 // This can get reached in tests where profile_ is null. |
| 194 if (profile_) | 204 if (profile_) |
| 195 chrome::DefaultBrowserPromptDeclined(profile_); | 205 chrome::DefaultBrowserPromptDeclined(profile_); |
| 196 content::RecordAction( | 206 content::RecordAction( |
| 197 base::UserMetricsAction("DefaultBrowserInfoBar_Cancel")); | 207 base::UserMetricsAction("DefaultBrowserInfoBar_Cancel")); |
| 198 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 208 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 199 CANCEL_INFO_BAR, | 209 CANCEL_INFO_BAR, |
| 200 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 210 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 201 return true; | 211 return true; |
| 202 } | 212 } |
| 203 | 213 |
| 204 scoped_refptr<shell_integration::DefaultBrowserWorker> | 214 scoped_refptr<shell_integration::DefaultBrowserWorker> |
| 205 DefaultBrowserInfoBarDelegate::CreateDefaultBrowserWorker( | 215 DefaultBrowserInfoBarDelegate::CreateDefaultBrowserWorker( |
| 206 const shell_integration::DefaultWebClientWorkerCallback& callback) { | 216 const shell_integration::DefaultWebClientWorkerCallback& callback) { |
| 207 return new shell_integration::DefaultBrowserWorker(callback); | 217 return new shell_integration::DefaultBrowserWorker(callback); |
| 208 } | 218 } |
| 209 | 219 |
| 210 void DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished( | 220 void DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished( |
| 211 shell_integration::DefaultWebClientState state) { | 221 shell_integration::DefaultWebClientState state) { |
| 212 infobar()->owner()->RemoveInfoBar(infobar()); | 222 infobar()->owner()->RemoveInfoBar(infobar()); |
| 213 } | 223 } |
| 214 | 224 |
| 215 } // namespace chrome | 225 } // namespace chrome |
| OLD | NEW |