Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Unified Diff: chrome/browser/ui/startup/default_browser_prompt.cc

Issue 10539169: Prototype version of the first-run dialog for Windows 8 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed some of reviewer's remarks. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 855b54948f518193be51cae44caea9a1671b362f..35ea7cd6ba7eebf605f540b183c096286fc9388f 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.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,8 @@ bool DefaultBrowserInfoBarDelegate::Accept() {
BrowserThread::PostTask(
BrowserThread::FILE,
FROM_HERE,
- base::Bind(&SetChromeAsDefaultBrowser, interactive_flow_required_));
+ base::Bind(&SetChromeAsDefaultBrowser, interactive_flow_required_,
+ prefs_));
return true;
}
@@ -164,6 +178,64 @@ void CheckDefaultBrowserCallback() {
}
}
+static void CheckDefaultAndShowMetroizerCallback(
+ Profile* profile, Browser* browser, bool dialog) {
grt (UTC plus 2) 2012/06/19 20:43:09 style: each arg goes on its own line if the args d
motek. 2012/06/20 16:02:15 Done. (moved to another file, too).
+ if (!ShellIntegration::IsDefaultBrowser() ||
+ (ShellIntegration::CanSetAsDefaultBrowser() ==
+ ShellIntegration::SET_DEFAULT_INTERACTIVE)) {
+ MetroizerUI::Show(profile, browser, dialog);
+ }
+}
+
+class SetMetroBrowserFlowLauncher : public content::NotificationObserver {
grt (UTC plus 2) 2012/06/19 20:43:09 please document. also, i think class definitions
motek. 2012/06/20 16:02:15 Documented. Placement of the class declaration doe
+ 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());
+
+ if (!browser || !browser->is_type_tabbed())
+ return;
+
+ // Unregister and delete.
+ registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
+ content::NotificationService::AllSources());
+
+ bool as_dialog =
+ profile_->GetPrefs()->GetBoolean(prefs::kDefaultBrowserFlowDialog);
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&CheckDefaultAndShowMetroizerCallback,
+ profile_, browser, as_dialog));
+ delete this;
+}
+
} // namespace
namespace browser {
@@ -196,6 +268,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() {

Powered by Google App Engine
This is Rietveld 408576698