| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 141 |
| 133 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { | 142 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { |
| 134 return button == BUTTON_OK; | 143 return button == BUTTON_OK; |
| 135 } | 144 } |
| 136 | 145 |
| 137 bool DefaultBrowserInfoBarDelegate::Accept() { | 146 bool DefaultBrowserInfoBarDelegate::Accept() { |
| 138 action_taken_ = true; | 147 action_taken_ = true; |
| 139 BrowserThread::PostTask( | 148 BrowserThread::PostTask( |
| 140 BrowserThread::FILE, | 149 BrowserThread::FILE, |
| 141 FROM_HERE, | 150 FROM_HERE, |
| 142 base::Bind(&SetChromeAsDefaultBrowser, interactive_flow_required_)); | 151 base::Bind(&SetChromeAsDefaultBrowser, interactive_flow_required_, |
| 152 prefs_)); |
| 143 | 153 |
| 144 return true; | 154 return true; |
| 145 } | 155 } |
| 146 | 156 |
| 147 bool DefaultBrowserInfoBarDelegate::Cancel() { | 157 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 148 action_taken_ = true; | 158 action_taken_ = true; |
| 149 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); | 159 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); |
| 150 // User clicked "Don't ask me again", remember that. | 160 // User clicked "Don't ask me again", remember that. |
| 151 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); | 161 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| 152 return true; | 162 return true; |
| (...skipping 36 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 |