Skip to content

Commit

Permalink
Some installer cleanup: introduced ChannelInfo class for fiddling wit…
Browse files Browse the repository at this point in the history
…h "ap" ClientState value.

BUG=61609
TEST=added to and modified chrome/installer_util_unittests.exe appropriately

Review URL: http://codereview.chromium.org/5656002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68603 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
grt@chromium.org committed Dec 8, 2010
1 parent 33f7497 commit b04880f
Show file tree
Hide file tree
Showing 10 changed files with 510 additions and 159 deletions.
66 changes: 12 additions & 54 deletions ceee/installer_dll/installer_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_installer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions chrome/chrome_installer_util.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
128 changes: 128 additions & 0 deletions chrome/installer/util/channel_info.cc
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions chrome/installer/util/channel_info.h
Original file line number Diff line number Diff line change
@@ -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_
Loading

0 comments on commit b04880f

Please sign in to comment.