summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormacourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-11 00:14:36 +0000
committermacourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-11 00:14:36 +0000
commitdafa6d040771e819abe6a70b545634a7f85d93a4 (patch)
tree73f223ea594957ac00ffe8d69ad421948c5dafdb
parent5ea712290906d29201f443194b4f3715a8c36592 (diff)
downloadchromium_src-dafa6d040771e819abe6a70b545634a7f85d93a4.zip
chromium_src-dafa6d040771e819abe6a70b545634a7f85d93a4.tar.gz
chromium_src-dafa6d040771e819abe6a70b545634a7f85d93a4.tar.bz2
Add a short delay before showing the first run bubble.
R=grt@chromium.org BUG=223939 Review URL: https://chromiumcodereview.appspot.com/13958003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193513 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/first_run/first_run.cc41
-rw-r--r--chrome/browser/first_run/first_run.h14
2 files changed, 51 insertions, 4 deletions
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index 255a6da..d93d65a 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -10,10 +10,12 @@
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/lazy_instance.h"
+#include "base/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/stringprintf.h"
+#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
@@ -35,6 +37,7 @@
#include "chrome/browser/shell_integration.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/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
@@ -61,6 +64,9 @@ using content::UserMetricsAction;
namespace {
+// How long to delay showing the first run bubble (in milliseconds).
+const int kFirstRunBubbleDelayMs = 200;
+
// Flags for functions of similar name.
bool should_show_welcome_page_ = false;
bool should_do_autofill_personal_data_manager_first_run_ = false;
@@ -512,12 +518,16 @@ void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() {
new FirstRunBubbleLauncher();
}
-FirstRunBubbleLauncher::FirstRunBubbleLauncher() {
+FirstRunBubbleLauncher::FirstRunBubbleLauncher()
+ : browser_(NULL) {
+ BrowserList::AddObserver(this);
registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
}
-FirstRunBubbleLauncher::~FirstRunBubbleLauncher() {}
+FirstRunBubbleLauncher::~FirstRunBubbleLauncher() {
+ BrowserList::RemoveObserver(this);
+}
void FirstRunBubbleLauncher::Observe(
int type,
@@ -570,12 +580,37 @@ void FirstRunBubbleLauncher::Observe(
if (global_error_service->GetFirstGlobalErrorWithBubbleView() != NULL)
return;
+ // Make sure we don't get notified again after resetting the
+ // kShowFirstRunBubbleOption preference below.
+ registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
+ content::NotificationService::AllSources());
+
// Reset the preference and notifications to avoid showing the bubble again.
prefs->SetInteger(prefs::kShowFirstRunBubbleOption,
FIRST_RUN_BUBBLE_DONT_SHOW);
+ // Show the bubble soon.
+ browser_ = browser;
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(
+ &FirstRunBubbleLauncher::DoShowFirstRunBubble,
+ AsWeakPtr()),
+ base::TimeDelta::FromMilliseconds(kFirstRunBubbleDelayMs));
+}
+
+void FirstRunBubbleLauncher::OnBrowserRemoved(Browser* browser) {
+ if (browser_ == browser) {
+ // Destroy this bubble launcher.
+ delete this;
+ }
+}
+
+void FirstRunBubbleLauncher::DoShowFirstRunBubble() {
+ DCHECK(browser_);
+
// Show the bubble now and destroy this bubble launcher.
- browser->ShowFirstRunBubble();
+ browser_->ShowFirstRunBubble();
delete this;
}
diff --git a/chrome/browser/first_run/first_run.h b/chrome/browser/first_run/first_run.h
index 2bebc46..8a40375 100644
--- a/chrome/browser/first_run/first_run.h
+++ b/chrome/browser/first_run/first_run.h
@@ -12,10 +12,13 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/native_widget_types.h"
+class Browser;
class CommandLine;
class GURL;
class PrefRegistrySyncable;
@@ -184,7 +187,10 @@ ProcessMasterPreferencesResult ProcessMasterPreferences(
// 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 {
+class FirstRunBubbleLauncher
+ : public content::NotificationObserver,
+ public chrome::BrowserListObserver,
+ public base::SupportsWeakPtr<FirstRunBubbleLauncher> {
public:
// Show the bubble at the first appropriate opportunity. This function
// instantiates a FirstRunBubbleLauncher, which manages its own lifetime.
@@ -199,7 +205,13 @@ class FirstRunBubbleLauncher : public content::NotificationObserver {
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
+ // chrome::BrowserListObserver override:
+ virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
+
+ void DoShowFirstRunBubble();
+
content::NotificationRegistrar registrar_;
+ Browser* browser_;
DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleLauncher);
};