Skip to content

Commit

Permalink
base/version: remove wstring version
Browse files Browse the repository at this point in the history
And fix callers.

BUG=23581
TEST=trybots

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70098 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
evan@chromium.org committed Dec 23, 2010
1 parent 8d4c4bb commit 36ee032
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 49 deletions.
7 changes: 0 additions & 7 deletions base/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"

// static
Version* Version::GetVersionFromString(const std::wstring& version_str) {
if (!IsStringASCII(version_str))
return NULL;
return GetVersionFromString(WideToUTF8(version_str));
}

// static
Version* Version::GetVersionFromString(const std::string& version_str) {
Version* vers = new Version();
Expand Down
4 changes: 3 additions & 1 deletion base/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"

// Version represents a dotted version number, like "1.2.3.4", supporting
// parsing and comparison.
// Each component is limited to a uint16.
class Version {
public:
// The version string must be made up of 1 or more uint16's separated
// by '.'. Returns NULL if string is not in this format.
// Caller is responsible for freeing the Version object once done.
static Version* GetVersionFromString(const std::wstring& version_str);
static Version* GetVersionFromString(const std::string& version_str);

// Exposed only so that a Version can be stored in STL containers;
Expand Down
22 changes: 11 additions & 11 deletions chrome/app/client_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/file_util.h"
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/version.h"
#include "chrome/app/breakpad_win.h"
Expand Down Expand Up @@ -213,26 +214,25 @@ HMODULE MainDllLoader::Load(std::wstring* out_version, std::wstring* out_file) {
if (dll)
return dll;

std::wstring version_env_string;
std::wstring version_string;
scoped_ptr<Version> version;
const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
if (cmd_line.HasSwitch(switches::kChromeVersion)) {
version_env_string = cmd_line.GetSwitchValueNative(
switches::kChromeVersion);
version.reset(Version::GetVersionFromString(version_env_string));
version_string = cmd_line.GetSwitchValueNative(switches::kChromeVersion);
version.reset(Version::GetVersionFromString(WideToASCII(version_string)));

if (!version.get()) {
// If a bogus command line flag was given, then abort.
LOG(ERROR) << "Invalid version string received on command line: "
<< version_env_string;
<< version_string;
return NULL;
}
}

if (!version.get()) {
if (EnvQueryStr(ASCIIToWide(chrome::kChromeVersionEnvVar).c_str(),
&version_env_string)) {
version.reset(Version::GetVersionFromString(version_env_string));
&version_string)) {
version.reset(Version::GetVersionFromString(WideToASCII(version_string)));
}
}

Expand All @@ -241,13 +241,13 @@ HMODULE MainDllLoader::Load(std::wstring* out_version, std::wstring* out_file) {
// Look into the registry to find the latest version. We don't validate
// this by building a Version object to avoid harming normal case startup
// time.
version_env_string.clear();
GetVersion(dir.c_str(), reg_path.c_str(), &version_env_string);
version_string.clear();
GetVersion(dir.c_str(), reg_path.c_str(), &version_string);
}

if (version.get() || !version_env_string.empty()) {
if (version.get() || !version_string.empty()) {
*out_file = dir;
*out_version = version_env_string;
*out_version = version_string;
out_file->append(*out_version).append(L"\\");
return LoadChromeWithDirectory(out_file);
} else {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/enumerate_modules_model_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ ModuleEnumerator::ModuleStatus ModuleEnumerator::Match(
// We have a name match against the blacklist (and possibly location match
// also), so check version.
scoped_ptr<Version> module_version(
Version::GetVersionFromString(module.version));
Version::GetVersionFromString(UTF16ToASCII(module.version)));
scoped_ptr<Version> version_min(
Version::GetVersionFromString(blacklisted.version_from));
scoped_ptr<Version> version_max(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void ExternalRegistryExtensionProvider::VisitRegisteredExtension(
StringToLowerASCII(&id);

scoped_ptr<Version> version;
version.reset(Version::GetVersionFromString(extension_version));
version.reset(Version::GetVersionFromString(
WideToASCII(extension_version)));
if (!version.get()) {
LOG(ERROR) << "Invalid version value " << extension_version
<< " for key " << key_path;
Expand Down Expand Up @@ -103,8 +104,10 @@ bool ExternalRegistryExtensionProvider::GetExtensionDetails(
if (!key.ReadValue(kRegistryExtensionVersion, &extension_version))
return false;

if (version)
version->reset(Version::GetVersionFromString(extension_version));
if (version) {
version->reset(Version::GetVersionFromString(
WideToASCII(extension_version)));
}

if (location)
*location = Extension::EXTERNAL_REGISTRY;
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/gpu_blacklist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/sys_info.h"
#include "base/values.h"
Expand Down Expand Up @@ -369,7 +370,7 @@ GpuFeatureFlags GpuBlacklist::DetermineGpuFeatureFlags(
if (gpu_info.progress() == GPUInfo::kUninitialized)
return flags;
scoped_ptr<Version> driver_version(
Version::GetVersionFromString(gpu_info.driver_version()));
Version::GetVersionFromString(WideToASCII(gpu_info.driver_version())));
if (driver_version.get() == NULL)
return flags;

Expand Down
14 changes: 7 additions & 7 deletions chrome/browser/ui/views/about_chrome_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ void AboutChromeView::Init() {
return;
}

current_version_ = ASCIIToWide(version_info.Version());
current_version_ = version_info.Version();

std::string version_modifier = platform_util::GetVersionStringModifier();
if (!version_modifier.empty())
version_details_ += L" " + ASCIIToWide(version_modifier);
version_details_ += " " + version_modifier;

#if !defined(GOOGLE_CHROME_BUILD)
version_details_ += L" (";
version_details_ += ASCIIToWide(version_info.LastChange());
version_details_ += L")";
version_details_ += " (";
version_details_ += version_info.LastChange();
version_details_ += ")";
#endif

// Views we will add to the *parent* of this dialog, since it will display
Expand Down Expand Up @@ -210,7 +210,7 @@ void AboutChromeView::Init() {

// This is a text field so people can copy the version number from the dialog.
version_label_ = new views::Textfield();
version_label_->SetText(WideToUTF16Hack(current_version_ + version_details_));
version_label_->SetText(ASCIIToUTF16(current_version_ + version_details_));
version_label_->SetReadOnly(true);
version_label_->RemoveBorder();
version_label_->SetTextColor(SK_ColorBLACK);
Expand Down Expand Up @@ -763,7 +763,7 @@ void AboutChromeView::UpdateStatus(GoogleUpdateUpgradeResult result,
std::wstring update_label_text =
l10n_util::GetStringF(IDS_UPGRADE_ALREADY_UP_TO_DATE,
l10n_util::GetString(IDS_PRODUCT_NAME),
current_version_);
ASCIIToUTF16(current_version_));
#endif
if (base::i18n::IsRTL()) {
update_label_text.push_back(
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/about_chrome_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ class AboutChromeView : public views::View,
#endif

// Our current version.
std::wstring current_version_;
std::string current_version_;

// Additional information about the version (channel and build number).
std::wstring version_details_;
std::string version_details_;

// The version Google Update reports is available to us.
std::wstring new_version_available_;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/upgrade_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class DetectUpgradeTask : public Task {
}
#elif defined(OS_MACOSX)
installed_version.reset(
Version::GetVersionFromString(UTF16ToWideHack(
Version::GetVersionFromString(UTF16ToASCII(
keystone_glue::CurrentlyInstalledVersion())));
#elif defined(OS_POSIX)
// POSIX but not Mac OS X: Linux, etc.
Expand Down
3 changes: 1 addition & 2 deletions chrome/common/extensions/extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key,
*error = errors::kInvalidVersion;
return false;
}
version_.reset(
Version::GetVersionFromString(version_str));
version_.reset(Version::GetVersionFromString(version_str));
if (!version_.get() ||
version_->components().size() > 4) {
*error = errors::kInvalidVersion;
Expand Down
3 changes: 2 additions & 1 deletion chrome/installer/setup/setup_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/file_util.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/util_constants.h"
#include "courgette/courgette.h"
Expand Down Expand Up @@ -45,7 +46,7 @@ Version* installer::GetVersionFromArchiveDir(const FilePath& chrome_path) {
file_util::FileEnumerator::FindInfo find_data = {0};
version_enum.GetFindInfo(&find_data);
VLOG(1) << "directory found: " << find_data.cFileName;
version = Version::GetVersionFromString(find_data.cFileName);
version = Version::GetVersionFromString(WideToASCII(find_data.cFileName));
if (version)
break;
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/installer/util/helper_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ TEST_F(SetupHelperTest, Delete) {
CreateTextFile(chrome_dll_4.value(), text_content_1);
ASSERT_TRUE(file_util::PathExists(chrome_dll_4));

scoped_ptr<Version> latest_version(Version::GetVersionFromString(L"1.0.4.0"));
scoped_ptr<Version> latest_version(Version::GetVersionFromString("1.0.4.0"));
ChromePackageProperties properties;
scoped_refptr<Package> package(new Package(false, true, chrome_dir,
&properties));
Expand Down Expand Up @@ -185,7 +185,7 @@ TEST_F(SetupHelperTest, DeleteInUsed) {
CreateTextFile(chrome_dll_4.value(), text_content_1);
ASSERT_TRUE(file_util::PathExists(chrome_dll_4));

scoped_ptr<Version> latest_version(Version::GetVersionFromString(L"1.0.4.0"));
scoped_ptr<Version> latest_version(Version::GetVersionFromString("1.0.4.0"));
ChromePackageProperties properties;
scoped_refptr<Package> install_path(new Package(false, true, chrome_dir,
&properties));
Expand Down
2 changes: 1 addition & 1 deletion chrome/installer/util/install_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist,
key.Close();
VLOG(1) << "Existing " << dist->GetApplicationName()
<< " version found " << version_str;
return Version::GetVersionFromString(version_str);
return Version::GetVersionFromString(WideToASCII(version_str));
}

bool InstallUtil::IsOSSupported() {
Expand Down
7 changes: 5 additions & 2 deletions chrome/installer/util/package.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/file_util.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
#include "chrome/installer/util/channel_info.h"
Expand Down Expand Up @@ -125,7 +126,8 @@ Version* Package::GetCurrentVersion() const {
chrome_key.ReadValue(google_update::kRegVersionField, &version);

if (!version.empty()) {
scoped_ptr<Version> this_version(Version::GetVersionFromString(version));
scoped_ptr<Version> this_version(Version::GetVersionFromString(
WideToASCII(version)));
if (this_version.get()) {
if (!current_version.get() ||
(current_version->CompareTo(*this_version) > 0)) {
Expand Down Expand Up @@ -155,7 +157,8 @@ void Package::RemoveOldVersionDirectories(
file_util::FileEnumerator::FindInfo find_data = {0};
version_enum.GetFindInfo(&find_data);
VLOG(1) << "directory found: " << find_data.cFileName;
version.reset(Version::GetVersionFromString(find_data.cFileName));
version.reset(Version::GetVersionFromString(
WideToASCII(find_data.cFileName)));
if (version.get() && (latest_version.CompareTo(*version) > 0)) {
std::vector<FilePath> key_files;
for (Products::const_iterator it = products_.begin();
Expand Down
6 changes: 3 additions & 3 deletions chrome/installer/util/package_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ TEST_F(PackageTest, Basic) {
EXPECT_TRUE(package->IsEqual(test_dir_.path()));
EXPECT_EQ(0U, package->products().size());

const wchar_t kOldVersion[] = L"1.2.3.4";
const wchar_t kNewVersion[] = L"2.3.4.5";
const char kOldVersion[] = "1.2.3.4";
const char kNewVersion[] = "2.3.4.5";

scoped_ptr<Version> new_version(Version::GetVersionFromString(kNewVersion));
scoped_ptr<Version> old_version(Version::GetVersionFromString(kOldVersion));
Expand Down Expand Up @@ -110,7 +110,7 @@ TEST_F(PackageTest, WithProduct) {
EXPECT_EQ(1U, package->products().size());
EXPECT_EQ(system_level, package->system_level());

const wchar_t kCurrentVersion[] = L"1.2.3.4";
const char kCurrentVersion[] = "1.2.3.4";
scoped_ptr<Version> current_version(
Version::GetVersionFromString(kCurrentVersion));

Expand Down
2 changes: 1 addition & 1 deletion chrome/installer/util/product_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ TEST_F(ProductTest, ProductInstallBasic) {
KEY_ALL_ACCESS);
ASSERT_TRUE(version_key.Valid());

const wchar_t kCurrentVersion[] = L"1.2.3.4";
const char kCurrentVersion[] = "1.2.3.4";
scoped_ptr<Version> current_version(
Version::GetVersionFromString(kCurrentVersion));
version_key.WriteValue(google_update::kRegVersionField,
Expand Down
3 changes: 2 additions & 1 deletion chrome_frame/dll_redirector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "base/shared_memory.h"
#include "base/string_util.h"
#include "base/sys_info.h"
#include "base/utf_string_conversions.h"
#include "base/version.h"
Expand Down Expand Up @@ -247,7 +248,7 @@ Version* DllRedirector::GetCurrentModuleVersion() {
Version* current_version = NULL;
if (file_version_info.get()) {
current_version = Version::GetVersionFromString(
file_version_info->file_version());
WideToASCII(file_version_info->file_version()));
DCHECK(current_version);
}

Expand Down
4 changes: 2 additions & 2 deletions webkit/plugins/npapi/plugin_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ bool PluginGroup::Match(const WebPluginInfo& plugin) const {

// There's at least one version range, the plugin's version must be in it.
scoped_ptr<Version> plugin_version(
Version::GetVersionFromString(UTF16ToWide(plugin.version)));
Version::GetVersionFromString(UTF16ToASCII(plugin.version)));
if (plugin_version.get() == NULL) {
// No version could be extracted, assume we don't match the range.
return false;
Expand All @@ -208,7 +208,7 @@ Version* PluginGroup::CreateVersionFromString(const string16& version_string) {
std::replace(version.begin(), version.end(), ',', '.');
std::replace(version.begin(), version.end(), '(', '.');

return Version::GetVersionFromString(version);
return Version::GetVersionFromString(WideToASCII(version));
}

void PluginGroup::UpdateActivePlugin(const WebPluginInfo& plugin) {
Expand Down

0 comments on commit 36ee032

Please sign in to comment.