diff options
-rw-r--r-- | ceee/installer_dll/installer_helper.cc | 66 | ||||
-rw-r--r-- | chrome/chrome_installer.gypi | 1 | ||||
-rw-r--r-- | chrome/chrome_installer_util.gypi | 2 | ||||
-rw-r--r-- | chrome/installer/util/channel_info.cc | 128 | ||||
-rw-r--r-- | chrome/installer/util/channel_info.h | 73 | ||||
-rw-r--r-- | chrome/installer/util/channel_info_unittest.cc | 151 | ||||
-rw-r--r-- | chrome/installer/util/google_update_settings.cc | 78 | ||||
-rw-r--r-- | chrome/installer/util/google_update_settings.h | 13 | ||||
-rw-r--r-- | chrome/installer/util/google_update_settings_unittest.cc | 153 | ||||
-rw-r--r-- | chrome_frame/utils.cc | 4 |
10 files changed, 510 insertions, 159 deletions
diff --git a/ceee/installer_dll/installer_helper.cc b/ceee/installer_dll/installer_helper.cc index 01f5bd4..a435e17 100644 --- a/ceee/installer_dll/installer_helper.cc +++ b/ceee/installer_dll/installer_helper.cc @@ -18,6 +18,7 @@ #include "ceee/ie/common/ceee_module_util.h" #include "chrome/common/zip.h" #include "chrome/installer/mini_installer/pe_resource.h" +#include "chrome/installer/util/channel_info.h" #include "chrome/installer/util/google_update_constants.h" class InstallerHelperModule : public CAtlDllModuleT<InstallerHelperModule> { @@ -250,72 +251,29 @@ HRESULT RegisterFirefoxCeee(bool do_register) { return hr; } -const wchar_t kCeeeChannelTag[] = L"-CEEE"; - -const HKEY reg_root = HKEY_LOCAL_MACHINE; - -// Registers this install as coming from the CEEE+CF channel if it was -// installed using Omaha. -HRESULT RegisterCeeeChannel() { +// Registers or unregisters this install as coming from the CEEE+CF channel if +// it was installed using Omaha. +HRESULT SetCeeeChannelModifier(bool new_value) { std::wstring reg_key(ceee_module_util::GetCromeFrameClientStateKey()); base::win::RegKey key; - if (!key.Open(reg_root, reg_key.c_str(), KEY_ALL_ACCESS)) { + if (!key.Open(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_ALL_ACCESS)) { // Omaha didn't install the key. Perhaps no Omaha? That's ok. return S_OK; } - std::wstring ap_key_value; - if (!key.ReadValue(google_update::kRegApField, &ap_key_value)) { - // Key doesn't exist yet. - if (!key.WriteValue(google_update::kRegApField, kCeeeChannelTag)) { - return E_FAIL; - } - return S_OK; - } + // We create the "ap" value if it doesn't exist. + installer_util::ChannelInfo channel_info; + channel_info.Initialize(key); - if (ap_key_value.find(kCeeeChannelTag) == std::wstring::npos) { - // Key doesn't contain -CEEE - ap_key_value.append(kCeeeChannelTag); - if (!key.WriteValue(google_update::kRegApField, ap_key_value.c_str())) { - return E_FAIL; - } - return S_OK; + if (channel_info.SetCeee(new_value) && !channel_info.Write(&key)) { + return E_FAIL; } // Everything we need is already done! return S_OK; } -// Removes any registration information written by RegisterCeeeChannel. -HRESULT UnregisterCeeeChannel() { - std::wstring reg_key(ceee_module_util::GetCromeFrameClientStateKey()); - base::win::RegKey key; - if (!key.Open(reg_root, reg_key.c_str(), KEY_ALL_ACCESS)) { - // Omaha didn't install the key. - return S_OK; - } - - std::wstring ap_key_value; - if (!key.ReadValue(google_update::kRegApField, &ap_key_value)) { - // Key doesn't exist. Nothing to do. - return S_OK; - } - - size_t pos = ap_key_value.find(kCeeeChannelTag); - - if (pos == std::wstring::npos) { - // Key doesn't contain -CEEE. Nothing to do. - return S_OK; - } - - // Prune -CEEE from ap and write it. - ap_key_value.erase(pos, wcslen(kCeeeChannelTag)); - if (!key.WriteValue(google_update::kRegApField, ap_key_value.c_str())) { - return E_FAIL; - } - return S_OK; -} } // namespace @@ -381,7 +339,7 @@ STDAPI DllRegisterServerImpl(void) { } if (SUCCEEDED(hr)) { - hr = RegisterCeeeChannel(); + hr = SetCeeeChannelModifier(true); DCHECK(SUCCEEDED(hr)) << "Could not register with Omaha for CEEE+CF channel" << com::LogHr(hr); } @@ -424,7 +382,7 @@ STDAPI DllUnregisterServer(void) { DCHECK(SUCCEEDED(hr)) << "Unable to extract CEEE for FF" << com::LogHr(hr); AggregateComError(hr, &combined_result); - hr = UnregisterCeeeChannel(); + hr = SetCeeeChannelModifier(false); DCHECK(SUCCEEDED(hr)) << "Could not unregister with Omaha for corp channel" << com::LogHr(hr); AggregateComError(hr, &combined_result); diff --git a/chrome/chrome_installer.gypi b/chrome/chrome_installer.gypi index 468c95d..80cf38d 100644 --- a/chrome/chrome_installer.gypi +++ b/chrome/chrome_installer.gypi @@ -77,6 +77,7 @@ 'installer/setup/compat_checks_unittest.cc', 'installer/setup/setup_constants.cc', 'installer/util/browser_distribution_unittest.cc', + 'installer/util/channel_info_unittest.cc', 'installer/util/copy_tree_work_item_unittest.cc', 'installer/util/create_dir_work_item_unittest.cc', 'installer/util/create_reg_key_work_item_unittest.cc', diff --git a/chrome/chrome_installer_util.gypi b/chrome/chrome_installer_util.gypi index 2c922cd..2842eb3 100644 --- a/chrome/chrome_installer_util.gypi +++ b/chrome/chrome_installer_util.gypi @@ -13,6 +13,8 @@ 'sources': [ 'installer/util/browser_distribution.cc', 'installer/util/browser_distribution.h', + 'installer/util/channel_info.cc', + 'installer/util/channel_info.h', 'installer/util/chrome_frame_distribution.cc', 'installer/util/chrome_frame_distribution.h', 'installer/util/copy_tree_work_item.cc', diff --git a/chrome/installer/util/channel_info.cc b/chrome/installer/util/channel_info.cc new file mode 100644 index 0000000..4025cb9 --- /dev/null +++ b/chrome/installer/util/channel_info.cc @@ -0,0 +1,128 @@ +// Copyright (c) 2010 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/channel_info.h" + +#include "base/logging.h" +#include "base/win/registry.h" +#include "chrome/installer/util/google_update_constants.h" + +using base::win::RegKey; + +namespace { + +const wchar_t kChannelBeta[] = L"beta"; +const wchar_t kChannelDev[] = L"dev"; +const wchar_t kModCeee[] = L"-CEEE"; +const wchar_t kModFullInstall[] = L"-full"; +const wchar_t kModMultiInstall[] = L"-multi"; + +const wchar_t* const kChannels[] = { + kChannelBeta, + kChannelDev +}; + +const wchar_t* const kModifiers[] = { + kModCeee, + kModFullInstall, + kModMultiInstall +}; + +} // namespace + +namespace installer_util { + +// static +bool ChannelInfo::HasModifier(const wchar_t* modifier, + const std::wstring& ap_value) { + DCHECK(modifier); + return ap_value.find(modifier) != std::wstring::npos; +} + +// Returns true if |ap_value| is modified. +// static +bool ChannelInfo::SetModifier(const wchar_t* modifier, + bool set, + std::wstring* ap_value) { + DCHECK(modifier); + DCHECK(ap_value); + std::wstring::size_type position = ap_value->find(modifier); + if (set) { + if (position == std::wstring::npos) { + ap_value->append(modifier); + return true; + } + } else { + if (position != std::wstring::npos) { + ap_value->erase(position, std::wstring::traits_type::length(modifier)); + return true; + } + } + return false; +} + +bool ChannelInfo::Initialize(const RegKey& key) { + return key.ReadValue(google_update::kRegApField, &value_); +} + +bool ChannelInfo::Write(RegKey* key) const { + return key->WriteValue(google_update::kRegApField, value_.c_str()); +} + +bool ChannelInfo::GetChannelName(std::wstring* channel_name) const { + DCHECK(channel_name); + if (value_.empty()) { + channel_name->erase(); + return true; + } else { + for (const wchar_t* const* scan = &kChannels[0], + *const* end = &kChannels[arraysize(kChannels)]; scan != end; + ++scan) { + if (value_.find(*scan) != std::wstring::npos) { + channel_name->assign(*scan); + return true; + } + } + // There may be modifiers present. Strip them off and see if we're left + // with the empty string (stable channel). + std::wstring tmp_value = value_; + for (const wchar_t* const* scan = &kModifiers[0], + *const *end = &kModifiers[arraysize(kModifiers)]; scan != end; + ++scan) { + SetModifier(*scan, false, &tmp_value); + } + if (tmp_value.empty()) { + channel_name->erase(); + return true; + } + } + + return false; +} + +bool ChannelInfo::IsCeee() const { + return HasModifier(kModCeee, value_); +} + +bool ChannelInfo::SetCeee(bool value) { + return SetModifier(kModCeee, value, &value_); +} + +bool ChannelInfo::IsFullInstall() const { + return HasModifier(kModFullInstall, value_); +} + +bool ChannelInfo::SetFullInstall(bool value) { + return SetModifier(kModFullInstall, value, &value_); +} + +bool ChannelInfo::IsMultiInstall() const { + return HasModifier(kModMultiInstall, value_); +} + +bool ChannelInfo::SetMultiInstall(bool value) { + return SetModifier(kModMultiInstall, value, &value_); +} + +} // namespace installer_util diff --git a/chrome/installer/util/channel_info.h b/chrome/installer/util/channel_info.h new file mode 100644 index 0000000..bfee20f --- /dev/null +++ b/chrome/installer/util/channel_info.h @@ -0,0 +1,73 @@ +// Copyright (c) 2010 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_CHANNEL_INFO_H_ +#define CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_ +#pragma once + +#include <string> + +namespace base { +namespace win { +class RegKey; +} +} + +namespace installer_util { + +// A helper class for parsing and modifying the Omaha additional parameter +// ("ap") client state value for a product. +class ChannelInfo { + public: + + // Initialize an instance from the "ap" value in a given registry key. + // Returns false if the value could not be read from the registry. + bool Initialize(const base::win::RegKey& key); + + // Writes the info to the "ap" value in a given registry key. + // Returns false if the value could not be written to the registry. + bool Write(base::win::RegKey* key) const; + + const std::wstring& value() const { return value_; } + void set_value(const std::wstring& value) { value_ = value; } + + // Determines the update channel for the value. Possible |channel_name| + // results are the empty string (stable channel), "beta", and "dev". Returns + // false (without modifying |channel_name|) if the channel could not be + // determined. + bool GetChannelName(std::wstring* channel_name) const; + + // Returns true if the -CEEE modifier is present in the value. + bool IsCeee() const; + + // Adds or removes the -CEEE modifier, returning true if the value is + // modified. + bool SetCeee(bool value); + + // Returns true if the -full modifier is present in the value. + bool IsFullInstall() const; + + // Adds or removes the -full modifier, returning true if the value is + // modified. + bool SetFullInstall(bool value); + + // Returns true if the -multi modifier is present in the value. + bool IsMultiInstall() const; + + // Adds or removes the -multi modifier, returning true if the value is + // modified. + bool SetMultiInstall(bool value); + + private: + static bool HasModifier(const wchar_t* modifier, + const std::wstring& ap_value); + static bool SetModifier(const wchar_t* modifier, bool set, + std::wstring* ap_value); + + std::wstring value_; +}; // class ChannelInfo + +} // namespace installer_util + +#endif // CHROME_INSTALLER_UTIL_CHANNEL_INFO_H_ diff --git a/chrome/installer/util/channel_info_unittest.cc b/chrome/installer/util/channel_info_unittest.cc new file mode 100644 index 0000000..ac3350e --- /dev/null +++ b/chrome/installer/util/channel_info_unittest.cc @@ -0,0 +1,151 @@ +// Copyright (c) 2010 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/channel_info.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +const std::wstring kChannelStable; +const std::wstring kChannelBeta(L"beta"); +const std::wstring kChannelDev(L"dev"); + +} // namespace + +TEST(ChannelInfoTest, Channels) { + installer_util::ChannelInfo ci; + std::wstring channel; + + ci.set_value(L""); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelStable, channel); + ci.set_value(L"-CEEE"); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelStable, channel); + ci.set_value(L"-CEEE-multi"); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelStable, channel); + ci.set_value(L"-full"); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelStable, channel); + + ci.set_value(L"2.0-beta"); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelBeta, channel); + ci.set_value(L"2.0-beta-spam"); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelBeta, channel); + ci.set_value(L"2.0-spam-beta"); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelBeta, channel); + + ci.set_value(L"2.0-dev"); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelDev, channel); + ci.set_value(L"2.0-kinda-dev"); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelDev, channel); + ci.set_value(L"2.0-dev-eloper"); + EXPECT_TRUE(ci.GetChannelName(&channel)); + EXPECT_EQ(kChannelDev, channel); + + ci.set_value(L"fuzzy"); + EXPECT_FALSE(ci.GetChannelName(&channel)); +} + +TEST(ChannelInfoTest, CEEE) { + installer_util::ChannelInfo ci; + + ci.set_value(L""); + EXPECT_TRUE(ci.SetCeee(true)); + EXPECT_TRUE(ci.IsCeee()); + EXPECT_EQ(L"-CEEE", ci.value()); + EXPECT_FALSE(ci.SetCeee(true)); + EXPECT_TRUE(ci.IsCeee()); + EXPECT_EQ(L"-CEEE", ci.value()); + EXPECT_TRUE(ci.SetCeee(false)); + EXPECT_FALSE(ci.IsCeee()); + EXPECT_EQ(L"", ci.value()); + EXPECT_FALSE(ci.SetCeee(false)); + EXPECT_FALSE(ci.IsCeee()); + EXPECT_EQ(L"", ci.value()); + + ci.set_value(L"2.0-beta"); + EXPECT_TRUE(ci.SetCeee(true)); + EXPECT_TRUE(ci.IsCeee()); + EXPECT_EQ(L"2.0-beta-CEEE", ci.value()); + EXPECT_FALSE(ci.SetCeee(true)); + EXPECT_TRUE(ci.IsCeee()); + EXPECT_EQ(L"2.0-beta-CEEE", ci.value()); + EXPECT_TRUE(ci.SetCeee(false)); + EXPECT_FALSE(ci.IsCeee()); + EXPECT_EQ(L"2.0-beta", ci.value()); + EXPECT_FALSE(ci.SetCeee(false)); + EXPECT_FALSE(ci.IsCeee()); + EXPECT_EQ(L"2.0-beta", ci.value()); +} + +TEST(ChannelInfoTest, FullInstall) { + installer_util::ChannelInfo ci; + + ci.set_value(L""); + EXPECT_TRUE(ci.SetFullInstall(true)); + EXPECT_TRUE(ci.IsFullInstall()); + EXPECT_EQ(L"-full", ci.value()); + EXPECT_FALSE(ci.SetFullInstall(true)); + EXPECT_TRUE(ci.IsFullInstall()); + EXPECT_EQ(L"-full", ci.value()); + EXPECT_TRUE(ci.SetFullInstall(false)); + EXPECT_FALSE(ci.IsFullInstall()); + EXPECT_EQ(L"", ci.value()); + EXPECT_FALSE(ci.SetFullInstall(false)); + EXPECT_FALSE(ci.IsFullInstall()); + EXPECT_EQ(L"", ci.value()); + + ci.set_value(L"2.0-beta"); + EXPECT_TRUE(ci.SetFullInstall(true)); + EXPECT_TRUE(ci.IsFullInstall()); + EXPECT_EQ(L"2.0-beta-full", ci.value()); + EXPECT_FALSE(ci.SetFullInstall(true)); + EXPECT_TRUE(ci.IsFullInstall()); + EXPECT_EQ(L"2.0-beta-full", ci.value()); + EXPECT_TRUE(ci.SetFullInstall(false)); + EXPECT_FALSE(ci.IsFullInstall()); + EXPECT_EQ(L"2.0-beta", ci.value()); + EXPECT_FALSE(ci.SetFullInstall(false)); + EXPECT_FALSE(ci.IsFullInstall()); + EXPECT_EQ(L"2.0-beta", ci.value()); +} + +TEST(ChannelInfoTest, MultiInstall) { + installer_util::ChannelInfo ci; + + ci.set_value(L""); + EXPECT_TRUE(ci.SetMultiInstall(true)); + EXPECT_TRUE(ci.IsMultiInstall()); + EXPECT_EQ(L"-multi", ci.value()); + EXPECT_FALSE(ci.SetMultiInstall(true)); + EXPECT_TRUE(ci.IsMultiInstall()); + EXPECT_EQ(L"-multi", ci.value()); + EXPECT_TRUE(ci.SetMultiInstall(false)); + EXPECT_FALSE(ci.IsMultiInstall()); + EXPECT_EQ(L"", ci.value()); + EXPECT_FALSE(ci.SetMultiInstall(false)); + EXPECT_FALSE(ci.IsMultiInstall()); + EXPECT_EQ(L"", ci.value()); + + ci.set_value(L"2.0-beta"); + EXPECT_TRUE(ci.SetMultiInstall(true)); + EXPECT_TRUE(ci.IsMultiInstall()); + EXPECT_EQ(L"2.0-beta-multi", ci.value()); + EXPECT_FALSE(ci.SetMultiInstall(true)); + EXPECT_TRUE(ci.IsMultiInstall()); + EXPECT_EQ(L"2.0-beta-multi", ci.value()); + EXPECT_TRUE(ci.SetMultiInstall(false)); + EXPECT_FALSE(ci.IsMultiInstall()); + EXPECT_EQ(L"2.0-beta", ci.value()); + EXPECT_FALSE(ci.SetMultiInstall(false)); + EXPECT_FALSE(ci.IsMultiInstall()); + EXPECT_EQ(L"2.0-beta", ci.value()); +} diff --git a/chrome/installer/util/google_update_settings.cc b/chrome/installer/util/google_update_settings.cc index c542aac..e16e62a 100644 --- a/chrome/installer/util/google_update_settings.cc +++ b/chrome/installer/util/google_update_settings.cc @@ -14,6 +14,7 @@ #include "base/win/registry.h" #include "chrome/common/chrome_switches.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/install_util.h" @@ -164,26 +165,22 @@ bool GoogleUpdateSettings::GetChromeChannel(bool system_install, HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; std::wstring reg_path = dist->GetStateKey(); RegKey key(root_key, reg_path.c_str(), KEY_READ); - std::wstring update_branch; - if (!key.ReadValue(google_update::kRegApField, &update_branch)) { + installer_util::ChannelInfo channel_info; + if (!channel_info.Initialize(key)) { *channel = L"unknown"; return false; } - // Map to something pithy for human consumption. There are no rules as to - // what the ap string can contain, but generally it will contain a number - // followed by a dash followed by the branch name (and then some random - // suffix). We fall back on empty string in case we fail to parse. - // Only ever return "", "unknown", "dev" or "beta". - if (update_branch.find(L"-beta") != std::wstring::npos) - *channel = L"beta"; - else if (update_branch.find(L"-dev") != std::wstring::npos) - *channel = L"dev"; - else if (update_branch.empty()) - *channel = L""; - else + if (!channel_info.GetChannelName(channel)) *channel = L"unknown"; + // Tag the channel name if this is a multi-install product. + if (channel_info.IsMultiInstall()) { + if (!channel->empty()) + channel->append(1, L'-'); + channel->append(1, L'm'); + } + return true; } @@ -193,12 +190,12 @@ void GoogleUpdateSettings::UpdateDiffInstallStatus(bool system_install, HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; RegKey key; - std::wstring ap_key_value; + installer_util::ChannelInfo channel_info; std::wstring reg_key(google_update::kRegPathClientState); reg_key.append(L"\\"); reg_key.append(product_guid); if (!key.Open(reg_root, reg_key.c_str(), KEY_ALL_ACCESS) || - !key.ReadValue(google_update::kRegApField, &ap_key_value)) { + !channel_info.Initialize(key)) { VLOG(1) << "Application key not found."; if (!incremental_install || !install_return_code) { VLOG(1) << "Returning without changing application key."; @@ -215,39 +212,36 @@ void GoogleUpdateSettings::UpdateDiffInstallStatus(bool system_install, } } - std::wstring new_value = GetNewGoogleUpdateApKey( - incremental_install, install_return_code, ap_key_value); - if ((new_value.compare(ap_key_value) != 0) && - !key.WriteValue(google_update::kRegApField, new_value.c_str())) { - LOG(ERROR) << "Failed to write value " << new_value + if (UpdateGoogleUpdateApKey(incremental_install, install_return_code, + &channel_info) && + !channel_info.Write(&key)) { + LOG(ERROR) << "Failed to write value " << channel_info.value() << " to the registry field " << google_update::kRegApField; } key.Close(); } -std::wstring GoogleUpdateSettings::GetNewGoogleUpdateApKey( - bool diff_install, int install_return_code, const std::wstring& value) { - // Magic suffix that we need to add or remove to "ap" key value. - const std::wstring kMagicSuffix = L"-full"; - - bool has_magic_string = false; - if ((value.length() >= kMagicSuffix.length()) && - (value.rfind(kMagicSuffix) == (value.length() - kMagicSuffix.length()))) { - VLOG(1) << "Incremental installer failure key already set."; - has_magic_string = true; - } - - std::wstring new_value(value); - if ((!diff_install || !install_return_code) && has_magic_string) { - VLOG(1) << "Removing failure key from value " << value; - new_value = value.substr(0, value.length() - kMagicSuffix.length()); - } else if ((diff_install && install_return_code) && - !has_magic_string) { - VLOG(1) << "Incremental installer failed, setting failure key."; - new_value.append(kMagicSuffix); +bool GoogleUpdateSettings::UpdateGoogleUpdateApKey( + bool diff_install, int install_return_code, + installer_util::ChannelInfo* value) { + if (!diff_install || !install_return_code) { + if (value->SetFullInstall(false)) { + VLOG(1) << "Removed incremental installer failure key; new value: " + << value->value(); + return true; + } + } else if (diff_install && install_return_code) { + if (value->SetFullInstall(true)) { + VLOG(1) << "Incremental installer failed, setting failure key; " + "new value: " + << value->value(); + return true; + } else { + VLOG(1) << "Incremental installer failure key already set."; + } } - return new_value; + return false; } int GoogleUpdateSettings::DuplicateGoogleUpdateSystemClientKey() { diff --git a/chrome/installer/util/google_update_settings.h b/chrome/installer/util/google_update_settings.h index 715ef9f..e1b8fbb 100644 --- a/chrome/installer/util/google_update_settings.h +++ b/chrome/installer/util/google_update_settings.h @@ -10,6 +10,10 @@ #include "base/basictypes.h" +namespace installer_util { +class ChannelInfo; +} + // This class provides accessors to the Google Update 'ClientState' information // that recorded when the user downloads the chrome installer. It is // google_update.exe responsability to write the initial values. @@ -89,7 +93,7 @@ class GoogleUpdateSettings { int install_return_code, const std::wstring& product_guid); - // This method generates the new value for Google Update "ap" key for Chrome + // This method updates the value for Google Update "ap" key for Chrome // based on whether we are doing incremental install (or not) and whether // the install succeeded. // - If install worked, remove the magic string (if present). @@ -101,9 +105,10 @@ class GoogleUpdateSettings { // diff_install: tells whether this is incremental install or not. // install_return_code: if 0, means installation was successful. // value: current value of Google Update "ap" key. - static std::wstring GetNewGoogleUpdateApKey(bool diff_install, - int install_return_code, - const std::wstring& value); + // Returns true if |value| is modified. + static bool UpdateGoogleUpdateApKey(bool diff_install, + int install_return_code, + installer_util::ChannelInfo* value); // For system-level installs, we need to be able to communicate the results // of the Toast Experiments back to Google Update. The problem is just that diff --git a/chrome/installer/util/google_update_settings_unittest.cc b/chrome/installer/util/google_update_settings_unittest.cc index 75f15a8..519a1c8 100644 --- a/chrome/installer/util/google_update_settings_unittest.cc +++ b/chrome/installer/util/google_update_settings_unittest.cc @@ -3,11 +3,12 @@ // found in the LICENSE file. #include <windows.h> -#include <shlwapi.h> // For SHDeleteKey. +#include <shlwapi.h> // For SHDeleteKey. #include "base/scoped_ptr.h" #include "base/win/registry.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/google_update_settings.h" #include "chrome/installer/util/work_item_list.h" @@ -86,10 +87,10 @@ class GoogleUpdateSettingsTest: public testing::Test { const wchar_t* ap_value; const wchar_t* channel; } expectations[] = { - { L"dev", L"unknown" }, + { L"dev", L"dev" }, { L"-dev", L"dev" }, { L"-developer", L"dev" }, - { L"beta", L"unknown" }, + { L"beta", L"beta" }, { L"-beta", L"beta" }, { L"-betamax", L"beta" }, }; @@ -211,68 +212,110 @@ TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) { TestCurrentChromeChannelWithVariousApValues(USER_INSTALL); } -TEST_F(GoogleUpdateSettingsTest, GetNewGoogleUpdateApKeyTest) { +TEST_F(GoogleUpdateSettingsTest, UpdateGoogleUpdateApKey) { installer_util::InstallStatus s = installer_util::FIRST_INSTALL_SUCCESS; installer_util::InstallStatus f = installer_util::INSTALL_FAILED; // Incremental Installer that worked. - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L""), L""); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"1.1"), - L"1.1"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"1.1-dev"), - L"1.1-dev"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"-full"), - L""); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"1.1-full"), - L"1.1"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, - L"1.1-dev-full"), - L"1.1-dev"); + installer_util::ChannelInfo v; + v.set_value(L""); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, s, &v)); + EXPECT_EQ(v.value(), L""); + + v.set_value(L"1.1"); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, s, &v)); + EXPECT_EQ(v.value(), L"1.1"); + + v.set_value(L"1.1-dev"); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, s, &v)); + EXPECT_EQ(v.value(), L"1.1-dev"); + + v.set_value(L"-full"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, s, &v)); + EXPECT_EQ(v.value(), L""); + + v.set_value(L"1.1-full"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, s, &v)); + EXPECT_EQ(v.value(), L"1.1"); + + v.set_value(L"1.1-dev-full"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, s, &v)); + EXPECT_EQ(v.value(), L"1.1-dev"); // Incremental Installer that failed. - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L""), - L"-full"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"1.1"), - L"1.1-full"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"1.1-dev"), - L"1.1-dev-full"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"-full"), - L"-full"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"1.1-full"), - L"1.1-full"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, - L"1.1-dev-full"), - L"1.1-dev-full"); + v.set_value(L""); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, f, &v)); + EXPECT_EQ(v.value(), L"-full"); + + v.set_value(L"1.1"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, f, &v)); + EXPECT_EQ(v.value(), L"1.1-full"); + + v.set_value(L"1.1-dev"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, f, &v)); + EXPECT_EQ(v.value(), L"1.1-dev-full"); + + v.set_value(L"-full"); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, f, &v)); + EXPECT_EQ(v.value(), L"-full"); + + v.set_value(L"1.1-full"); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, f, &v)); + EXPECT_EQ(v.value(), L"1.1-full"); + + v.set_value(L"1.1-dev-full"); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(true, f, &v)); + EXPECT_EQ(v.value(), L"1.1-dev-full"); // Full Installer that worked. - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L""), L""); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L"1.1"), - L"1.1"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L"1.1-dev"), - L"1.1-dev"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L"-full"), - L""); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, - L"1.1-full"), - L"1.1"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, - L"1.1-dev-full"), - L"1.1-dev"); + v.set_value(L""); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, s, &v)); + EXPECT_EQ(v.value(), L""); + + v.set_value(L"1.1"); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, s, &v)); + EXPECT_EQ(v.value(), L"1.1"); + + v.set_value(L"1.1-dev"); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, s, &v)); + EXPECT_EQ(v.value(), L"1.1-dev"); + + v.set_value(L"-full"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, s, &v)); + EXPECT_EQ(v.value(), L""); + + v.set_value(L"1.1-full"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, s, &v)); + EXPECT_EQ(v.value(), L"1.1"); + + v.set_value(L"1.1-dev-full"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, s, &v)); + EXPECT_EQ(v.value(), L"1.1-dev"); // Full Installer that failed. - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L""), L""); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L"1.1"), - L"1.1"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L"1.1-dev"), - L"1.1-dev"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L"-full"), - L""); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, - L"1.1-full"), - L"1.1"); - EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, - L"1.1-dev-full"), - L"1.1-dev"); + v.set_value(L""); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, f, &v)); + EXPECT_EQ(v.value(), L""); + + v.set_value(L"1.1"); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, f, &v)); + EXPECT_EQ(v.value(), L"1.1"); + + v.set_value(L"1.1-dev"); + EXPECT_FALSE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, f, &v)); + EXPECT_EQ(v.value(), L"1.1-dev"); + + v.set_value(L"-full"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, f, &v)); + EXPECT_EQ(v.value(), L""); + + v.set_value(L"1.1-full"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, f, &v)); + EXPECT_EQ(v.value(), L"1.1"); + + v.set_value(L"1.1-dev-full"); + EXPECT_TRUE(GoogleUpdateSettings::UpdateGoogleUpdateApKey(false, f, &v)); + EXPECT_EQ(v.value(), L"1.1-dev"); } TEST_F(GoogleUpdateSettingsTest, UpdateDiffInstallStatusTest) { diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc index 781d6d4..f1495e8 100644 --- a/chrome_frame/utils.cc +++ b/chrome_frame/utils.cc @@ -69,10 +69,6 @@ static const wchar_t kChromeFrameNPAPIKey[] = L"Software\\MozillaPlugins\\@google.com/ChromeFrame,version=1.0"; static const wchar_t kChromeFramePersistNPAPIReg[] = L"PersistNPAPIReg"; -// Used to isolate chrome frame builds from google chrome release channels. -const wchar_t kChromeFrameOmahaSuffix[] = L"-cf"; -const wchar_t kDevChannelName[] = L"-dev"; - const char kAttachExternalTabPrefix[] = "attach_external_tab"; // Indicates that we are running in a test environment, where execptions, etc |