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

Unified Diff: chrome/browser/ui/browser_init.cc

Issue 8729009: Implement an AutoLaunch experiment for Chrome for certain brand codes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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/browser_init.cc
===================================================================
--- chrome/browser/ui/browser_init.cc (revision 111708)
+++ chrome/browser/ui/browser_init.cc (working copy)
@@ -20,6 +20,7 @@
#include "base/string_split.h"
#include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/auto_launch_trial.h"
#include "chrome/browser/automation/automation_provider.h"
#include "chrome/browser/automation/automation_provider_list.h"
#include "chrome/browser/automation/chrome_frame_automation_provider.h"
@@ -113,10 +114,122 @@
#include "ui/base/touch/touch_factory.h"
#endif
+#if defined(OS_WIN)
+#include "chrome/installer/util/auto_launch_util.h"
+#endif
+
using content::BrowserThread;
namespace {
+static const int kMaxInfobarShown = 5;
+
+#if defined(OS_WIN)
+// The delegate for the infobar shown when Chrome was auto-launched.
+class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate {
+ public:
+ explicit AutolaunchInfoBarDelegate(InfoBarTabHelper* infobar_helper,
grt (UTC plus 2) 2011/11/29 18:55:45 remove "explicit"
+ PrefService* prefs);
+
+ private:
+ virtual ~AutolaunchInfoBarDelegate();
grt (UTC plus 2) 2011/11/29 18:55:45 why private dtor?
Finnur 2011/11/29 23:48:30 Hmm... I don't have a good reason besides the othe
+
+ void AllowExpiry() { should_expire_ = true; }
+
+ // ConfirmInfoBarDelegate:
+ virtual bool ShouldExpire(
+ const content::LoadCommittedDetails& details) const OVERRIDE;
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
+
+ // The prefs to use.
+ PrefService* prefs_;
+
+ // Whether the user clicked one of the buttons.
+ bool action_taken_;
+
+ // Whether the info-bar should be dismissed on the next navigation.
+ bool should_expire_;
+
+ // Used to delay the expiration of the info-bar.
+ ScopedRunnableMethodFactory<AutolaunchInfoBarDelegate> method_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate);
+};
+
+AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate(
+ InfoBarTabHelper* infobar_helper,
+ PrefService* prefs)
+ : ConfirmInfoBarDelegate(infobar_helper),
+ prefs_(prefs),
+ action_taken_(false),
+ should_expire_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
grt (UTC plus 2) 2011/11/29 18:55:45 indent?
+ auto_launch_trial::UpdateInfobarShownMetric();
+
+ int count = prefs_->GetInteger(prefs::kShownAutoLaunchInfobar);
+ prefs_->SetInteger(prefs::kShownAutoLaunchInfobar, count + 1);
+
+ // We want the info-bar to stick-around for a few seconds and then be hidden
+ // on the next navigation after that.
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &AutolaunchInfoBarDelegate::AllowExpiry), 8000); // 8 seconds.
+}
+
+AutolaunchInfoBarDelegate::~AutolaunchInfoBarDelegate() {
+ if (!action_taken_)
+ auto_launch_trial::UpdateInfobarResponseMetric(2);
+}
+
+bool AutolaunchInfoBarDelegate::ShouldExpire(
+ const content::LoadCommittedDetails& details) const {
+ return details.is_navigation_to_different_page() && should_expire_;
+}
+
+gfx::Image* AutolaunchInfoBarDelegate::GetIcon() const {
+ return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
+ IDR_PRODUCT_LOGO_32);
+}
+
+string16 AutolaunchInfoBarDelegate::GetMessageText() const {
+ return l10n_util::GetStringFUTF16(IDS_AUTO_LAUNCH_INFOBAR_TEXT,
+ l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
+}
+
+string16 AutolaunchInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
+ IDS_AUTO_LAUNCH_OK : IDS_AUTO_LAUNCH_REVERT);
+}
+
+bool AutolaunchInfoBarDelegate::Accept() {
+ action_taken_ = true;
+ auto_launch_trial::UpdateInfobarResponseMetric(1);
+ return true;
+}
+
+bool AutolaunchInfoBarDelegate::Cancel() {
+ action_taken_ = true;
+
+ // Track infobar reponse.
+ auto_launch_trial::UpdateInfobarResponseMetric(0);
+ // Also make sure we keep track of how many disable and how many enable.
+ bool auto_launch = false;
+ auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch);
+
+ FilePath chrome_exe;
+ if (!PathService::Get(base::DIR_EXE, &chrome_exe))
+ NOTREACHED();
+ auto_launch_util::SetIsAutoLaunched(auto_launch, chrome_exe);
+
+ return true;
+}
+#endif // OS_WIN
+
// DefaultBrowserInfoBarDelegate ----------------------------------------------
// The delegate for the infobar shown when Chrome is not the default browser.
@@ -219,7 +332,44 @@
return true;
}
+// NotifyAutolaunchTask ------------------------------------------------
+#if defined(OS_WIN)
+class NotifyAutolaunchTask : public Task {
+ public:
+ NotifyAutolaunchTask();
+ virtual ~NotifyAutolaunchTask();
+ private:
+ virtual void Run();
grt (UTC plus 2) 2011/11/29 18:55:45 OVERRIDE
+
+ DISALLOW_COPY_AND_ASSIGN(NotifyAutolaunchTask);
+};
+
+NotifyAutolaunchTask::NotifyAutolaunchTask() {
+}
+
+NotifyAutolaunchTask::~NotifyAutolaunchTask() {
+}
+
+void NotifyAutolaunchTask::Run() {
+ if (!auto_launch_trial::IsInAutoLaunchGroup())
+ return;
+
+ Browser* browser = BrowserList::GetLastActive();
+ TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper();
+
+ int infobar_shown =
+ tab->profile()->GetPrefs()->GetInteger(prefs::kShownAutoLaunchInfobar);
+ if (infobar_shown >= kMaxInfobarShown)
+ return;
+
+ InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
+ infobar_helper->AddInfoBar(
+ new AutolaunchInfoBarDelegate(infobar_helper,
+ tab->profile()->GetPrefs()));
+}
+#endif // OS_WIN
+
// NotifyNotDefaultBrowserTask ------------------------------------------------
class NotifyNotDefaultBrowserTask : public Task {
@@ -546,6 +696,12 @@
return in_startup;
}
+// static
+void BrowserInit::RegisterUserPrefs(PrefService* prefs) {
+ prefs->RegisterIntegerPref(
+ prefs::kShownAutoLaunchInfobar, 0, PrefService::UNSYNCABLE_PREF);
+}
+
bool BrowserInit::LaunchBrowser(const CommandLine& command_line,
Profile* profile,
const FilePath& cur_dir,
@@ -709,6 +865,7 @@
// Check whether we are the default browser.
CheckDefaultBrowser(profile);
}
+ CheckIfAutoLaunched(profile);
#if defined(OS_MACOSX)
// Check whether the auto-update system needs to be promoted from user
// to system.
@@ -1316,6 +1473,19 @@
BrowserThread::FILE, FROM_HERE, new CheckDefaultBrowserTask());
}
+void BrowserInit::LaunchWithProfile::CheckIfAutoLaunched(Profile* profile) {
+#if defined(OS_WIN)
+ if (!auto_launch_trial::IsInAutoLaunchGroup())
+ return;
+
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ if (command_line.HasSwitch(switches::kAutoLaunchAtStartup)) {
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ new NotifyAutolaunchTask());
+ }
+#endif
+}
+
std::vector<GURL> BrowserInit::GetURLsFromCommandLine(
const CommandLine& command_line,
const FilePath& cur_dir,

Powered by Google App Engine
This is Rietveld 408576698