diff options
author | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-04 21:24:42 +0000 |
---|---|---|
committer | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-04 21:24:42 +0000 |
commit | ac9e9f1d7a2ec0ff5f2b764b6bec9956afcd62a4 (patch) | |
tree | 08df3256c59fe53e87b70886ba76f913d7c53218 | |
parent | 94610a491a3a8989a5774d62da0a6a18688b6627 (diff) | |
download | chromium_src-ac9e9f1d7a2ec0ff5f2b764b6bec9956afcd62a4.zip chromium_src-ac9e9f1d7a2ec0ff5f2b764b6bec9956afcd62a4.tar.gz chromium_src-ac9e9f1d7a2ec0ff5f2b764b6bec9956afcd62a4.tar.bz2 |
Read multi-install chrome's channel from the binaries.
BUG=380828
R=robertshield@chromium.org
Review URL: https://codereview.chromium.org/316103002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274909 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/installer/util/google_update_settings.cc | 40 | ||||
-rw-r--r-- | chrome/installer/util/google_update_settings_unittest.cc | 54 |
2 files changed, 80 insertions, 14 deletions
diff --git a/chrome/installer/util/google_update_settings.cc b/chrome/installer/util/google_update_settings.cc index 7168412..94b7994 100644 --- a/chrome/installer/util/google_update_settings.cc +++ b/chrome/installer/util/google_update_settings.cc @@ -134,29 +134,41 @@ bool GetChromeChannelInternal(bool system_install, bool add_multi_modifier, base::string16* channel) { BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - if (dist->GetChromeChannel(channel)) { - return true; - } - HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; - base::string16 reg_path = dist->GetStateKey(); - RegKey key(root_key, reg_path.c_str(), KEY_READ | KEY_WOW64_32KEY); + // Shortcut in case this distribution knows what channel it is (canary). + if (dist->GetChromeChannel(channel)) + return true; + // Determine whether or not chrome is multi-install. If so, updates are + // delivered under the binaries' app guid, so that's where the relevant + // channel is found. + installer::ProductState state; installer::ChannelInfo channel_info; - if (!channel_info.Initialize(key)) { - channel->assign(installer::kChromeChannelUnknown); - return false; + ignore_result(state.Initialize(system_install, dist)); + if (!state.is_multi_install()) { + // Use the channel info that was just read for this single-install chrome. + channel_info = state.channel(); + } else { + // Read the channel info from the binaries' state key. + HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + dist = BrowserDistribution::GetSpecificDistribution( + BrowserDistribution::CHROME_BINARIES); + RegKey key(root_key, dist->GetStateKey().c_str(), + KEY_READ | KEY_WOW64_32KEY); + + if (!channel_info.Initialize(key)) { + channel->assign(installer::kChromeChannelUnknown); + return false; + } } - if (!channel_info.GetChannelName(channel)) { + if (!channel_info.GetChannelName(channel)) channel->assign(installer::kChromeChannelUnknown); - } // Tag the channel name if this is a multi-install. - if (add_multi_modifier && channel_info.IsMultiInstall()) { - if (!channel->empty()) { + if (add_multi_modifier && state.is_multi_install()) { + if (!channel->empty()) channel->push_back(L'-'); - } channel->push_back(L'm'); } diff --git a/chrome/installer/util/google_update_settings_unittest.cc b/chrome/installer/util/google_update_settings_unittest.cc index 71c0262..f3ddafc6 100644 --- a/chrome/installer/util/google_update_settings_unittest.cc +++ b/chrome/installer/util/google_update_settings_unittest.cc @@ -54,6 +54,37 @@ class GoogleUpdateSettingsTest : public testing::Test { ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); } + // Sets the "ap" field for a multi-install product (both the product and + // the binaries). + void SetMultiApField(SystemUserInstall is_system, const wchar_t* value) { + // Caller must specify a multi-install ap value. + ASSERT_NE(std::wstring::npos, std::wstring(value).find(L"-multi")); + HKEY root = is_system == SYSTEM_INSTALL ? + HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + RegKey update_key; + + // Write the ap value for both the product and the binaries. + BrowserDistribution* const kDists[] = { + BrowserDistribution::GetDistribution(), + BrowserDistribution::GetSpecificDistribution( + BrowserDistribution::CHROME_BINARIES) + }; + for (size_t i = 0; i < arraysize(kDists); ++i) { + std::wstring path = kDists[i]->GetStateKey(); + ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), + KEY_WRITE)); + ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); + } + + // Make the product technically multi-install. + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); + ASSERT_EQ(ERROR_SUCCESS, + update_key.Create(root, dist->GetStateKey().c_str(), KEY_WRITE)); + ASSERT_EQ(ERROR_SUCCESS, + update_key.WriteValue(installer::kUninstallArgumentsField, + L"--multi-install")); + } + // Tests setting the ap= value to various combinations of values with // prefixes and suffixes, while asserting on the correct channel value. // Note that any non-empty ap= value that doesn't match ".*-{dev|beta}.*" @@ -310,6 +341,29 @@ TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelEmptyUser) { EXPECT_STREQ(L"", channel.c_str()); } +// Test that the channel is pulled from the binaries for multi-install products. +TEST_F(GoogleUpdateSettingsTest, MultiInstallChannelFromBinaries) { + SetMultiApField(USER_INSTALL, L"2.0-dev-multi-chrome"); + base::string16 channel; + + EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, + &channel)); + EXPECT_STREQ(L"dev-m", channel.c_str()); + + // See if the same happens if the product's ap is cleared. + SetApField(USER_INSTALL, L""); + EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, + &channel)); + EXPECT_STREQ(L"dev-m", channel.c_str()); + + // Test the converse (binaries are stable, Chrome is other). + SetMultiApField(USER_INSTALL, L"-multi-chrome"); + SetApField(USER_INSTALL, L"2.0-dev-multi-chrome"); + EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, + &channel)); + EXPECT_STREQ(L"m", channel.c_str()); +} + TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) { TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL); } |