diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/auto_launch_trial.cc | 43 | ||||
-rw-r--r-- | chrome/browser/auto_launch_trial.h | 51 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main.cc | 16 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main.h | 4 | ||||
-rw-r--r-- | chrome/browser/prefs/browser_prefs.cc | 2 | ||||
-rw-r--r-- | chrome/browser/resources/options/browser_options.html | 7 | ||||
-rw-r--r-- | chrome/browser/resources/options/browser_options.js | 26 | ||||
-rw-r--r-- | chrome/browser/ui/browser_init.cc | 159 | ||||
-rw-r--r-- | chrome/browser/ui/browser_init.h | 6 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/browser_options_handler.cc | 73 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/browser_options_handler.h | 22 |
11 files changed, 406 insertions, 3 deletions
diff --git a/chrome/browser/auto_launch_trial.cc b/chrome/browser/auto_launch_trial.cc new file mode 100644 index 0000000..60aa1b2 --- /dev/null +++ b/chrome/browser/auto_launch_trial.cc @@ -0,0 +1,43 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/auto_launch_trial.h" + +#include "base/file_path.h" +#include "base/metrics/field_trial.h" +#include "base/metrics/histogram.h" +#include "chrome/browser/first_run/first_run.h" +#include "chrome/installer/util/master_preferences_constants.h" +#include "chrome/installer/util/master_preferences.h" + +const char kAutoLaunchTrialName[] = "AutoLaunchExperiment"; +const char kAutoLaunchTrialAutoLaunchGroup[] = "AutoLaunching"; +const char kAutoLaunchTrialControlGroup[] = "NotAutoLaunching"; + +namespace auto_launch_trial { + +bool IsInAutoLaunchGroup() { + return base::FieldTrialList::TrialExists(kAutoLaunchTrialName) && + base::FieldTrialList::Find(kAutoLaunchTrialName)->group_name() + == kAutoLaunchTrialAutoLaunchGroup; +} + +void UpdateToggleAutoLaunchMetric(bool auto_launch) { + UMA_HISTOGRAM_ENUMERATION( + base::FieldTrial::MakeName("ToggleAutoLaunch", kAutoLaunchTrialName), + auto_launch ? 1 : 0, 2); +} + +void UpdateInfobarResponseMetric(InfobarMetricResponse response) { + UMA_HISTOGRAM_ENUMERATION( + base::FieldTrial::MakeName("InfobarRepsonse", kAutoLaunchTrialName), + response, 3); +} + +void UpdateInfobarShownMetric() { + UMA_HISTOGRAM_COUNTS( + base::FieldTrial::MakeName("InfobarShown", kAutoLaunchTrialName), 1); +} + +} // namespace auto_launch_trial diff --git a/chrome/browser/auto_launch_trial.h b/chrome/browser/auto_launch_trial.h new file mode 100644 index 0000000..69a3e9d --- /dev/null +++ b/chrome/browser/auto_launch_trial.h @@ -0,0 +1,51 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_AUTO_LAUNCH_TRIAL_H_ +#define CHROME_BROWSER_AUTO_LAUNCH_TRIAL_H_ +#pragma once + +// Strings used with the "auto launching Chrome at computer startup" trial. If +// the field trial is running then... +// base::FieldTrialList::TrialExists(kAutoLaunchTrial_Name) returns true. +// +// The field trial consists of two groups of users: those that auto-launch +// Chrome at startup and those that don't. The group_name() of the field +// trial object is used to determine the group that the user belongs to. +// +// The field trial is setup in ChromeBrowserMainParts::AutoLaunchFieldTrial() +// based on the user's brand code: +// +// - brand RNGP auto launches Chrome on computer startup. +// - brand RNGQ does not. +// - any other brand code does whatever comes natural to it. + +extern const char kAutoLaunchTrialName[]; +extern const char kAutoLaunchTrialAutoLaunchGroup[]; +extern const char kAutoLaunchTrialControlGroup[]; + +namespace auto_launch_trial { + +// The possible responses for the auto-launch infobar. +enum InfobarMetricResponse { + INFOBAR_CUT_IT_OUT = 0, + INFOBAR_OK, + INFOBAR_IGNORE, +}; + +// Whether the auto-launch experiment is active and the user is part of it. +bool IsInAutoLaunchGroup(); + +// Updates UMA to reflect user changing the auto-launch setting. +void UpdateToggleAutoLaunchMetric(bool auto_launch); + +// Updates UMA to reflect user responses to the infobar. +void UpdateInfobarResponseMetric(InfobarMetricResponse response); + +// Updates UMA to reflect that the infobar has been shown. +void UpdateInfobarShownMetric(); + +} // namespace auto_launch_trial + +#endif // CHROME_BROWSER_AUTO_LAUNCH_TRIAL_H_ diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index ad900d6..3898f57 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -29,6 +29,7 @@ #include "base/values.h" #include "build/build_config.h" #include "chrome/browser/about_flags.h" +#include "chrome/browser/auto_launch_trial.h" #include "chrome/browser/background/background_mode_manager.h" #include "chrome/browser/browser_process_impl.h" #include "chrome/browser/browser_shutdown.h" @@ -1113,6 +1114,20 @@ void ChromeBrowserMainParts::DefaultAppsFieldTrial() { } } +void ChromeBrowserMainParts::AutoLaunchChromeFieldTrial() { + std::string brand; + google_util::GetBrand(&brand); + + // Create a 100% field trial based on the brand code. + if (LowerCaseEqualsASCII(brand, "rngp")) { + base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName, + kAutoLaunchTrialAutoLaunchGroup); + } else if (LowerCaseEqualsASCII(brand, "rngq")) { + base::FieldTrialList::CreateFieldTrial(kAutoLaunchTrialName, + kAutoLaunchTrialControlGroup); + } +} + // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- // Initializes the metrics service with the configuration for this process, @@ -1173,6 +1188,7 @@ void ChromeBrowserMainParts::SetupFieldTrials(bool metrics_recording_enabled, WarmConnectionFieldTrial(); PredictorFieldTrial(); DefaultAppsFieldTrial(); + AutoLaunchChromeFieldTrial(); sync_promo_trial::Activate(); } diff --git a/chrome/browser/chrome_browser_main.h b/chrome/browser/chrome_browser_main.h index 26f22a6..491f5d3 100644 --- a/chrome/browser/chrome_browser_main.h +++ b/chrome/browser/chrome_browser_main.h @@ -113,6 +113,10 @@ class ChromeBrowserMainParts : public content::BrowserMainParts { // has on retention and general apps/webstore usage. void DefaultAppsFieldTrial(); + // A field trial to see what effects launching Chrome automatically on + // computer startup has on retention and usage of Chrome. + void AutoLaunchChromeFieldTrial(); + // Methods for |SetupMetricsAndFieldTrials()| -------------------------------- // Constructs metrics service and does related initialization, including diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 9b4a6b3..b113259 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -52,6 +52,7 @@ #include "chrome/browser/translate/translate_prefs.h" #include "chrome/browser/ui/alternate_error_tab_observer.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_init.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" #include "chrome/browser/ui/webui/flags_ui.h" @@ -153,6 +154,7 @@ void RegisterUserPrefs(PrefService* user_prefs) { SessionStartupPref::RegisterUserPrefs(user_prefs); BookmarkModel::RegisterUserPrefs(user_prefs); Browser::RegisterUserPrefs(user_prefs); + BrowserInit::RegisterUserPrefs(user_prefs); PasswordManager::RegisterUserPrefs(user_prefs); chrome_browser_net::Predictor::RegisterUserPrefs(user_prefs); DownloadPrefs::RegisterUserPrefs(user_prefs); diff --git a/chrome/browser/resources/options/browser_options.html b/chrome/browser/resources/options/browser_options.html index 2af7b17..4d06327 100644 --- a/chrome/browser/resources/options/browser_options.html +++ b/chrome/browser/resources/options/browser_options.html @@ -121,6 +121,13 @@ i18n-content="defaultBrowserUseAsDefault"></button> <div id="defaultBrowserState" i18n-content="defaultBrowserUnknown"></div> + <div id="autoLaunchOption" class="checkbox" hidden> + <label> + <input id="autoLaunch" type="checkbox"> + <span i18n-content="autoLaunchText"></span> + </input> + </label> + </div> </div> </section> </if> diff --git a/chrome/browser/resources/options/browser_options.js b/chrome/browser/resources/options/browser_options.js index ba59d3d..294bb9d 100644 --- a/chrome/browser/resources/options/browser_options.js +++ b/chrome/browser/resources/options/browser_options.js @@ -113,6 +113,9 @@ cr.define('options', function() { $('defaultBrowserUseAsDefaultButton').onclick = function(event) { chrome.send('becomeDefaultBrowser'); }; + + $('autoLaunch').addEventListener('click', + this.handleAutoLaunchChanged_); } var startupPagesList = $('startupPagesList'); @@ -282,7 +285,7 @@ cr.define('options', function() { }, /** - * Handle change events of the preference + * Handles change events of the preference * 'session.urls_to_restore_on_startup'. * @param {event} preference changed event. * @private @@ -293,7 +296,7 @@ cr.define('options', function() { }, /** - * Set the default search engine based on the popup selection. + * Sets the default search engine based on the popup selection. */ setDefaultSearchEngine_: function() { var engineSelect = $('defaultSearchEngine'); @@ -305,6 +308,13 @@ cr.define('options', function() { }, /** + * Sets or clear whether Chrome should Auto-launch on computer startup. + */ + handleAutoLaunchChanged_: function() { + chrome.send('toggleAutoLaunch', [Boolean($('autoLaunch').checked)]); + }, + + /** * Sends an asynchronous request for new autocompletion suggestions for the * the given query. When new suggestions are available, the C++ handler will * call updateAutocompleteSuggestions_. @@ -329,6 +339,14 @@ cr.define('options', function() { return; list.suggestions = suggestions; }, + + /** + * Shows the autoLaunch preference and initializes its checkbox value. + */ + updateAutoLaunchState_: function(enabled) { + $('autoLaunchOption').hidden = false; + $('autoLaunch').checked = enabled; + }, }; BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, @@ -354,6 +372,10 @@ cr.define('options', function() { BrowserOptions.getInstance().updateAutocompleteSuggestions_(suggestions); }; + BrowserOptions.updateAutoLaunchState = function(enabled) { + BrowserOptions.getInstance().updateAutoLaunchState_(enabled); + }; + BrowserOptions.setInstantFieldTrialStatus = function(enabled) { BrowserOptions.getInstance().setInstantFieldTrialStatus_(enabled); }; diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index a6555eb..23c05e1 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -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" @@ -116,10 +117,127 @@ #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: + AutolaunchInfoBarDelegate(InfoBarTabHelper* infobar_helper, + PrefService* prefs); + virtual ~AutolaunchInfoBarDelegate(); + + private: + 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. + base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_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(weak_factory_(this)) { + 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, + base::Bind(&AutolaunchInfoBarDelegate::AllowExpiry, + weak_factory_.GetWeakPtr()), + 8000); // 8 seconds. +} + +AutolaunchInfoBarDelegate::~AutolaunchInfoBarDelegate() { + if (!action_taken_) { + auto_launch_trial::UpdateInfobarResponseMetric( + auto_launch_trial::INFOBAR_IGNORE); + } +} + +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( + auto_launch_trial::INFOBAR_OK); + return true; +} + +bool AutolaunchInfoBarDelegate::Cancel() { + action_taken_ = true; + + // Track infobar reponse. + auto_launch_trial::UpdateInfobarResponseMetric( + auto_launch_trial::INFOBAR_CUT_IT_OUT); + // Also make sure we keep track of how many disable and how many enable. + const bool auto_launch = false; + auto_launch_trial::UpdateToggleAutoLaunchMetric(auto_launch); + + content::BrowserThread::PostTask( + content::BrowserThread::FILE, FROM_HERE, + base::Bind(&auto_launch_util::SetWillLaunchAtLogin, + auto_launch, FilePath())); + return true; +} + +#endif // OS_WIN + // DefaultBrowserInfoBarDelegate ---------------------------------------------- // The delegate for the infobar shown when Chrome is not the default browser. @@ -223,6 +341,26 @@ bool DefaultBrowserInfoBarDelegate::Cancel() { return true; } +#if defined(OS_WIN) +void CheckAutoLaunchCallback() { + 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 + void NotifyNotDefaultBrowserCallback() { Browser* browser = BrowserList::GetLastActive(); if (!browser) @@ -517,6 +655,12 @@ bool BrowserInit::InProcessStartup() { 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, @@ -699,6 +843,8 @@ bool BrowserInit::LaunchWithProfile::Launch( if (process_startup) { if (browser_defaults::kOSSupportsOtherBrowsers && !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { + CheckIfAutoLaunched(profile); + // Check whether we are the default browser. CheckDefaultBrowser(profile); } @@ -1309,6 +1455,19 @@ void BrowserInit::LaunchWithProfile::CheckDefaultBrowser(Profile* profile) { BrowserThread::FILE, FROM_HERE, base::Bind(&CheckDefaultBrowserCallback)); } +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, + base::Bind(&CheckAutoLaunchCallback)); + } +#endif +} + std::vector<GURL> BrowserInit::GetURLsFromCommandLine( const CommandLine& command_line, const FilePath& cur_dir, diff --git a/chrome/browser/ui/browser_init.h b/chrome/browser/ui/browser_init.h index 9e2ebfc..7d5a332 100644 --- a/chrome/browser/ui/browser_init.h +++ b/chrome/browser/ui/browser_init.h @@ -18,6 +18,7 @@ class Browser; class CommandLine; class GURL; +class PrefService; class TabContentsWrapper; // class containing helpers for BrowserMain to spin up a new instance and @@ -62,6 +63,8 @@ class BrowserInit { // Returns true if the browser is coming up. static bool InProcessStartup(); + static void RegisterUserPrefs(PrefService* prefs); + // Launches a browser window associated with |profile|. |command_line| should // be the command line passed to this process. |cur_dir| can be empty, which // implies that the directory of the executable should be used. @@ -224,6 +227,9 @@ class BrowserInit { // previously instructed not to do so) and warns the user if it is not. void CheckDefaultBrowser(Profile* profile); + // Checks whether Chrome was auto-started at login. + void CheckIfAutoLaunched(Profile* profile); + const FilePath cur_dir_; const CommandLine& command_line_; Profile* profile_; diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc index 3546734..653efbd 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.cc +++ b/chrome/browser/ui/webui/options/browser_options_handler.cc @@ -8,9 +8,11 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/memory/singleton.h" +#include "base/path_service.h" #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/auto_launch_trial.h" #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/browser_process.h" @@ -37,10 +39,18 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" +#if defined(OS_WIN) +#include "chrome/installer/util/auto_launch_util.h" +#endif + +using content::BrowserThread; using content::UserMetricsAction; BrowserOptionsHandler::BrowserOptionsHandler() - : template_url_service_(NULL), startup_custom_pages_table_model_(NULL) { + : template_url_service_(NULL), + startup_custom_pages_table_model_(NULL), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_file_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_ui_(this)) { #if !defined(OS_MACOSX) default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); #endif @@ -92,6 +102,9 @@ void BrowserOptionsHandler::GetLocalizedValues( localized_strings->SetString("defaultBrowserUseAsDefault", l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); + localized_strings->SetString("autoLaunchText", + l10n_util::GetStringFUTF16(IDS_AUTOLAUNCH_TEXT, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); } void BrowserOptionsHandler::RegisterMessages() { @@ -154,6 +167,47 @@ void BrowserOptionsHandler::Initialize() { UpdateSearchEngines(); autocomplete_controller_.reset(new AutocompleteController(profile, this)); + +#if defined(OS_WIN) + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, + base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, + weak_ptr_factory_for_ui_.GetWeakPtr(), + weak_ptr_factory_for_file_.GetWeakPtr())); + weak_ptr_factory_for_ui_.DetachFromThread(); +#endif +} + +void BrowserOptionsHandler::CheckAutoLaunch( + base::WeakPtr<BrowserOptionsHandler> weak_this) { +#if defined(OS_WIN) + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); + + // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is + // deleted. + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, + weak_this, + auto_launch_trial::IsInAutoLaunchGroup(), + auto_launch_util::WillLaunchAtLogin(FilePath()))); +#endif +} + +void BrowserOptionsHandler::CheckAutoLaunchCallback( + bool is_in_auto_launch_group, + bool will_launch_at_login) { +#if defined(OS_WIN) + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + if (is_in_auto_launch_group) { + web_ui_->RegisterMessageCallback("toggleAutoLaunch", + base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, + base::Unretained(this))); + + base::FundamentalValue enabled(will_launch_at_login); + web_ui_->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", + enabled); + } +#endif } void BrowserOptionsHandler::UpdateDefaultBrowserState() { @@ -463,6 +517,23 @@ void BrowserOptionsHandler::DisableInstant(const ListValue* args) { InstantController::Disable(Profile::FromWebUI(web_ui_)); } +void BrowserOptionsHandler::ToggleAutoLaunch(const ListValue* args) { +#if defined(OS_WIN) + if (!auto_launch_trial::IsInAutoLaunchGroup()) + return; + + bool enable; + CHECK_EQ(args->GetSize(), 1U); + CHECK(args->GetBoolean(0, &enable)); + + // Make sure we keep track of how many disable and how many enable. + auto_launch_trial::UpdateToggleAutoLaunchMetric(enable); + content::BrowserThread::PostTask( + content::BrowserThread::FILE, FROM_HERE, + base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable, FilePath())); +#endif // OS_WIN +} + void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { Profile* profile = Profile::FromWebUI(web_ui_); base::FundamentalValue enabled( diff --git a/chrome/browser/ui/webui/options/browser_options_handler.h b/chrome/browser/ui/webui/options/browser_options_handler.h index 44aec51..ce64322 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.h +++ b/chrome/browser/ui/webui/options/browser_options_handler.h @@ -8,6 +8,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" #include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/prefs/pref_member.h" @@ -89,6 +90,22 @@ class BrowserOptionsHandler : public OptionsPageUIHandler, void EnableInstant(const ListValue* args); void DisableInstant(const ListValue* args); + // Enables/disables auto-launching of Chrome on computer startup. + void ToggleAutoLaunch(const ListValue* args); + + // Checks (on the file thread) whether the user is in the auto-launch trial + // and whether Chrome is set to auto-launch at login. Gets a reply on the UI + // thread (see CheckAutoLaunchCallback). A weak pointer to this is passed in + // as a parameter to avoid the need to lock between this function and the + // destructor. + + void CheckAutoLaunch(base::WeakPtr<BrowserOptionsHandler> weak_this); + // Sets up (on the UI thread) the necessary bindings for toggling auto-launch + // (if the user is part of the auto-launch and makes sure the HTML UI knows + // whether Chrome will auto-launch at login. + void CheckAutoLaunchCallback(bool is_in_auto_launch_group, + bool will_launch_at_login); + // Called to request information about the Instant field trial. void GetInstantFieldTrialStatus(const ListValue* args); @@ -130,6 +147,11 @@ class BrowserOptionsHandler : public OptionsPageUIHandler, scoped_ptr<AutocompleteController> autocomplete_controller_; + // Used to get |weak_ptr_| to self for use on the File thread. + base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_for_file_; + // Used to post update tasks to the UI thread. + base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_for_ui_; + DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler); }; |