diff options
author | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-13 14:35:53 +0000 |
---|---|---|
committer | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-13 14:35:53 +0000 |
commit | a947ccbb9104c4ac6104837f00baca16d3a7ea62 (patch) | |
tree | 3ef45854c369758b105ecf17112374de2a410d34 /chrome | |
parent | f7c1658f2adf64f36eb5950dda426097e6191c88 (diff) | |
download | chromium_src-a947ccbb9104c4ac6104837f00baca16d3a7ea62.zip chromium_src-a947ccbb9104c4ac6104837f00baca16d3a7ea62.tar.gz chromium_src-a947ccbb9104c4ac6104837f00baca16d3a7ea62.tar.bz2 |
Add a CEEE mode to the ChromeFrame distribution class.
Pass a MasterPreferences into BrowserDistribution et al. to allow for preferences-based behaviour.
Add a GetComDllList() method that returns the set of registerable components for that distribution.
Change GetKeyFile() on BrowserDistribution to GetKeyFiles().
Refactor GetMasterPreferencesForCurrentProcess into a static method on MasterPreferences.
BUG=61609
TEST=None
Review URL: http://codereview.chromium.org/5558006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68996 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
26 files changed, 300 insertions, 163 deletions
diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc index e6507d6..b6b9939 100644 --- a/chrome/installer/setup/install.cc +++ b/chrome/installer/setup/install.cc @@ -16,6 +16,7 @@ #include "base/win/registry.h" #include "chrome/installer/setup/setup_constants.h" #include "chrome/installer/util/browser_distribution.h" +#include "chrome/installer/util/chrome_frame_distribution.h" #include "chrome/installer/util/create_reg_key_work_item.h" #include "chrome/installer/util/delete_after_reboot_helper.h" #include "chrome/installer/util/google_update_constants.h" @@ -83,52 +84,23 @@ void AppendUninstallCommandLineFlags(CommandLine* uninstall_cmd, uninstall_cmd->AppendSwitch(installer_util::switches::kUninstall); - const installer_util::MasterPreferences& prefs = - InstallUtil::GetMasterPreferencesForCurrentProcess(); - - bool cf_switch_added = false; + // Append the product-specific uninstall flags. + product.distribution()->AppendUninstallCommandLineFlags(uninstall_cmd); + if (product.IsMsi()) + uninstall_cmd->AppendSwitch(installer_util::switches::kMsi); + if (product.system_level()) + uninstall_cmd->AppendSwitch(installer_util::switches::kSystemLevel); + // Propagate switches obtained from preferences as well. + const installer_util::MasterPreferences& prefs = + installer_util::MasterPreferences::ForCurrentProcess(); if (prefs.is_multi_install()) { uninstall_cmd->AppendSwitch(installer_util::switches::kMultiInstall); - switch (product.distribution()->GetType()) { - case BrowserDistribution::CHROME_BROWSER: - uninstall_cmd->AppendSwitch(installer_util::switches::kChrome); - break; - case BrowserDistribution::CHROME_FRAME: - uninstall_cmd->AppendSwitch(installer_util::switches::kChromeFrame); - cf_switch_added = true; - break; - case BrowserDistribution::CEEE: - uninstall_cmd->AppendSwitch(installer_util::switches::kCeee); - break; - default: - NOTREACHED(); - break; - } - } - - if (product.distribution()->GetType() == BrowserDistribution::CHROME_FRAME) { - DCHECK(prefs.install_chrome_frame()); - uninstall_cmd->AppendSwitch(installer_util::switches::kDeleteProfile); - if (!cf_switch_added) { - uninstall_cmd->AppendSwitch(installer_util::switches::kChromeFrame); - } } - - if (InstallUtil::IsChromeSxSProcess()) - uninstall_cmd->AppendSwitch(installer_util::switches::kChromeSxS); - - if (product.IsMsi()) - uninstall_cmd->AppendSwitch(installer_util::switches::kMsi); - - // Propagate the verbose logging switch to uninstalls too. bool value = false; if (prefs.GetBool(installer_util::master_preferences::kVerboseLogging, &value) && value) uninstall_cmd->AppendSwitch(installer_util::switches::kVerboseLogging); - - if (product.system_level()) - uninstall_cmd->AppendSwitch(installer_util::switches::kSystemLevel); } // This method adds work items to create (or update) Chrome uninstall entry in @@ -292,7 +264,7 @@ bool CreateOrUpdateChromeShortcuts(const FilePath& setup_path, // TODO(tommi): Change this function to use WorkItemList. #ifndef NDEBUG const installer_util::MasterPreferences& prefs = - InstallUtil::GetMasterPreferencesForCurrentProcess(); + installer_util::MasterPreferences::ForCurrentProcess(); DCHECK(prefs.install_chrome()); #endif @@ -513,10 +485,7 @@ bool DoPostInstallTasks(const FilePath& setup_path, } } - if (FindProduct(products, BrowserDistribution::CHROME_FRAME) || - FindProduct(products, BrowserDistribution::CEEE)) { - // TODO(robershield): move the "which DLLs should be registered" policy - // into the installer. + if (FindProduct(products, BrowserDistribution::CHROME_FRAME)) { if (!RegisterComDlls(package, current_version, new_version)) { LOG(ERROR) << "RegisterComDlls failed. Aborting."; return false; @@ -850,4 +819,3 @@ bool RegisterComDllList(const FilePath& dll_folder, bool system_level, } } // namespace installer - diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc index 8aa5638..239d4fa 100644 --- a/chrome/installer/setup/setup_main.cc +++ b/chrome/installer/setup/setup_main.cc @@ -42,7 +42,7 @@ #include "chrome/installer/util/shell_util.h" #include "chrome/installer/util/util_constants.h" -#include "installer_util_strings.h" +#include "installer_util_strings.h" // NOLINT using installer::Product; using installer::ProductPackageMapping; @@ -282,7 +282,7 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, FilePath unpack_path(temp_path.Append(installer::kInstallSourceDir)); bool incremental_install = false; - if (UnPackArchive(archive, installation,temp_path, unpack_path, + if (UnPackArchive(archive, installation, temp_path, unpack_path, incremental_install)) { install_status = installer_util::UNCOMPRESSION_FAILED; WriteInstallerResult(products, install_status, @@ -696,17 +696,12 @@ void PopulateInstallations(const MasterPreferences& prefs, DCHECK(installations); if (prefs.install_chrome()) { VLOG(1) << "Install distribution: Chrome"; - installations->AddDistribution(BrowserDistribution::CHROME_BROWSER); + installations->AddDistribution(BrowserDistribution::CHROME_BROWSER, prefs); } if (prefs.install_chrome_frame()) { VLOG(1) << "Install distribution: Chrome Frame"; - installations->AddDistribution(BrowserDistribution::CHROME_FRAME); - } - - if (prefs.install_ceee()) { - VLOG(1) << "Install distribution: CEEE"; - installations->AddDistribution(BrowserDistribution::CHROME_FRAME); + installations->AddDistribution(BrowserDistribution::CHROME_FRAME, prefs); } } @@ -719,7 +714,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, CommandLine::Init(0, NULL); const MasterPreferences& prefs = - InstallUtil::GetMasterPreferencesForCurrentProcess(); + installer_util::MasterPreferences::ForCurrentProcess(); installer::InitInstallerLogging(prefs); const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc index 018e9da..4ef2103 100644 --- a/chrome/installer/setup/uninstall.cc +++ b/chrome/installer/setup/uninstall.cc @@ -218,13 +218,10 @@ enum DeleteResult { }; FilePath GetLocalStateFolder(const Product& product) { - // chrome_frame will be true for CHROME_FRAME and CEEE. - bool chrome_frame = (product.distribution()->GetType() != - BrowserDistribution::CHROME_BROWSER); // Obtain the location of the user profile data. Chrome Frame needs to // build this path manually since it doesn't use the Chrome default dir. FilePath local_state_folder; - if (chrome_frame) { + if (product.distribution()->GetType() == BrowserDistribution::CHROME_FRAME) { chrome::GetChromeFrameUserDataDirectory(&local_state_folder); } else { chrome::GetDefaultUserDataDirectory(&local_state_folder); diff --git a/chrome/installer/util/browser_distribution.cc b/chrome/installer/util/browser_distribution.cc index 1a82cf5..933a783 100644 --- a/chrome/installer/util/browser_distribution.cc +++ b/chrome/installer/util/browser_distribution.cc @@ -48,22 +48,27 @@ bool IsCeeeBrokerProcess() { installer_util::kCeeeBrokerExe); } -BrowserDistribution::DistributionType GetCurrentDistributionType() { - static BrowserDistribution::DistributionType type = +BrowserDistribution::Type GetCurrentDistributionType() { + static BrowserDistribution::Type type = (InstallUtil::IsChromeFrameProcess() || IsChromeFrameModule()) ? BrowserDistribution::CHROME_FRAME : - (IsCeeeBrokerProcess() ? BrowserDistribution::CEEE : - BrowserDistribution::CHROME_BROWSER); + BrowserDistribution::CHROME_BROWSER; return type; } } // end namespace +BrowserDistribution::BrowserDistribution( + const installer_util::MasterPreferences& prefs) + : type_(BrowserDistribution::CHROME_BROWSER) { +} + template<class DistributionClass> BrowserDistribution* BrowserDistribution::GetOrCreateBrowserDistribution( + const installer_util::MasterPreferences& prefs, BrowserDistribution** dist) { if (!*dist) { - DistributionClass* temp = new DistributionClass(); + DistributionClass* temp = new DistributionClass(prefs); if (base::subtle::NoBarrier_CompareAndSwap( reinterpret_cast<base::subtle::AtomicWord*>(dist), NULL, reinterpret_cast<base::subtle::AtomicWord>(temp)) != NULL) @@ -74,35 +79,33 @@ BrowserDistribution* BrowserDistribution::GetOrCreateBrowserDistribution( } BrowserDistribution* BrowserDistribution::GetDistribution() { - return GetSpecificDistribution(GetCurrentDistributionType()); + const installer_util::MasterPreferences& prefs = + installer_util::MasterPreferences::ForCurrentProcess(); + return GetSpecificDistribution(GetCurrentDistributionType(), prefs); } // static BrowserDistribution* BrowserDistribution::GetSpecificDistribution( - BrowserDistribution::DistributionType type) { + BrowserDistribution::Type type, + const installer_util::MasterPreferences& prefs) { BrowserDistribution* dist = NULL; - // TODO(tommi): initialize g_ceee_distribution when appropriate. Right now - // we treat CEEE as Chrome Frame. - - if (type == CHROME_FRAME || type == CEEE) { - // TODO(robertshield): Make one of these for Google Chrome vs - // non Google Chrome builds? + if (type == CHROME_FRAME) { dist = GetOrCreateBrowserDistribution<ChromeFrameDistribution>( - &g_chrome_frame_distribution); + prefs, &g_chrome_frame_distribution); } else { DCHECK_EQ(CHROME_BROWSER, type); #if defined(GOOGLE_CHROME_BUILD) - if (InstallUtil::IsChromeSxSProcess()) { - dist = GetOrCreateBrowserDistribution<GoogleChromeSxSDistribution>( - &g_browser_distribution); - } else { - dist = GetOrCreateBrowserDistribution<GoogleChromeDistribution>( - &g_browser_distribution); - } + if (InstallUtil::IsChromeSxSProcess()) { + dist = GetOrCreateBrowserDistribution<GoogleChromeSxSDistribution>( + prefs, &g_browser_distribution); + } else { + dist = GetOrCreateBrowserDistribution<GoogleChromeDistribution>( + prefs, &g_browser_distribution); + } #else - dist = GetOrCreateBrowserDistribution<BrowserDistribution>( - &g_browser_distribution); + dist = GetOrCreateBrowserDistribution<BrowserDistribution>( + prefs, &g_browser_distribution); #endif } @@ -224,6 +227,18 @@ void BrowserDistribution::InactiveUserToastExperiment(int flavor, const installer::Product& installation) { } -FilePath::StringType BrowserDistribution::GetKeyFile() { - return installer_util::kChromeDll; +std::vector<FilePath> BrowserDistribution::GetKeyFiles() { + std::vector<FilePath> key_files; + key_files.push_back(FilePath(installer_util::kChromeDll)); + return key_files; +} + +std::vector<FilePath> BrowserDistribution::GetComDllList() { + return std::vector<FilePath>(); +} + +void BrowserDistribution::AppendUninstallCommandLineFlags( + CommandLine* cmd_line) { + DCHECK(cmd_line); + cmd_line->AppendSwitch(installer_util::switches::kChrome); } diff --git a/chrome/installer/util/browser_distribution.h b/chrome/installer/util/browser_distribution.h index 53aa540..a4436bff 100644 --- a/chrome/installer/util/browser_distribution.h +++ b/chrome/installer/util/browser_distribution.h @@ -9,6 +9,7 @@ #pragma once #include <string> +#include <vector> #include "base/basictypes.h" #include "base/file_path.h" @@ -19,25 +20,30 @@ #include <windows.h> // NOLINT #endif +class CommandLine; + namespace installer { class Product; } +namespace installer_util { +class MasterPreferences; +} class BrowserDistribution { public: virtual ~BrowserDistribution() {} - enum DistributionType { + enum Type { CHROME_BROWSER, CHROME_FRAME, - CEEE, }; static BrowserDistribution* GetDistribution(); - static BrowserDistribution* GetSpecificDistribution(DistributionType type); + static BrowserDistribution* GetSpecificDistribution( + Type type, const installer_util::MasterPreferences& prefs); - DistributionType GetType() const { return type_; } + Type GetType() const { return type_; } static int GetInstallReturnCode(installer_util::InstallStatus install_status); @@ -109,18 +115,27 @@ class BrowserDistribution { // an uninstallation, the uninstaller will check if any one of a potential // set of key files is in use and if they are, abort the delete operation. // Only if none of the key files are in use, can the folder be deleted. - // Note that this function does not return a full path to the key file, - // only a file name. - virtual FilePath::StringType GetKeyFile(); + // Note that this function does not return a full path to the key file(s), + // only (a) file name(s). + virtual std::vector<FilePath> GetKeyFiles(); + + // Returns the list of Com Dlls that this product cares about having + // registered and unregistered. The list may be empty. + virtual std::vector<FilePath> GetComDllList(); + + // Given a command line, appends the set of uninstall flags the uninstaller + // for this distribution will require. + virtual void AppendUninstallCommandLineFlags(CommandLine* cmd_line); protected: - BrowserDistribution() : type_(CHROME_BROWSER) {} + explicit BrowserDistribution(const installer_util::MasterPreferences& prefs); template<class DistributionClass> static BrowserDistribution* GetOrCreateBrowserDistribution( + const installer_util::MasterPreferences& prefs, BrowserDistribution** dist); - DistributionType type_; + Type type_; private: DISALLOW_COPY_AND_ASSIGN(BrowserDistribution); diff --git a/chrome/installer/util/browser_distribution_unittest.cc b/chrome/installer/util/browser_distribution_unittest.cc index 2733d1f..ac6b399 100644 --- a/chrome/installer/util/browser_distribution_unittest.cc +++ b/chrome/installer/util/browser_distribution_unittest.cc @@ -5,6 +5,7 @@ // Unit tests for BrowserDistribution class. #include "chrome/installer/util/browser_distribution.h" +#include "chrome/installer/util/master_preferences.h" #include "chrome/installer/util/shell_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -24,15 +25,21 @@ class BrowserDistributionTest : public testing::Test { // The distribution strings should not be empty. The unit tests are not linking // with the chrome resources so we cannot test official build. TEST(BrowserDistributionTest, StringsTest) { - BrowserDistribution::DistributionType types[] = { - BrowserDistribution::CHROME_BROWSER, - BrowserDistribution::CHROME_FRAME, - // TODO(tommi): Also include CEEE. + struct browser_test_type { + BrowserDistribution::Type type; + bool has_com_dlls; + } browser_tests[] = { + { BrowserDistribution::CHROME_BROWSER, false }, + { BrowserDistribution::CHROME_FRAME, true }, }; - for (int i = 0; i < arraysize(types); ++i) { + const installer_util::MasterPreferences& prefs = + installer_util::MasterPreferences::ForCurrentProcess(); + + for (int i = 0; i < arraysize(browser_tests); ++i) { BrowserDistribution* dist = - BrowserDistribution::GetSpecificDistribution(types[i]); + BrowserDistribution::GetSpecificDistribution(browser_tests[i].type, + prefs); ASSERT_TRUE(dist != NULL); std::wstring name = dist->GetApplicationName(); EXPECT_FALSE(name.empty()); @@ -40,6 +47,12 @@ TEST(BrowserDistributionTest, StringsTest) { EXPECT_FALSE(desc.empty()); std::wstring alt_name = dist->GetAlternateApplicationName(); EXPECT_FALSE(alt_name.empty()); + std::vector<FilePath> com_dlls(dist->GetComDllList()); + if (browser_tests[i].has_com_dlls) { + EXPECT_FALSE(com_dlls.empty()); + } else { + EXPECT_TRUE(com_dlls.empty()); + } } } diff --git a/chrome/installer/util/chrome_frame_distribution.cc b/chrome/installer/util/chrome_frame_distribution.cc index 896cd87..02ec281 100644 --- a/chrome/installer/util/chrome_frame_distribution.cc +++ b/chrome/installer/util/chrome_frame_distribution.cc @@ -12,9 +12,10 @@ #include <string> #include "base/string_util.h" -#include "chrome/installer/util/l10n_string_util.h" #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/google_update_settings.h" +#include "chrome/installer/util/l10n_string_util.h" +#include "chrome/installer/util/master_preferences.h" #include "installer_util_strings.h" // NOLINT @@ -22,6 +23,13 @@ namespace { const wchar_t kChromeFrameGuid[] = L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}"; } +ChromeFrameDistribution::ChromeFrameDistribution( + const installer_util::MasterPreferences& prefs) + : BrowserDistribution(prefs) { + type_ = BrowserDistribution::CHROME_FRAME; + ceee_ = prefs.install_ceee(); +} + std::wstring ChromeFrameDistribution::GetAppGuid() { return kChromeFrameGuid; } @@ -78,7 +86,6 @@ std::wstring ChromeFrameDistribution::GetStatsServerURL() { return L"https://clients4.google.com/firefox/metrics/collect"; } - std::wstring ChromeFrameDistribution::GetUninstallLinkName() { return L"Uninstall Chrome Frame"; } @@ -106,7 +113,32 @@ void ChromeFrameDistribution::UpdateDiffInstallStatus(bool system_install, kChromeFrameGuid); } -FilePath::StringType ChromeFrameDistribution::GetKeyFile() { - // TODO(tommi): Implement this for CEEE too. - return installer_util::kChromeFrameDll; +std::vector<FilePath> ChromeFrameDistribution::GetKeyFiles() { + std::vector<FilePath> key_files; + key_files.push_back(FilePath(installer_util::kChromeFrameDll)); + if (ceee_) { + key_files.push_back(FilePath(installer_util::kCeeeIeDll)); + key_files.push_back(FilePath(installer_util::kCeeeBrokerExe)); + } + return key_files; +} + +std::vector<FilePath> ChromeFrameDistribution::GetComDllList() { + std::vector<FilePath> dll_list; + dll_list.push_back(FilePath(installer_util::kChromeFrameDll)); + if (ceee_) { + dll_list.push_back(FilePath(installer_util::kCeeeInstallHelperDll)); + dll_list.push_back(FilePath(installer_util::kCeeeIeDll)); + } + return dll_list; +} + +void ChromeFrameDistribution::AppendUninstallCommandLineFlags( + CommandLine* cmd_line) { + DCHECK(cmd_line); + cmd_line->AppendSwitch(installer_util::switches::kDeleteProfile); + cmd_line->AppendSwitch(installer_util::switches::kChromeFrame); + if (ceee_) { + cmd_line->AppendSwitch(installer_util::switches::kCeee); + } } diff --git a/chrome/installer/util/chrome_frame_distribution.h b/chrome/installer/util/chrome_frame_distribution.h index 7c368119..fdf9c28 100644 --- a/chrome/installer/util/chrome_frame_distribution.h +++ b/chrome/installer/util/chrome_frame_distribution.h @@ -14,6 +14,10 @@ #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/util_constants.h" +namespace installer_util { +class MasterPreferences; +} + class ChromeFrameDistribution : public BrowserDistribution { public: virtual std::wstring GetAppGuid(); @@ -52,15 +56,22 @@ class ChromeFrameDistribution : public BrowserDistribution { virtual void UpdateDiffInstallStatus(bool system_install, bool incremental_install, installer_util::InstallStatus install_status); - virtual FilePath::StringType GetKeyFile(); + virtual std::vector<FilePath> GetKeyFiles(); + + virtual std::vector<FilePath> GetComDllList(); + + virtual void AppendUninstallCommandLineFlags(CommandLine* cmd_line); protected: friend class BrowserDistribution; // Disallow construction from non-friends. - ChromeFrameDistribution() { - type_ = BrowserDistribution::CHROME_FRAME; - } + explicit ChromeFrameDistribution( + const installer_util::MasterPreferences& prefs); + + // Determines whether this Chrome Frame distribution is being used to work + // with CEEE bits as well. + bool ceee_; }; #endif // CHROME_INSTALLER_UTIL_CHROME_FRAME_DISTRIBUTION_H_ diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc index f60fb96..31987f9 100644 --- a/chrome/installer/util/google_chrome_distribution.cc +++ b/chrome/installer/util/google_chrome_distribution.cc @@ -35,7 +35,7 @@ #include "chrome/installer/util/util_constants.h" #include "chrome/installer/util/wmi.h" -#include "installer_util_strings.h" +#include "installer_util_strings.h" // NOLINT #pragma comment(lib, "wtsapi32.lib") @@ -252,8 +252,9 @@ bool RelaunchSetupAsConsoleUser(const std::string& flag) { } // namespace -GoogleChromeDistribution::GoogleChromeDistribution() - : product_guid_(kChromeGuid) { +GoogleChromeDistribution::GoogleChromeDistribution( + const installer_util::MasterPreferences& prefs) + : BrowserDistribution(prefs), product_guid_(kChromeGuid) { } // The functions below are not used by the 64-bit Windows binary - diff --git a/chrome/installer/util/google_chrome_distribution.h b/chrome/installer/util/google_chrome_distribution.h index 221f6b4..9a84b94 100644 --- a/chrome/installer/util/google_chrome_distribution.h +++ b/chrome/installer/util/google_chrome_distribution.h @@ -9,6 +9,8 @@ #define CHROME_INSTALLER_UTIL_GOOGLE_CHROME_DISTRIBUTION_H_ #pragma once +#include <string> + #include "base/gtest_prod_util.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/util_constants.h" @@ -83,7 +85,8 @@ class GoogleChromeDistribution : public BrowserDistribution { void set_product_guid(std::wstring guid) { product_guid_ = guid; } // Disallow construction from others. - GoogleChromeDistribution(); + explicit GoogleChromeDistribution( + const installer_util::MasterPreferences& prefs); private: friend class BrowserDistribution; diff --git a/chrome/installer/util/google_chrome_distribution_dummy.cc b/chrome/installer/util/google_chrome_distribution_dummy.cc index 94b2ddd..9d6d6d5 100644 --- a/chrome/installer/util/google_chrome_distribution_dummy.cc +++ b/chrome/installer/util/google_chrome_distribution_dummy.cc @@ -14,7 +14,9 @@ #include "base/logging.h" -GoogleChromeDistribution::GoogleChromeDistribution() { +GoogleChromeDistribution::GoogleChromeDistribution( + const installer_util::MasterPreferences& prefs) + : BrowserDistribution(prefs) { } void GoogleChromeDistribution::DoPostUninstallOperations( diff --git a/chrome/installer/util/google_chrome_distribution_unittest.cc b/chrome/installer/util/google_chrome_distribution_unittest.cc index 10c2022..ee5ce89 100644 --- a/chrome/installer/util/google_chrome_distribution_unittest.cc +++ b/chrome/installer/util/google_chrome_distribution_unittest.cc @@ -11,6 +11,7 @@ #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/google_chrome_distribution.h" +#include "chrome/installer/util/master_preferences.h" #include "testing/gtest/include/gtest/gtest.h" #if defined(GOOGLE_CHROME_BUILD) @@ -50,9 +51,13 @@ TEST(GoogleChromeDistTest, TestExtractUninstallMetrics) { scoped_ptr<Value> root(json_deserializer.Deserialize(NULL, &error_message)); ASSERT_TRUE(root.get()); std::wstring uninstall_metrics_string; + + const installer_util::MasterPreferences& prefs = + installer_util::MasterPreferences::ForCurrentProcess(); + GoogleChromeDistribution* dist = static_cast<GoogleChromeDistribution*>( BrowserDistribution::GetSpecificDistribution( - BrowserDistribution::CHROME_BROWSER)); + BrowserDistribution::CHROME_BROWSER, prefs)); EXPECT_TRUE( dist->ExtractUninstallMetrics(*static_cast<DictionaryValue*>(root.get()), diff --git a/chrome/installer/util/google_chrome_sxs_distribution.cc b/chrome/installer/util/google_chrome_sxs_distribution.cc index b24c9c3..0adfd95 100644 --- a/chrome/installer/util/google_chrome_sxs_distribution.cc +++ b/chrome/installer/util/google_chrome_sxs_distribution.cc @@ -6,6 +6,9 @@ #include "chrome/installer/util/google_chrome_sxs_distribution.h" +#include "base/command_line.h" +#include "base/logging.h" + #include "installer_util_strings.h" namespace { @@ -17,7 +20,9 @@ const int kSxSIconIndex = 4; } // namespace -GoogleChromeSxSDistribution::GoogleChromeSxSDistribution() { +GoogleChromeSxSDistribution::GoogleChromeSxSDistribution( + const installer_util::MasterPreferences& prefs) + : GoogleChromeDistribution(prefs) { GoogleChromeDistribution::set_product_guid(kChromeSxSGuid); } @@ -57,3 +62,9 @@ bool GoogleChromeSxSDistribution::GetChromeChannel(std::wstring* channel) { std::wstring GoogleChromeSxSDistribution::ChannelName() { return kChannelName; } + +void GoogleChromeSxSDistribution::AppendUninstallCommandLineFlags( + CommandLine* cmd_line) { + DCHECK(cmd_line); + cmd_line->AppendSwitch(installer_util::switches::kChromeSxS); +} diff --git a/chrome/installer/util/google_chrome_sxs_distribution.h b/chrome/installer/util/google_chrome_sxs_distribution.h index 5981d46..c007c1c 100644 --- a/chrome/installer/util/google_chrome_sxs_distribution.h +++ b/chrome/installer/util/google_chrome_sxs_distribution.h @@ -11,6 +11,9 @@ #include "chrome/installer/util/l10n_string_util.h" #include "chrome/installer/util/util_constants.h" +namespace installer_util { +class MasterPreferences; +} // GoogleChromeSxSDistribution encapsulates properties of Google Chrome Sxs // distribution which can co-exist with other Google Chrome distributions. @@ -29,11 +32,13 @@ class GoogleChromeSxSDistribution : public GoogleChromeDistribution { virtual bool GetChromeChannel(std::wstring* channel); // returns the channel name for GoogleChromeSxSDistribution static std::wstring ChannelName(); + virtual void AppendUninstallCommandLineFlags(CommandLine* cmd_line); private: friend class BrowserDistribution; // Disallow construction from non-friends. - GoogleChromeSxSDistribution(); + explicit GoogleChromeSxSDistribution( + const installer_util::MasterPreferences& prefs); }; #endif // CHROME_INSTALLER_UTIL_GOOGLE_CHROME_SXS_DISTRIBUTION_H_ diff --git a/chrome/installer/util/install_util.cc b/chrome/installer/util/install_util.cc index ae9c67d..d18b1612 100644 --- a/chrome/installer/util/install_util.cc +++ b/chrome/installer/util/install_util.cc @@ -31,11 +31,6 @@ using base::win::RegKey; using installer_util::MasterPreferences; -const MasterPreferences& InstallUtil::GetMasterPreferencesForCurrentProcess() { - static MasterPreferences prefs(*CommandLine::ForCurrentProcess()); - return prefs; -} - bool InstallUtil::ExecuteExeAsAdmin(const CommandLine& cmd, DWORD* exit_code) { FilePath::StringType program(cmd.GetProgram().value()); DCHECK(!program.empty()); @@ -125,7 +120,8 @@ bool InstallUtil::IsPerUserInstall(const wchar_t* const exe_path) { } bool InstallUtil::IsChromeFrameProcess() { - const MasterPreferences& prefs = GetMasterPreferencesForCurrentProcess(); + const MasterPreferences& prefs = + installer_util::MasterPreferences::ForCurrentProcess(); return prefs.install_chrome_frame(); } diff --git a/chrome/installer/util/install_util.h b/chrome/installer/util/install_util.h index 5fd87be..fd21b29 100644 --- a/chrome/installer/util/install_util.h +++ b/chrome/installer/util/install_util.h @@ -100,12 +100,6 @@ class InstallUtil { static bool DeleteRegistryValue(HKEY reg_root, const std::wstring& key_path, const std::wstring& value_name); - // Returns a static preference object that has been initialized with the - // CommandLine object for the current process. - // NOTE: Must not be called before CommandLine::Init() is called! - static const installer_util::MasterPreferences& - GetMasterPreferencesForCurrentProcess(); - private: DISALLOW_COPY_AND_ASSIGN(InstallUtil); }; diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc index 2d77ada..9fc3bd4 100644 --- a/chrome/installer/util/master_preferences.cc +++ b/chrome/installer/util/master_preferences.cc @@ -7,13 +7,13 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" +#include "base/singleton.h" #include "base/string_util.h" #include "chrome/common/json_value_serializer.h" #include "chrome/installer/util/master_preferences_constants.h" #include "chrome/installer/util/util_constants.h" #include "googleurl/src/gurl.h" - namespace { const char kDistroDict[] = "distribution"; @@ -74,9 +74,45 @@ DictionaryValue* ParseDistributionPreferences( namespace installer_util { +MasterPreferences::MasterPreferences() : distribution_(NULL), + preferences_read_from_file_(false), + ceee_(false), + chrome_(true), + chrome_frame_(false), + multi_install_(false) { + InitializeFromCommandLine(*CommandLine::ForCurrentProcess()); +} + MasterPreferences::MasterPreferences(const CommandLine& cmd_line) + : distribution_(NULL), + preferences_read_from_file_(false), + ceee_(false), + chrome_(true), + chrome_frame_(false), + multi_install_(false) { + InitializeFromCommandLine(cmd_line); +} + +MasterPreferences::MasterPreferences(const FilePath& prefs_path) : distribution_(NULL), preferences_read_from_file_(false), ceee_(false), chrome_(true), chrome_frame_(false), multi_install_(false) { + master_dictionary_.reset(ParseDistributionPreferences(prefs_path)); + + if (!master_dictionary_.get()) { + master_dictionary_.reset(new DictionaryValue()); + } else { + preferences_read_from_file_ = true; + // Cache a pointer to the distribution dictionary. + master_dictionary_->GetDictionary(kDistroDict, &distribution_); + } + + InitializeProductFlags(); +} + +MasterPreferences::~MasterPreferences() { +} + +void MasterPreferences::InitializeFromCommandLine(const CommandLine& cmd_line) { #if defined(OS_WIN) if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) { FilePath prefs_path(cmd_line.GetSwitchValuePath( @@ -150,25 +186,6 @@ MasterPreferences::MasterPreferences(const CommandLine& cmd_line) #endif } -MasterPreferences::MasterPreferences(const FilePath& prefs_path) - : distribution_(NULL), preferences_read_from_file_(false), ceee_(false), - chrome_(true), chrome_frame_(false), multi_install_(false) { - master_dictionary_.reset(ParseDistributionPreferences(prefs_path)); - - if (!master_dictionary_.get()) { - master_dictionary_.reset(new DictionaryValue()); - } else { - preferences_read_from_file_ = true; - // Cache a pointer to the distribution dictionary. - master_dictionary_->GetDictionary(kDistroDict, &distribution_); - } - - InitializeProductFlags(); -} - -MasterPreferences::~MasterPreferences() { -} - void MasterPreferences::InitializeProductFlags() { // Make sure we start out with the correct defaults. multi_install_ = false; @@ -235,4 +252,8 @@ bool MasterPreferences::GetExtensionsBlock(DictionaryValue** extensions) const { master_preferences::kExtensionsBlock, extensions); } +// static +const MasterPreferences& MasterPreferences::ForCurrentProcess() { + return *Singleton<MasterPreferences>::get(); +} } // installer_util diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h index 53c708e..f0d93c8 100644 --- a/chrome/installer/util/master_preferences.h +++ b/chrome/installer/util/master_preferences.h @@ -9,6 +9,7 @@ #define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ #pragma once +#include <string> #include <vector> #include "base/command_line.h" @@ -69,8 +70,14 @@ const char kDefaultMasterPrefs[] = "master_preferences"; // installation properties. This entry will be ignored at other times. // This function parses the 'distribution' entry and returns a combination // of MasterPrefResult. + class MasterPreferences { public: + // Construct a master preferences from the current process' current command + // line. Equivalent to calling + // MasterPreferences(*CommandLine::ForCurrentProcess()). + MasterPreferences(); + // Parses the command line and optionally reads the master preferences file // to get distribution related install options (if the "installerdata" switch // is present in the command line. @@ -165,9 +172,17 @@ class MasterPreferences { return multi_install_; } + // Returns a static preference object that has been initialized with the + // CommandLine object for the current process. + // NOTE: Must not be called before CommandLine::Init() is called! + // OTHER NOTE: Not thread safe. + static const MasterPreferences& ForCurrentProcess(); + protected: void InitializeProductFlags(); + void InitializeFromCommandLine(const CommandLine& cmd_line); + protected: scoped_ptr<DictionaryValue> master_dictionary_; DictionaryValue* distribution_; diff --git a/chrome/installer/util/master_preferences_dummy.cc b/chrome/installer/util/master_preferences_dummy.cc index 2ae6d4b..3f8f549 100644 --- a/chrome/installer/util/master_preferences_dummy.cc +++ b/chrome/installer/util/master_preferences_dummy.cc @@ -51,4 +51,9 @@ std::vector<GURL> MasterPreferences::GetFirstRunTabs() const { return std::vector<GURL>(); } +// static +const MasterPreferences& MasterPreferences::ForCurrentProcess() { + static MasterPreferences prefs(*CommandLine::ForCurrentProcess()); + return prefs; +} } diff --git a/chrome/installer/util/package.cc b/chrome/installer/util/package.cc index 569a8f5..d662548 100644 --- a/chrome/installer/util/package.cc +++ b/chrome/installer/util/package.cc @@ -126,10 +126,16 @@ void Package::RemoveOldVersionDirectories( if (version.get() && latest_version.IsHigherThan(version.get())) { FilePath remove_dir(path_.Append(find_file_data.cFileName)); std::vector<FilePath> key_files; + Products::const_iterator it = products_.begin(); for (; it != products_.end(); ++it) { BrowserDistribution* dist = it->get()->distribution(); - key_files.push_back(remove_dir.Append(dist->GetKeyFile())); + std::vector<FilePath> dist_key_files(dist->GetKeyFiles()); + std::vector<FilePath>::const_iterator key_file_iter( + dist_key_files.begin()); + for (; key_file_iter != dist_key_files.end(); ++key_file_iter) { + key_files.push_back(remove_dir.Append(*key_file_iter)); + } } VLOG(1) << "Deleting directory: " << remove_dir.value(); diff --git a/chrome/installer/util/package_unittest.cc b/chrome/installer/util/package_unittest.cc index 575716d..8512a71 100644 --- a/chrome/installer/util/package_unittest.cc +++ b/chrome/installer/util/package_unittest.cc @@ -6,6 +6,7 @@ #include "base/scoped_handle.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/google_update_constants.h" +#include "chrome/installer/util/master_preferences.h" #include "chrome/installer/util/package.h" #include "chrome/installer/util/product.h" #include "chrome/installer/util/product_unittest.h" @@ -86,15 +87,18 @@ TEST_F(PackageTest, Basic) { TEST_F(PackageTest, WithProduct) { TempRegKeyOverride::DeleteAllTempKeys(); + const installer_util::MasterPreferences& prefs = + installer_util::MasterPreferences::ForCurrentProcess(); + // TODO(tommi): We should mock this and use our mocked distribution. const bool system_level = true; BrowserDistribution* distribution = BrowserDistribution::GetSpecificDistribution( - BrowserDistribution::CHROME_BROWSER); + BrowserDistribution::CHROME_BROWSER, prefs); scoped_refptr<Package> package(new Package(test_dir_.path())); scoped_refptr<Product> product(new Product(distribution, - system_level, - package.get())); + system_level, + package.get())); EXPECT_EQ(1U, package->products().size()); EXPECT_EQ(system_level, package->system_level()); diff --git a/chrome/installer/util/product.cc b/chrome/installer/util/product.cc index 60846e3..7560cd0 100644 --- a/chrome/installer/util/product.cc +++ b/chrome/installer/util/product.cc @@ -24,21 +24,21 @@ using installer_util::MasterPreferences; namespace { class ProductIsOfType { public: - explicit ProductIsOfType(BrowserDistribution::DistributionType type) + explicit ProductIsOfType(BrowserDistribution::Type type) : type_(type) { } bool operator()( const scoped_refptr<const installer::Product>& pi) const { return pi->distribution()->GetType() == type_; } private: - BrowserDistribution::DistributionType type_; + BrowserDistribution::Type type_; }; // class ProductIsOfType } // end namespace namespace installer { const Product* FindProduct(const Products& products, - BrowserDistribution::DistributionType type) { + BrowserDistribution::Type type) { Products::const_iterator i = std::find_if(products.begin(), products.end(), ProductIsOfType(type)); return i == products.end() ? NULL : *i; @@ -129,7 +129,7 @@ bool Product::IsMsi() const { msi_ = NOT_MSI; // Covers failure cases below. const MasterPreferences& prefs = - InstallUtil::GetMasterPreferencesForCurrentProcess(); + installer_util::MasterPreferences::ForCurrentProcess(); bool is_msi = false; prefs.GetBool(installer_util::master_preferences::kMsi, &is_msi); @@ -251,9 +251,10 @@ bool ProductPackageMapping::AddDistribution(BrowserDistribution* distribution) { } bool ProductPackageMapping::AddDistribution( - BrowserDistribution::DistributionType type) { + BrowserDistribution::Type type, + const installer_util::MasterPreferences& prefs) { BrowserDistribution* distribution = - BrowserDistribution::GetSpecificDistribution(type); + BrowserDistribution::GetSpecificDistribution(type, prefs); if (!distribution) { NOTREACHED(); return false; diff --git a/chrome/installer/util/product.h b/chrome/installer/util/product.h index 639e48a..49a375e 100644 --- a/chrome/installer/util/product.h +++ b/chrome/installer/util/product.h @@ -14,6 +14,10 @@ class CommandLine; +namespace installer_util { +class MasterPreferences; +} + namespace installer { class Product; @@ -24,7 +28,7 @@ typedef std::vector<scoped_refptr<Package> > Packages; typedef std::vector<scoped_refptr<const Product> > Products; const Product* FindProduct(const Products& products, - BrowserDistribution::DistributionType type); + BrowserDistribution::Type type); // Calls WriteInstallerResult for each Product object. void WriteInstallerResult(const Products& products, @@ -134,7 +138,8 @@ class ProductPackageMapping { const Products& products() const; - bool AddDistribution(BrowserDistribution::DistributionType type); + bool AddDistribution(BrowserDistribution::Type type, + const installer_util::MasterPreferences& prefs); bool AddDistribution(BrowserDistribution* distribution); protected: diff --git a/chrome/installer/util/product_unittest.cc b/chrome/installer/util/product_unittest.cc index 7dab702..20988e4 100644 --- a/chrome/installer/util/product_unittest.cc +++ b/chrome/installer/util/product_unittest.cc @@ -8,6 +8,7 @@ #include "base/scoped_handle.h" #include "chrome/installer/util/chrome_frame_distribution.h" #include "chrome/installer/util/google_update_constants.h" +#include "chrome/installer/util/master_preferences.h" #include "chrome/installer/util/product.h" using base::win::RegKey; @@ -16,6 +17,7 @@ using installer::Package; using installer::Product; using installer::ProductPackageMapping; using installer::Version; +using installer_util::MasterPreferences; void TestWithTempDir::SetUp() { // Name a subdirectory of the user temp directory. @@ -76,9 +78,11 @@ class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys { TEST_F(ProductTest, ProductInstallBasic) { // TODO(tommi): We should mock this and use our mocked distribution. const bool system_level = true; + const installer_util::MasterPreferences& prefs = + installer_util::MasterPreferences::ForCurrentProcess(); BrowserDistribution* distribution = BrowserDistribution::GetSpecificDistribution( - BrowserDistribution::CHROME_BROWSER); + BrowserDistribution::CHROME_BROWSER, prefs); scoped_refptr<Package> package(new Package(test_dir_.path())); scoped_refptr<Product> product(new Product(distribution, system_level, package.get())); @@ -156,9 +160,14 @@ TEST_F(ProductTest, LaunchChrome) { // the Chrome (not Chrome Frame) installation path. class FakeChromeFrameDistribution : public ChromeFrameDistribution { public: + explicit FakeChromeFrameDistribution( + const installer_util::MasterPreferences& prefs) + : ChromeFrameDistribution(prefs) {} virtual std::wstring GetInstallSubDir() { + const MasterPreferences& prefs = + installer_util::MasterPreferences::ForCurrentProcess(); return BrowserDistribution::GetSpecificDistribution( - BrowserDistribution::CHROME_BROWSER)->GetInstallSubDir(); + BrowserDistribution::CHROME_BROWSER, prefs)->GetInstallSubDir(); } }; @@ -169,8 +178,12 @@ TEST_F(ProductTest, ProductInstallsBasic) { EXPECT_EQ(0U, installs.packages().size()); EXPECT_EQ(0U, installs.products().size()); - installs.AddDistribution(BrowserDistribution::CHROME_BROWSER); - FakeChromeFrameDistribution fake_chrome_frame; + // TODO(robertshield): Include test that use mock master preferences. + const MasterPreferences& prefs = + installer_util::MasterPreferences::ForCurrentProcess(); + + installs.AddDistribution(BrowserDistribution::CHROME_BROWSER, prefs); + FakeChromeFrameDistribution fake_chrome_frame(prefs); installs.AddDistribution(&fake_chrome_frame); EXPECT_EQ(2U, installs.products().size()); // Since our fake Chrome Frame distribution class is reporting the same diff --git a/chrome/installer/util/util_constants.cc b/chrome/installer/util/util_constants.cc index 3b1d651..961b878 100644 --- a/chrome/installer/util/util_constants.cc +++ b/chrome/installer/util/util_constants.cc @@ -132,6 +132,8 @@ const char kToastResultsKey[] = "toast-results-key"; } // namespace switches const wchar_t kCeeeBrokerExe[] = L"ceee_broker.exe"; +const wchar_t kCeeeIeDll[] = L"ceee_ie.dll"; +const wchar_t kCeeeInstallHelperDll[] = L"ceee_installer_helper.dll"; const wchar_t kChromeDll[] = L"chrome.dll"; const wchar_t kChromeExe[] = L"chrome.exe"; const wchar_t kChromeFrameDll[] = L"npchrome_frame.dll"; diff --git a/chrome/installer/util/util_constants.h b/chrome/installer/util/util_constants.h index 3cd21b0..c1ee5a8 100644 --- a/chrome/installer/util/util_constants.h +++ b/chrome/installer/util/util_constants.h @@ -88,6 +88,8 @@ extern const char kToastResultsKey[]; } // namespace switches extern const wchar_t kCeeeBrokerExe[]; +extern const wchar_t kCeeeIeDll[]; +extern const wchar_t kCeeeInstallHelperDll[]; extern const wchar_t kChromeDll[]; extern const wchar_t kChromeExe[]; extern const wchar_t kChromeFrameDll[]; |