Skip to content

Commit 812d5b8

Browse files
committed
Use VersionHelpers.h to simplify SystemUtil
A set of useful utilify functions called "Version Helper functions" has been available since Windows SDK 8.1. https://msdn.microsoft.com/en-us/library/windows/desktop/dn424972.aspx We can rely on them in SystemUtil instead of reimplementing the same logic. This is just a code clean-up. No behavior change is intended. BUG=none TEST=unittest git-svn-id: https://mozc.googlecode.com/svn/trunk@522 a6090854-d499-a067-5803-1114d4e51264
1 parent 6895df1 commit 812d5b8

File tree

2 files changed

+11
-84
lines changed

2 files changed

+11
-84
lines changed

src/base/system_util.cc

Lines changed: 10 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <LMCons.h>
3535
#include <Sddl.h>
3636
#include <ShlObj.h>
37+
#include <VersionHelpers.h>
3738
#else // OS_WIN
3839
#include <pwd.h>
3940
#include <sys/mman.h>
@@ -707,69 +708,6 @@ string SystemUtil::GetDesktopNameAsString() {
707708

708709
#ifdef OS_WIN
709710
namespace {
710-
// TODO(yukawa): Use API wrapper so that unit test can emulate any case.
711-
template<DWORD MajorVersion, DWORD MinorVersion>
712-
class IsWindowsVerXOrLaterCache {
713-
public:
714-
IsWindowsVerXOrLaterCache()
715-
: succeeded_(false),
716-
is_ver_x_or_later_(true) {
717-
// Examine if this system is greater than or equal to WinNT ver. X
718-
{
719-
OSVERSIONINFOEX osvi = {};
720-
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
721-
osvi.dwMajorVersion = MajorVersion;
722-
osvi.dwMinorVersion = MinorVersion;
723-
DWORDLONG conditional = 0;
724-
VER_SET_CONDITION(conditional, VER_MAJORVERSION, VER_GREATER_EQUAL);
725-
VER_SET_CONDITION(conditional, VER_MINORVERSION, VER_GREATER_EQUAL);
726-
const BOOL result = ::VerifyVersionInfo(
727-
&osvi, VER_MAJORVERSION | VER_MINORVERSION, conditional);
728-
if (result != FALSE) {
729-
succeeded_ = true;
730-
is_ver_x_or_later_ = true;
731-
return;
732-
}
733-
}
734-
735-
// Examine if this system is less than WinNT ver. X
736-
{
737-
OSVERSIONINFOEX osvi = {};
738-
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
739-
osvi.dwMajorVersion = MajorVersion;
740-
osvi.dwMinorVersion = MinorVersion;
741-
DWORDLONG conditional = 0;
742-
VER_SET_CONDITION(conditional, VER_MAJORVERSION, VER_LESS);
743-
VER_SET_CONDITION(conditional, VER_MINORVERSION, VER_LESS);
744-
const BOOL result = ::VerifyVersionInfo(
745-
&osvi, VER_MAJORVERSION | VER_MINORVERSION, conditional);
746-
if (result != FALSE) {
747-
succeeded_ = true;
748-
is_ver_x_or_later_ = false;
749-
return;
750-
}
751-
}
752-
753-
// Unexpected situation.
754-
succeeded_ = false;
755-
is_ver_x_or_later_ = false;
756-
}
757-
const bool succeeded() const {
758-
return succeeded_;
759-
}
760-
const bool is_ver_x_or_later() const {
761-
return is_ver_x_or_later_;
762-
}
763-
764-
private:
765-
bool succeeded_;
766-
bool is_ver_x_or_later_;
767-
};
768-
769-
typedef IsWindowsVerXOrLaterCache<6, 0> IsWindowsVistaOrLaterCache;
770-
typedef IsWindowsVerXOrLaterCache<6, 1> IsWindows7OrLaterCache;
771-
typedef IsWindowsVerXOrLaterCache<6, 2> IsWindows8OrLaterCache;
772-
typedef IsWindowsVerXOrLaterCache<6, 3> IsWindows8_1OrLaterCache;
773711

774712
// TODO(yukawa): Use API wrapper so that unit test can emulate any case.
775713
class SystemDirectoryCache {
@@ -794,22 +732,11 @@ class SystemDirectoryCache {
794732
wchar_t path_buffer_[MAX_PATH];
795733
wchar_t *system_dir_;
796734
};
735+
797736
} // namespace
798737

799738
// TODO(team): Support other platforms.
800739
bool SystemUtil::EnsureVitalImmutableDataIsAvailable() {
801-
if (!Singleton<IsWindowsVistaOrLaterCache>::get()->succeeded()) {
802-
return false;
803-
}
804-
if (!Singleton<IsWindows7OrLaterCache>::get()->succeeded()) {
805-
return false;
806-
}
807-
if (!Singleton<IsWindows8OrLaterCache>::get()->succeeded()) {
808-
return false;
809-
}
810-
if (!Singleton<IsWindows8_1OrLaterCache>::get()->succeeded()) {
811-
return false;
812-
}
813740
if (!Singleton<SystemDirectoryCache>::get()->succeeded()) {
814741
return false;
815742
}
@@ -928,35 +855,35 @@ bool SystemUtil::IsPlatformSupported() {
928855

929856
bool SystemUtil::IsVistaOrLater() {
930857
#ifdef OS_WIN
931-
DCHECK(Singleton<IsWindowsVistaOrLaterCache>::get()->succeeded());
932-
return Singleton<IsWindowsVistaOrLaterCache>::get()->is_ver_x_or_later();
858+
static const bool result = ::IsWindowsVistaOrGreater();
859+
return result;
933860
#else
934861
return false;
935862
#endif // OS_WIN
936863
}
937864

938865
bool SystemUtil::IsWindows7OrLater() {
939866
#ifdef OS_WIN
940-
DCHECK(Singleton<IsWindows7OrLaterCache>::get()->succeeded());
941-
return Singleton<IsWindows7OrLaterCache>::get()->is_ver_x_or_later();
867+
static const bool result = ::IsWindows7OrGreater();
868+
return result;
942869
#else
943870
return false;
944871
#endif // OS_WIN
945872
}
946873

947874
bool SystemUtil::IsWindows8OrLater() {
948875
#ifdef OS_WIN
949-
DCHECK(Singleton<IsWindows8OrLaterCache>::get()->succeeded());
950-
return Singleton<IsWindows8OrLaterCache>::get()->is_ver_x_or_later();
876+
static const bool result = ::IsWindows8OrGreater();
877+
return result;
951878
#else
952879
return false;
953880
#endif // OS_WIN
954881
}
955882

956883
bool SystemUtil::IsWindows8_1OrLater() {
957884
#ifdef OS_WIN
958-
DCHECK(Singleton<IsWindows8_1OrLaterCache>::get()->succeeded());
959-
return Singleton<IsWindows8_1OrLaterCache>::get()->is_ver_x_or_later();
885+
static const bool result = ::IsWindows8Point1OrGreater();
886+
return result;
960887
#else
961888
return false;
962889
#endif // OS_WIN

src/mozc_version_template.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MAJOR=2
22
MINOR=16
3-
BUILD=2038
3+
BUILD=2039
44
REVISION=102
55
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
66
# downloaded by NaCl Mozc.

0 commit comments

Comments
 (0)