diff options
Diffstat (limited to 'chrome/installer/util')
-rw-r--r-- | chrome/installer/util/package.cc | 44 | ||||
-rw-r--r-- | chrome/installer/util/package.h | 7 | ||||
-rw-r--r-- | chrome/installer/util/package_unittest.cc | 48 |
3 files changed, 94 insertions, 5 deletions
diff --git a/chrome/installer/util/package.cc b/chrome/installer/util/package.cc index 68e1a33..c2fff7b 100644 --- a/chrome/installer/util/package.cc +++ b/chrome/installer/util/package.cc @@ -8,12 +8,16 @@ #include "base/logging.h" #include "base/utf_string_conversions.h" #include "base/win/registry.h" +#include "chrome/installer/util/channel_info.h" #include "chrome/installer/util/delete_tree_work_item.h" #include "chrome/installer/util/google_update_constants.h" +#include "chrome/installer/util/master_preferences.h" #include "chrome/installer/util/package_properties.h" #include "chrome/installer/util/product.h" using base::win::RegKey; +using installer::ChannelInfo; +using installer::MasterPreferences; namespace installer { @@ -139,5 +143,45 @@ void Package::RemoveOldVersionDirectories( } } +size_t Package::GetMultiInstallDependencyCount() const { + BrowserDistribution::Type product_types[] = { + BrowserDistribution::CHROME_BROWSER, + BrowserDistribution::CHROME_FRAME, + }; + + const MasterPreferences& prefs = MasterPreferences::ForCurrentProcess(); + HKEY root_key = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + + size_t ret = 0; + + for (int i = 0; i < arraysize(product_types); ++i) { + BrowserDistribution* dist = + BrowserDistribution::GetSpecificDistribution(product_types[i], prefs); + // First see if the product is installed by checking its version key. + // If the key doesn't exist, the product isn't installed. + RegKey version_key(root_key, dist->GetVersionKey().c_str(), KEY_READ); + if (!version_key.Valid()) { + VLOG(1) << "Product not installed: " << dist->GetApplicationName(); + } else { + RegKey key(root_key, dist->GetStateKey().c_str(), KEY_READ); + ChannelInfo channel_info; + if (channel_info.Initialize(key)) { + if (channel_info.IsMultiInstall()) { + VLOG(1) << "Product dependency: " << dist->GetApplicationName(); + ret++; + } else { + VLOG(1) << "Product is installed, but not multi: " + << dist->GetApplicationName(); + } + } else { + LOG(INFO) << "Product missing 'ap' value: " + << dist->GetApplicationName(); + } + } + } + + return ret; +} + } // namespace installer diff --git a/chrome/installer/util/package.h b/chrome/installer/util/package.h index d89baa6..c673825 100644 --- a/chrome/installer/util/package.h +++ b/chrome/installer/util/package.h @@ -61,6 +61,13 @@ class Package : public base::RefCounted<Package> { // latest_version: the latest version of Chrome installed. void RemoveOldVersionDirectories(const Version& latest_version) const; + // Returns how many installed products depend on the binaries currently + // in the installation path. + // Note: The function counts only products that are installed as part of + // a multi install installation and only products that have the same + // system_level() value. + size_t GetMultiInstallDependencyCount() const; + protected: bool system_level_; FilePath path_; diff --git a/chrome/installer/util/package_unittest.cc b/chrome/installer/util/package_unittest.cc index b553a46..f1eda9c 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 "base/utf_string_conversions.h" #include "chrome/installer/util/browser_distribution.h" +#include "chrome/installer/util/channel_info.h" #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/master_preferences.h" #include "chrome/installer/util/package.h" @@ -16,10 +17,12 @@ using base::win::RegKey; using base::win::ScopedHandle; +using installer::ChannelInfo; using installer::ChromePackageProperties; using installer::ChromiumPackageProperties; using installer::Package; using installer::Product; +using installer::MasterPreferences; class PackageTest : public TestWithTempDirAndDeleteTempOverrideKeys { protected: @@ -92,10 +95,7 @@ TEST_F(PackageTest, Basic) { } TEST_F(PackageTest, WithProduct) { - TempRegKeyOverride::DeleteAllTempKeys(); - - const installer::MasterPreferences& prefs = - installer::MasterPreferences::ForCurrentProcess(); + const MasterPreferences& prefs = MasterPreferences::ForCurrentProcess(); // TODO(tommi): We should mock this and use our mocked distribution. const bool system_level = true; @@ -130,6 +130,44 @@ TEST_F(PackageTest, WithProduct) { } } } +} + +TEST_F(PackageTest, Dependency) { + const bool system_level = true; + HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + TempRegKeyOverride override(root, L"root_dep"); - TempRegKeyOverride::DeleteAllTempKeys(); + ChromePackageProperties properties; + scoped_refptr<Package> package(new Package(system_level, test_dir_.path(), + &properties)); + EXPECT_EQ(0U, package->GetMultiInstallDependencyCount()); + + const MasterPreferences& prefs = MasterPreferences::ForCurrentProcess(); + + BrowserDistribution* chrome = BrowserDistribution::GetSpecificDistribution( + BrowserDistribution::CHROME_BROWSER, prefs); + BrowserDistribution* cf = BrowserDistribution::GetSpecificDistribution( + BrowserDistribution::CHROME_FRAME, prefs); + + // "install" Chrome. + RegKey chrome_version_key(root, chrome->GetVersionKey().c_str(), + KEY_ALL_ACCESS); + RegKey chrome_key(root, chrome->GetStateKey().c_str(), KEY_ALL_ACCESS); + ChannelInfo channel; + channel.set_value(L""); + channel.SetMultiInstall(true); + channel.Write(&chrome_key); + EXPECT_EQ(1U, package->GetMultiInstallDependencyCount()); + + // "install" Chrome Frame without multi-install. + RegKey cf_version_key(root, cf->GetVersionKey().c_str(), KEY_ALL_ACCESS); + RegKey cf_key(root, cf->GetStateKey().c_str(), KEY_ALL_ACCESS); + channel.SetMultiInstall(false); + channel.Write(&cf_key); + EXPECT_EQ(1U, package->GetMultiInstallDependencyCount()); + + // "install" Chrome Frame with multi-install. + channel.SetMultiInstall(true); + channel.Write(&cf_key); + EXPECT_EQ(2U, package->GetMultiInstallDependencyCount()); } |