summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-04 01:53:07 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-04 01:53:07 +0000
commitca87af8d86675f09d36d34c70ebbe2689ba8c183 (patch)
treed15dfd16e00e81c768b53f07512853ce9b90f41d
parent37f20cf70515a6cdf930f0ed64a2aa16feb2df53 (diff)
downloadchromium_src-ca87af8d86675f09d36d34c70ebbe2689ba8c183.zip
chromium_src-ca87af8d86675f09d36d34c70ebbe2689ba8c183.tar.gz
chromium_src-ca87af8d86675f09d36d34c70ebbe2689ba8c183.tar.bz2
Merge 120450 - 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 TBR=msw@chromium.org Review URL: https://chromiumcodereview.appspot.com/9317106 git-svn-id: svn://svn.chromium.org/chrome/branches/1025/src@120452 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/first_run/first_run.cc70
-rw-r--r--chrome/browser/first_run/first_run.h27
-rw-r--r--chrome/browser/ui/browser.cc50
-rw-r--r--chrome/browser/ui/browser.h3
-rw-r--r--chrome/browser/ui/webui/ntp/new_tab_ui.cc3
-rw-r--r--chrome/browser/ui/webui/ntp/new_tab_ui.h6
-rw-r--r--chrome/browser/ui/webui/ntp/ntp_login_handler.cc3
7 files changed, 128 insertions, 34 deletions
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index 0da49ea..249c9b7 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)
@@ -329,7 +337,7 @@ void AutoImportPlatformCommon(
TemplateURLService* template_url =
TemplateURLServiceFactory::GetForProfile(profile);
if (template_url && template_url->GetDefaultSearchProvider())
- SetShowFirstRunBubblePref(true);
+ FirstRunBubbleLauncher::ShowFirstRunBubbleSoon();
SetShowWelcomePagePref();
SetPersonalDataManagerFirstRunPref();
}
@@ -423,6 +431,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 e9d6ea4..56f48f9 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;
// TODO(jennyz): All FirstRun class code will be refactored to first_run
// namespace progressively with several changelists to be landed. Therefore,
@@ -101,6 +100,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
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index f1198fc..103bf8d 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -4439,6 +4439,27 @@ gfx::Rect Browser::GetInstantBounds() {
return window()->GetInstantBounds();
}
+void Browser::OnWindowDidShow() {
+ if (window_has_shown_)
+ return;
+ window_has_shown_ = true;
+
+ // Nothing to do for non-tabbed windows.
+ if (!is_type_tabbed())
+ return;
+
+ // Show any pending global error bubble.
+ GlobalErrorService* service =
+ GlobalErrorServiceFactory::GetForProfile(profile());
+ GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
+ if (error)
+ error->ShowBubbleView(this);
+}
+
+void Browser::ShowFirstRunBubble() {
+ window()->GetLocationBar()->ShowFirstRunBubble();
+}
+
///////////////////////////////////////////////////////////////////////////////
// Browser, protected:
@@ -5471,32 +5492,3 @@ void Browser::ShowSyncSetup() {
void Browser::ToggleSpeechInput() {
GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput();
}
-
-void Browser::OnWindowDidShow() {
- if (window_has_shown_)
- return;
- window_has_shown_ = true;
-
- // Nothing to do for non-tabbed windows.
- if (!is_type_tabbed())
- return;
-
- // Suppress the first run bubble if we're showing the sync promo.
- WebContents* contents = GetSelectedWebContents();
- bool is_showing_promo = contents &&
- contents->GetURL().SchemeIs(chrome::kChromeUIScheme) &&
- contents->GetURL().host() == chrome::kChromeUISyncPromoHost;
- PrefService* local_state = g_browser_process->local_state();
- if (!is_showing_promo && local_state &&
- local_state->GetBoolean(prefs::kShouldShowFirstRunBubble)) {
- // Reset the preference to avoid showing the bubble for subsequent windows.
- local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, false);
- window_->GetLocationBar()->ShowFirstRunBubble();
- } else {
- GlobalErrorService* service =
- GlobalErrorServiceFactory::GetForProfile(profile());
- GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
- if (error)
- error->ShowBubbleView(this);
- }
-}
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index 89151e2..c258aa6 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -860,6 +860,9 @@ class Browser : public TabHandlerDelegate,
// Called each time the browser window is shown.
void OnWindowDidShow();
+ // Show the first run search engine bubble on the location bar.
+ void ShowFirstRunBubble();
+
protected:
// Wrapper for the factory method in BrowserWindow. This allows subclasses to
// set their own window.
diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
index 1e32af4..452880e 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc
+++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
@@ -81,7 +81,8 @@ const char kWebStoreLinkExperiment[] = "WebStoreLinkExperiment";
// NewTabUI
NewTabUI::NewTabUI(content::WebUI* web_ui)
- : WebUIController(web_ui) {
+ : WebUIController(web_ui),
+ showing_sync_bubble_(false) {
g_live_new_tabs.Pointer()->insert(this);
// Override some options on the Web UI.
web_ui->HideFavicon();
diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.h b/chrome/browser/ui/webui/ntp/new_tab_ui.h
index b940284..be6e847 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_ui.h
+++ b/chrome/browser/ui/webui/ntp/new_tab_ui.h
@@ -58,6 +58,9 @@ class NewTabUI : public content::WebUIController,
// from the location bar.
bool CanShowBookmarkBar() const;
+ bool showing_sync_bubble() { return showing_sync_bubble_; }
+ void set_showing_sync_bubble(bool showing) { showing_sync_bubble_ = showing; }
+
class NewTabHTMLSource : public ChromeURLDataManager::DataSource {
public:
explicit NewTabHTMLSource(Profile* profile);
@@ -107,6 +110,9 @@ class NewTabUI : public content::WebUIController,
// The preference version. This used for migrating prefs of the NTP.
static const int current_pref_version_ = 3;
+ // If the sync promo NTP bubble is being shown.
+ bool showing_sync_bubble_;
+
DISALLOW_COPY_AND_ASSIGN(NewTabUI);
};
diff --git a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
index 76ff9ae..d432c3b 100644
--- a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
+++ b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc
@@ -25,6 +25,7 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
#include "chrome/browser/ui/webui/web_ui_util.h"
#include "chrome/browser/web_resource/promo_resource_service.h"
@@ -171,6 +172,8 @@ void NTPLoginHandler::RecordInHistogram(int type) {
void NTPLoginHandler::HandleLoginMessageSeen(const ListValue* args) {
Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(
prefs::kSyncPromoShowNTPBubble, false);
+ NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController());
+ ntp_ui->set_showing_sync_bubble(true);
}
void NTPLoginHandler::HandleShowAdvancedLoginUI(const ListValue* args) {