summaryrefslogtreecommitdiffstats
path: root/chrome/browser/first_run
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-04 01:36:00 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-04 01:36:00 +0000
commit43b9517ae28e7c0e3b3b2567e2336c81f38dd392 (patch)
tree44972e2f919c12f6002d7a04bc881898b7b5e7b3 /chrome/browser/first_run
parent2f2db5414a5a7f39f26aaab88f624ecd1e9eeb66 (diff)
downloadchromium_src-43b9517ae28e7c0e3b3b2567e2336c81f38dd392.zip
chromium_src-43b9517ae28e7c0e3b3b2567e2336c81f38dd392.tar.gz
chromium_src-43b9517ae28e7c0e3b3b2567e2336c81f38dd392.tar.bz2
Revise logic to show the first-run bubble at the first appropriate opportunity.
Add static function FirstRunBubbleLauncher::ShowFirstRunBubbleSoon. A FirstRunBubbleLauncher instance acts as a NotificationObserver and manages its own lifetime. Show the bubble on the first NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME when conditions permit. Also, make NTPLoginHandler::HandleLoginMessageSeen set the new NewTabUI::showing_sync_bubble_. The bubble will be delayed if: A) The First-Run Bubble has already been shown. B) The Sync Promo is being shown. C) The NTP Sync Promo Bubble will be shown. D) A Global Error Bubble is pending. Later attempts to show the bubble may succeed. The bubble shows as expected on Win/Mac/Gtk first runs: -When the sync promo is not shown. -On the first new tab/window/navigation ignoring the sync promo. -On clicking "Skip for now" from the sync promo. -On the first new tab/window/navigation after the "Sign in" NTP sync promo bubble. BUG=100299,107005 TEST=Ensure the first-run bubble shows when expected; but not with the sync promo, ntp sign-in sync promo bubble, with global errors, nor ever shown a second time (without the --first-run commandline argument). Review URL: https://chromiumcodereview.appspot.com/9288049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120450 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/first_run')
-rw-r--r--chrome/browser/first_run/first_run.cc70
-rw-r--r--chrome/browser/first_run/first_run.h27
2 files changed, 93 insertions, 4 deletions
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index 2373c05..e07aa19 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -26,13 +26,21 @@
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/shell_integration.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/global_error_service.h"
+#include "chrome/browser/ui/global_error_service_factory.h"
+#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/url_constants.h"
#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/master_preferences_constants.h"
#include "chrome/installer/util/util_constants.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_types.h"
#include "content/public/browser/user_metrics.h"
+#include "content/public/browser/web_contents.h"
#include "googleurl/src/gurl.h"
#if defined(OS_WIN)
@@ -358,7 +366,7 @@ void AutoImportPlatformCommon(
TemplateURLService* template_url =
TemplateURLServiceFactory::GetForProfile(profile);
if (template_url && template_url->GetDefaultSearchProvider())
- SetShowFirstRunBubblePref(true);
+ FirstRunBubbleLauncher::ShowFirstRunBubbleSoon();
SetShowWelcomePagePref();
SetPersonalDataManagerFirstRunPref();
}
@@ -467,6 +475,66 @@ bool SetPersonalDataManagerFirstRunPref() {
return true;
}
+// static
+void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() {
+ SetShowFirstRunBubblePref(true);
+ // This FirstRunBubbleLauncher instance will manage its own lifetime.
+ new FirstRunBubbleLauncher();
+}
+
+FirstRunBubbleLauncher::FirstRunBubbleLauncher() {
+ registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
+ content::NotificationService::AllSources());
+}
+
+FirstRunBubbleLauncher::~FirstRunBubbleLauncher() {}
+
+void FirstRunBubbleLauncher::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
+ Browser* browser = BrowserList::FindBrowserWithWebContents(
+ content::Source<content::WebContents>(source).ptr());
+ if (!browser || !browser->is_type_tabbed())
+ return;
+
+ // Check the preference to determine if the bubble should be shown.
+ PrefService* prefs = g_browser_process->local_state();
+ if (!prefs || !prefs->GetBoolean(prefs::kShouldShowFirstRunBubble)) {
+ delete this;
+ return;
+ }
+
+ content::WebContents* contents = browser->GetSelectedWebContents();
+ if (contents && contents->GetURL().SchemeIs(chrome::kChromeUIScheme)) {
+ // Suppress the first run bubble if the sync promo is showing.
+ if (contents->GetURL().host() == chrome::kChromeUISyncPromoHost)
+ return;
+
+ // Suppress the first run bubble if the NTP sync promo bubble is showing.
+ if (contents->GetURL().host() == chrome::kChromeUINewTabHost) {
+ NewTabUI* new_tab_ui =
+ NewTabUI::FromWebUIController(contents->GetWebUI()->GetController());
+ if (new_tab_ui && new_tab_ui->showing_sync_bubble())
+ return;
+ }
+ }
+
+ // Suppress the first run bubble if a global error bubble is pending.
+ GlobalErrorService* global_error_service =
+ GlobalErrorServiceFactory::GetForProfile(browser->profile());
+ if (global_error_service->GetFirstGlobalErrorWithBubbleView() != NULL)
+ return;
+
+ // Reset the preference and notifications to avoid showing the bubble again.
+ prefs->SetBoolean(prefs::kShouldShowFirstRunBubble, false);
+
+ // Show the bubble now and destroy this bubble launcher.
+ browser->ShowFirstRunBubble();
+ delete this;
+}
+
} // namespace first_run
// FirstRun -------------------------------------------------------------------
diff --git a/chrome/browser/first_run/first_run.h b/chrome/browser/first_run/first_run.h
index 8709bf4..4b6fee4 100644
--- a/chrome/browser/first_run/first_run.h
+++ b/chrome/browser/first_run/first_run.h
@@ -12,16 +12,15 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/native_widget_types.h"
class CommandLine;
class FilePath;
class GURL;
-class ImporterHost;
-class ImporterList;
class Profile;
class ProcessSingleton;
-class TemplateURLService;
namespace installer {
class MasterPreferences;
@@ -105,6 +104,28 @@ int ImportNow(Profile* profile, const CommandLine& cmdline);
// Returns the path for the master preferences file.
FilePath MasterPrefsPath();
+// Show the first run search engine bubble at the first appropriate opportunity.
+// This bubble may be delayed by other UI, like global errors and sync promos.
+class FirstRunBubbleLauncher : public content::NotificationObserver {
+ public:
+ // Show the bubble at the first appropriate opportunity. This function
+ // instantiates a FirstRunBubbleLauncher, which manages its own lifetime.
+ static void ShowFirstRunBubbleSoon();
+
+ private:
+ FirstRunBubbleLauncher();
+ virtual ~FirstRunBubbleLauncher();
+
+ // content::NotificationObserver override:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ content::NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleLauncher);
+};
+
} // namespace first_run
// This class contains the chrome first-run installation actions needed to