diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-15 10:45:32 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-15 10:45:32 +0000 |
commit | 0cba296108328045bad62e2286f5ec6a2e4fd7e8 (patch) | |
tree | 5d60490adfbb0d68f62e51809551b6cfb6e19063 /chrome/installer | |
parent | e69786054d76d7a8cc2a15536597b2ffb248afde (diff) | |
download | chromium_src-0cba296108328045bad62e2286f5ec6a2e4fd7e8.zip chromium_src-0cba296108328045bad62e2286f5ec6a2e4fd7e8.tar.gz chromium_src-0cba296108328045bad62e2286f5ec6a2e4fd7e8.tar.bz2 |
Implement an AutoLaunch experiment for Chrome for certain brand codes. This is for Windows only.
BUG=95971
TEST=This requires a special branded build to test (and master_preferences set to have auto_launch_chrome: true or specify mini_installer param --auto-launch-chrome), but after installing it you should see an item under the Wrench \ Options \ Basics that lets you configure Chrome to not auto-launch. If you instead, log out and log in again, Chrome should start with an infobar saying that it was auto-launched. The infobar should stay for a max of 5 launches and then not appear again. Pressing "Cut it out!" on the infobar should turn off this feature. If you just want to test the infobar, launch chrome with --auto-launch-at-startup. Also, uninstall and make sure Chrome is not auto-launched (a Windows error about Chrome not being found should not be shown).
Review URL: http://codereview.chromium.org/8729009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114621 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r-- | chrome/installer/setup/install.cc | 15 | ||||
-rw-r--r-- | chrome/installer/setup/uninstall.cc | 7 | ||||
-rw-r--r-- | chrome/installer/util/auto_launch_util.cc | 64 | ||||
-rw-r--r-- | chrome/installer/util/auto_launch_util.h | 31 | ||||
-rw-r--r-- | chrome/installer/util/install_util.cc | 7 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.cc | 2 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.h | 1 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences_constants.cc | 3 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences_constants.h | 7 | ||||
-rw-r--r-- | chrome/installer/util/util_constants.cc | 3 | ||||
-rw-r--r-- | chrome/installer/util/util_constants.h | 9 |
11 files changed, 141 insertions, 8 deletions
diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc index 0fa8859..464e69c 100644 --- a/chrome/installer/setup/install.cc +++ b/chrome/installer/setup/install.cc @@ -18,6 +18,7 @@ #include "base/utf_string_conversions.h" #include "chrome/installer/setup/setup_constants.h" #include "chrome/installer/setup/install_worker.h" +#include "chrome/installer/util/auto_launch_util.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/create_reg_key_work_item.h" #include "chrome/installer/util/delete_after_reboot_helper.h" @@ -411,6 +412,20 @@ InstallStatus InstallOrUpdateProduct( RegisterChromeOnMachine(installer_state, *chrome_install, make_chrome_default || force_chrome_default_for_user); + + if (result == FIRST_INSTALL_SUCCESS) { + installer_state.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH); + + // Add auto-launch key if specified in master preferences. + bool auto_launch_chrome = false; + prefs.GetBool( + installer::master_preferences::kAutoLaunchChrome, + &auto_launch_chrome); + if (auto_launch_chrome) { + auto_launch_util::SetWillLaunchAtLogin( + true, installer_state.target_path()); + } + } } installer_state.UpdateStage(installer::REMOVING_OLD_VERSIONS); diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc index 6538eab..08f53b7 100644 --- a/chrome/installer/setup/uninstall.cc +++ b/chrome/installer/setup/uninstall.cc @@ -22,6 +22,7 @@ #include "chrome/installer/setup/install_worker.h" #include "chrome/installer/setup/setup_constants.h" #include "chrome/installer/setup/setup_util.h" +#include "chrome/installer/util/auto_launch_util.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/channel_info.h" #include "chrome/installer/util/delete_after_reboot_helper.h" @@ -734,9 +735,13 @@ InstallStatus UninstallProduct(const InstallationState& original_state, // Chrome is not in use so lets uninstall Chrome by deleting various files // and registry entries. Here we will just make best effort and keep going // in case of errors. - if (is_chrome) + if (is_chrome) { ClearRlzProductState(); + if (auto_launch_util::WillLaunchAtLogin(installer_state.target_path())) + auto_launch_util::SetWillLaunchAtLogin(false, FilePath()); + } + // First delete shortcuts from Start->Programs, Desktop & Quick Launch. DeleteChromeShortcuts(installer_state, product); diff --git a/chrome/installer/util/auto_launch_util.cc b/chrome/installer/util/auto_launch_util.cc new file mode 100644 index 0000000..1a80a23 --- /dev/null +++ b/chrome/installer/util/auto_launch_util.cc @@ -0,0 +1,64 @@ +// 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/installer/util/auto_launch_util.h" + +#include "base/file_path.h" +#include "base/logging.h" +#include "base/path_service.h" +#include "base/string16.h" +#include "base/utf_string_conversions.h" +#include "base/win/win_util.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/installer/util/util_constants.h" + +namespace auto_launch_util { + +// The name of the Chrome Auto-launch key under the Run key. +const wchar_t kAutolaunchKeyValue[] = L"GoogleChromeAutoLaunch"; + +bool WillLaunchAtLogin(const FilePath& application_path) { + string16 autolaunch; + if (!base::win::ReadCommandFromAutoRun( + HKEY_CURRENT_USER, kAutolaunchKeyValue, &autolaunch)) { + return false; + } + + FilePath chrome_exe(application_path); + if (chrome_exe.empty()) { + if (!PathService::Get(base::DIR_EXE, &chrome_exe)) { + NOTREACHED(); + return false; + } + } + chrome_exe = chrome_exe.Append(installer::kChromeExe); + + return autolaunch.find(chrome_exe.value()) != string16::npos; +} + +void SetWillLaunchAtLogin(bool auto_launch, const FilePath& application_path) { + // TODO(finnur): Convert this into a shortcut, instead of using the Run key. + if (auto_launch) { + FilePath path(application_path); + if (path.empty()) { + if (!PathService::Get(base::DIR_EXE, &path)) { + NOTREACHED(); + return; + } + } + string16 cmd_line = ASCIIToUTF16("\""); + cmd_line += path.value(); + cmd_line += ASCIIToUTF16("\\"); + cmd_line += installer::kChromeExe; + cmd_line += ASCIIToUTF16("\" --"); + cmd_line += ASCIIToUTF16(switches::kAutoLaunchAtStartup); + + base::win::AddCommandToAutoRun( + HKEY_CURRENT_USER, kAutolaunchKeyValue, cmd_line); + } else { + base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, kAutolaunchKeyValue); + } +} + +} // namespace auto_launch_util diff --git a/chrome/installer/util/auto_launch_util.h b/chrome/installer/util/auto_launch_util.h new file mode 100644 index 0000000..3684e8c --- /dev/null +++ b/chrome/installer/util/auto_launch_util.h @@ -0,0 +1,31 @@ +// 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_INSTALLER_UTIL_AUTO_LAUNCH_UTIL_H_ +#define CHROME_INSTALLER_UTIL_AUTO_LAUNCH_UTIL_H_ +#pragma once + +class FilePath; + +// A namespace containing the platform specific implementation of setting Chrome +// to launch on computer startup. +namespace auto_launch_util { + +// Returns whether the Chrome executable specified in |application_path| is set +// to auto-launch at computer startup. NOTE: |application_path| is optional and +// should be blank in most cases (as it will default to the application path of +// the current executable). +bool WillLaunchAtLogin(const FilePath& application_path); + +// Configures whether the Chrome executable should auto-launch at computer +// startup. |application_path| is needed when |auto_launch| is true AND when +// the caller is not the process being set to auto-launch, ie. the installer. +// This is because |application_path|, if left blank, defaults to the +// application path of the current executable. If |auto_launch| is true, then it +// will auto-launch, otherwise it will be configured not to. +void SetWillLaunchAtLogin(bool auto_launch, const FilePath& application_path); + +} // namespace auto_launch_util + +#endif // CHROME_INSTALLER_UTIL_AUTO_LAUNCH_UTIL_H_ diff --git a/chrome/installer/util/install_util.cc b/chrome/installer/util/install_util.cc index f14f372..3479bf8 100644 --- a/chrome/installer/util/install_util.cc +++ b/chrome/installer/util/install_util.cc @@ -39,6 +39,7 @@ namespace { const wchar_t kStageBinaryPatching[] = L"binary_patching"; const wchar_t kStageBuilding[] = L"building"; +const wchar_t kStageConfiguringAutoLaunch[] = L"configuring_auto_launch"; const wchar_t kStageCopyingPreferencesFile[] = L"copying_prefs"; const wchar_t kStageCreatingShortcuts[] = L"creating_shortcuts"; const wchar_t kStageEnsemblePatching[] = L"ensemble_patching"; @@ -69,7 +70,8 @@ const wchar_t* const kStages[] = { kStageCreatingShortcuts, kStageRegisteringChrome, kStageRemovingOldVersions, - kStageFinishing + kStageFinishing, + kStageConfiguringAutoLaunch, }; COMPILE_ASSERT(installer::NUM_STAGES == arraysize(kStages), @@ -173,7 +175,8 @@ Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist, DCHECK(dist); RegKey key; HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; - LONG result = key.Open(reg_root, dist->GetVersionKey().c_str(), KEY_READ); + LONG result = key.Open(reg_root, dist->GetVersionKey().c_str(), + KEY_QUERY_VALUE); std::wstring version_str; if (result == ERROR_SUCCESS) diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc index cce0d2f..f004333 100644 --- a/chrome/installer/util/master_preferences.cc +++ b/chrome/installer/util/master_preferences.cc @@ -135,6 +135,8 @@ void MasterPreferences::InitializeFromCommandLine(const CommandLine& cmd_line) { const char* cmd_line_switch; const char* distribution_switch; } translate_switches[] = { + { installer::switches::kAutoLaunchChrome, + installer::master_preferences::kAutoLaunchChrome }, { installer::switches::kCeee, installer::master_preferences::kCeee }, { installer::switches::kChrome, diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h index 28175c5..2c7a068 100644 --- a/chrome/installer/util/master_preferences.h +++ b/chrome/installer/util/master_preferences.h @@ -39,6 +39,7 @@ const char kDefaultMasterPrefs[] = "master_preferences"; // { // "distribution": { // "alternate_shortcut_text": false, +// "auto_launch_chrome": false, // "oem_bubble": false, // "chrome_shortcut_icon_index": 0, // "create_all_shortcuts": true, diff --git a/chrome/installer/util/master_preferences_constants.cc b/chrome/installer/util/master_preferences_constants.cc index cea5b7f..c1c353f 100644 --- a/chrome/installer/util/master_preferences_constants.cc +++ b/chrome/installer/util/master_preferences_constants.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -8,6 +8,7 @@ namespace installer { namespace master_preferences { const char kAltFirstRunBubble[] = "oem_bubble"; const char kAltShortcutText[] = "alternate_shortcut_text"; + const char kAutoLaunchChrome[] = "auto_launch_chrome"; const char kCeee[] = "ceee"; const char kChrome[] = "chrome"; const char kChromeFrame[] = "chrome_frame"; diff --git a/chrome/installer/util/master_preferences_constants.h b/chrome/installer/util/master_preferences_constants.h index cd3d034..fb0acd89 100644 --- a/chrome/installer/util/master_preferences_constants.h +++ b/chrome/installer/util/master_preferences_constants.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. // @@ -13,13 +13,16 @@ namespace installer { namespace master_preferences { // All the preferences below are expected to be inside the JSON "distribution" // block. Some of them also have equivalent command line option. If same option -// is specified in master preference as well as command line, the commnd line +// is specified in master preference as well as command line, the command line // value takes precedence. // Boolean. Use alternate text for the shortcut. Cmd line override present. extern const char kAltShortcutText[]; // Boolean. Use alternate smaller first run info bubble. extern const char kAltFirstRunBubble[]; +// Boolean. Whether to instruct the installer to auto-launch chrome on computer +// startup. The default (if not provided) is |false|. +extern const char kAutoLaunchChrome[]; // Boolean. CEEE features of Chrome Frame should be enabled as part of // the install. Requires kChromeFrame to be specified as well. extern const char kCeee[]; diff --git a/chrome/installer/util/util_constants.cc b/chrome/installer/util/util_constants.cc index 72943a8..9dab113 100644 --- a/chrome/installer/util/util_constants.cc +++ b/chrome/installer/util/util_constants.cc @@ -8,6 +8,9 @@ namespace installer { namespace switches { +// Whether to set Chrome to launch at computer startup. +const char kAutoLaunchChrome[] = "auto-launch-chrome"; + // Install CEEE. const char kCeee[] = "ceee"; diff --git a/chrome/installer/util/util_constants.h b/chrome/installer/util/util_constants.h index 5911701..066edb8f 100644 --- a/chrome/installer/util/util_constants.h +++ b/chrome/installer/util/util_constants.h @@ -92,6 +92,9 @@ enum ArchiveType { }; // Stages of an installation reported through Google Update on failure. +// The order and value of existing enums must not change. Please add new +// values to the end (before NUM_STAGES) and update the compile assert below +// to assert on the last value added. enum InstallerStage { NO_STAGE, // 0: No stage to report. PRECONDITIONS, // 1: Evaluating pre-install conditions. @@ -109,15 +112,17 @@ enum InstallerStage { REGISTERING_CHROME, // 13: Performing Chrome registration. REMOVING_OLD_VERSIONS, // 14: Deleting old version directories. FINISHING, // 15: Finishing the install. - NUM_STAGES // 16: The number of stages. + CONFIGURE_AUTO_LAUNCH, // 16: Configuring Chrome to auto-launch. + NUM_STAGES // 17: The number of stages. }; // When we start reporting the numerical values from the enum, the order // above MUST be preserved. -COMPILE_ASSERT(FINISHING == 15, +COMPILE_ASSERT(CONFIGURE_AUTO_LAUNCH == 16, never_ever_ever_change_InstallerStage_values_bang); namespace switches { +extern const char kAutoLaunchChrome[]; extern const char kCeee[]; extern const char kChrome[]; extern const char kChromeFrame[]; |