forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some installer cleanup: introduced ChannelInfo class for fiddling wit…
…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
Showing
10 changed files
with
510 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
Oops, something went wrong.