| OLD | NEW |
| 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 "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 | 29 |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Calls the appropriate function for setting Chrome as the default browser. | 34 // Calls the appropriate function for setting Chrome as the default browser. |
| 35 // This requires IO access (registry) and may result in interaction with a | 35 // This requires IO access (registry) and may result in interaction with a |
| 36 // modal system UI. | 36 // modal system UI. |
| 37 void SetChromeAsDefaultBrowser(bool interactive_flow) { | 37 void SetChromeAsDefaultBrowser(bool interactive_flow, PrefService* prefs) { |
| 38 if (interactive_flow) { | 38 if (interactive_flow) { |
| 39 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUI", 1); | 39 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUI", 1); |
| 40 if (!ShellIntegration::SetAsDefaultBrowserInteractive()) | 40 if (!ShellIntegration::SetAsDefaultBrowserInteractive()) { |
| 41 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUIFailed", 1); | 41 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUIFailed", 1); |
| 42 } else if (!ShellIntegration::IsDefaultBrowser()) { |
| 43 // If the interaction succeeded but we are still not the default browser |
| 44 // it likely means the user simply selected another browser from the |
| 45 // panel. We will respect this choice and write it down as 'no, thanks'. |
| 46 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); |
| 47 // User clicked "Don't ask me again", remember that. |
| 48 if (prefs) |
| 49 prefs->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| 50 } |
| 42 } else { | 51 } else { |
| 43 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); | 52 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); |
| 44 ShellIntegration::SetAsDefaultBrowser(); | 53 ShellIntegration::SetAsDefaultBrowser(); |
| 45 } | 54 } |
| 46 } | 55 } |
| 47 | 56 |
| 48 // The delegate for the infobar shown when Chrome is not the default browser. | 57 // The delegate for the infobar shown when Chrome is not the default browser. |
| 49 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { | 58 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 50 public: | 59 public: |
| 51 DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, | 60 DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 136 |
| 128 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { | 137 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { |
| 129 return button == BUTTON_OK; | 138 return button == BUTTON_OK; |
| 130 } | 139 } |
| 131 | 140 |
| 132 bool DefaultBrowserInfoBarDelegate::Accept() { | 141 bool DefaultBrowserInfoBarDelegate::Accept() { |
| 133 action_taken_ = true; | 142 action_taken_ = true; |
| 134 BrowserThread::PostTask( | 143 BrowserThread::PostTask( |
| 135 BrowserThread::FILE, | 144 BrowserThread::FILE, |
| 136 FROM_HERE, | 145 FROM_HERE, |
| 137 base::Bind(&SetChromeAsDefaultBrowser, interactive_flow_required_)); | 146 base::Bind(&SetChromeAsDefaultBrowser, interactive_flow_required_, |
| 147 prefs_)); |
| 138 | 148 |
| 139 return true; | 149 return true; |
| 140 } | 150 } |
| 141 | 151 |
| 142 bool DefaultBrowserInfoBarDelegate::Cancel() { | 152 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 143 action_taken_ = true; | 153 action_taken_ = true; |
| 144 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); | 154 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); |
| 145 // User clicked "Don't ask me again", remember that. | 155 // User clicked "Don't ask me again", remember that. |
| 146 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); | 156 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| 147 return true; | 157 return true; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // TODO(pastarmovj): We can't really do anything meaningful here yet but | 199 // TODO(pastarmovj): We can't really do anything meaningful here yet but |
| 190 // just prevent showing the infobar. | 200 // just prevent showing the infobar. |
| 191 } | 201 } |
| 192 return; | 202 return; |
| 193 } | 203 } |
| 194 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 204 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 195 base::Bind(&CheckDefaultBrowserCallback)); | 205 base::Bind(&CheckDefaultBrowserCallback)); |
| 196 | 206 |
| 197 } | 207 } |
| 198 | 208 |
| 209 #if !defined(OS_WIN) |
| 210 void ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
| 211 } |
| 212 #endif |
| 213 |
| 199 namespace internal { | 214 namespace internal { |
| 200 | 215 |
| 201 void NotifyNotDefaultBrowserCallback() { | 216 void NotifyNotDefaultBrowserCallback() { |
| 202 Browser* browser = BrowserList::GetLastActive(); | 217 Browser* browser = BrowserList::GetLastActive(); |
| 203 if (!browser) | 218 if (!browser) |
| 204 return; // Reached during ui tests. | 219 return; // Reached during ui tests. |
| 205 | 220 |
| 206 // In ChromeBot tests, there might be a race. This line appears to get | 221 // In ChromeBot tests, there might be a race. This line appears to get |
| 207 // called during shutdown and |tab| can be NULL. | 222 // called during shutdown and |tab| can be NULL. |
| 208 TabContents* tab = browser->GetActiveTabContents(); | 223 TabContents* tab = browser->GetActiveTabContents(); |
| 209 if (!tab) | 224 if (!tab) |
| 210 return; | 225 return; |
| 211 | 226 |
| 212 // Don't show the info-bar if there are already info-bars showing. | 227 // Don't show the info-bar if there are already info-bars showing. |
| 213 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); | 228 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); |
| 214 if (infobar_helper->infobar_count() > 0) | 229 if (infobar_helper->infobar_count() > 0) |
| 215 return; | 230 return; |
| 216 | 231 |
| 217 bool interactive_flow = ShellIntegration::CanSetAsDefaultBrowser() == | 232 bool interactive_flow = ShellIntegration::CanSetAsDefaultBrowser() == |
| 218 ShellIntegration::SET_DEFAULT_INTERACTIVE; | 233 ShellIntegration::SET_DEFAULT_INTERACTIVE; |
| 219 infobar_helper->AddInfoBar( | 234 infobar_helper->AddInfoBar( |
| 220 new DefaultBrowserInfoBarDelegate(infobar_helper, | 235 new DefaultBrowserInfoBarDelegate(infobar_helper, |
| 221 tab->profile()->GetPrefs(), | 236 tab->profile()->GetPrefs(), |
| 222 interactive_flow)); | 237 interactive_flow)); |
| 223 } | 238 } |
| 224 | 239 |
| 225 } // namespace internal | 240 } // namespace internal |
| 226 } // namespace browser | 241 } // namespace browser |
| OLD | NEW |