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 06a36d002db6ab1a3af8bd183530e90ad4e39c7b..127a2ac29a25022cea027c502944ee1dbab22bd5 100644 |
| --- a/chrome/browser/ui/startup/default_browser_prompt.cc |
| +++ b/chrome/browser/ui/startup/default_browser_prompt.cc |
| @@ -15,11 +15,15 @@ |
| #include "chrome/browser/shell_integration.h" |
| #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| #include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_finder.h" |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| +#include "chrome/browser/ui/webui/metroizer_ui.h" |
| #include "chrome/common/pref_names.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/navigation_details.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/notification_types.h" |
| #include "grit/chromium_strings.h" |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources.h" |
| @@ -34,11 +38,20 @@ namespace { |
| // Calls the appropriate function for setting Chrome as the default browser. |
| // This requires IO access (registry) and may result in interaction with a |
| // modal system UI. |
| -void SetChromeAsDefaultBrowser(bool interactive_flow) { |
| +void SetChromeAsDefaultBrowser(bool interactive_flow, PrefService* prefs) { |
| if (interactive_flow) { |
| UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUI", 1); |
| - if (!ShellIntegration::SetAsDefaultBrowserInteractive()) |
| + if (!ShellIntegration::SetAsDefaultBrowserInteractive()) { |
| UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUIFailed", 1); |
| + } else if (!ShellIntegration::IsDefaultBrowser()) { |
| + // If the interaction succeeded but we are still not the default browser |
| + // it likely means the user simply selected another browser from the |
| + // panel. We will respect this choice and write it down as 'no, thanks'. |
| + UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); |
| + // User clicked "Don't ask me again", remember that. |
| + if (prefs) |
| + prefs->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| + } |
| } else { |
| UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); |
| ShellIntegration::SetAsDefaultBrowser(); |
| @@ -139,7 +152,9 @@ bool DefaultBrowserInfoBarDelegate::Accept() { |
| BrowserThread::PostTask( |
| BrowserThread::FILE, |
| FROM_HERE, |
| - base::Bind(&SetChromeAsDefaultBrowser, interactive_flow_required_)); |
| + base::Bind(&SetChromeAsDefaultBrowser, |
|
grt (UTC plus 2)
2012/06/18 19:19:13
condense
motek.
2012/06/19 18:06:44
Done.
|
| + interactive_flow_required_, |
| + prefs_)); |
| return true; |
| } |
| @@ -164,6 +179,64 @@ void CheckDefaultBrowserCallback() { |
| } |
| } |
| +static void CheckDefaultAndShowMetroizerCallback( |
| + Profile* profile, Browser* browser, bool dialog) { |
| + if (!ShellIntegration::IsDefaultBrowser() || |
| + (ShellIntegration::CanSetAsDefaultBrowser() == |
| + ShellIntegration::SET_DEFAULT_INTERACTIVE)) { |
| + MetroizerUI::Show(profile, browser, dialog); |
|
grt (UTC plus 2)
2012/06/18 19:19:13
de-indent two spaces
motek.
2012/06/19 18:06:44
Done.
|
| + } |
| +} |
| + |
| +class SetMetroBrowserFlowLauncher : public content::NotificationObserver { |
| + public: |
| + static void LaunchSoon(Profile* profile) { |
| + // The instance will manage its own lifetime. |
| + new SetMetroBrowserFlowLauncher(profile); |
| + } |
| + |
| + private: |
| + explicit SetMetroBrowserFlowLauncher(Profile* profile) |
| + : profile_(profile) { |
| + registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| + content::NotificationService::AllSources()); |
| + } |
| + |
| + // content::NotificationObserver override: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + content::NotificationRegistrar registrar_; |
| + Profile* profile_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher); |
| +}; |
| + |
| +void SetMetroBrowserFlowLauncher::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME); |
| + Browser* browser = browser::FindBrowserWithWebContents( |
| + content::Source<content::WebContents>(source).ptr()); |
|
grt (UTC plus 2)
2012/06/18 19:19:13
nit: indent two more spaces
motek.
2012/06/19 18:06:44
Done.
|
| + |
| + if (!browser || !browser->is_type_tabbed()) |
| + return; |
| + |
| + // Unregister and delete. |
|
grt (UTC plus 2)
2012/06/18 19:19:13
i don't see the delete. is it handled by the regi
motek.
2012/06/19 18:06:44
You are right, obviously. I must have clipped it i
|
| + registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| + content::NotificationService::AllSources()); |
| + |
| + bool as_dialog = |
| + profile_->GetPrefs()->GetBoolean(prefs::kDefaultBrowserFlowDialog); |
| + BrowserThread::PostTask( |
|
grt (UTC plus 2)
2012/06/18 19:19:13
save the whitespace! (args can share lines)
motek.
2012/06/19 18:06:44
Done.
|
| + BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind(&CheckDefaultAndShowMetroizerCallback, |
| + profile_, browser, as_dialog)); |
| +} |
| + |
| } // namespace |
| namespace browser { |
| @@ -196,6 +269,16 @@ void ShowDefaultBrowserPrompt(Profile* profile) { |
| } |
| +void ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
| + if (ShellIntegration::SET_DEFAULT_INTERACTIVE == |
| + ShellIntegration::CanSetAsDefaultBrowser()) { |
| + // If the only available mode of setting the default browser requires |
| + // user interaction, it means this couldn't have been done yet. Perform |
| + // this action as a delayed task (including the check). |
| + SetMetroBrowserFlowLauncher::LaunchSoon(profile); |
| + } |
| +} |
| + |
| namespace internal { |
| void NotifyNotDefaultBrowserCallback() { |