summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/webui/options2/browser_options_handler.cc73
-rw-r--r--chrome/browser/ui/webui/options2/browser_options_handler.h22
2 files changed, 94 insertions, 1 deletions
diff --git a/chrome/browser/ui/webui/options2/browser_options_handler.cc b/chrome/browser/ui/webui/options2/browser_options_handler.cc
index 205512c..9efc06e 100644
--- a/chrome/browser/ui/webui/options2/browser_options_handler.cc
+++ b/chrome/browser/ui/webui/options2/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/options2/browser_options_handler.h b/chrome/browser/ui/webui/options2/browser_options_handler.h
index 894620a..18f1ddb 100644
--- a/chrome/browser/ui/webui/options2/browser_options_handler.h
+++ b/chrome/browser/ui/webui/options2/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 OptionsPage2UIHandler,
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 OptionsPage2UIHandler,
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);
};