Permalink
Browse files

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
  • Loading branch information...
1 parent 6895df1 commit 812d5b8be99631b4f630fdf31e6111b6f015f3d8 @yukawa yukawa committed Jan 31, 2015
Showing with 11 additions and 84 deletions.
  1. +10 −83 src/base/system_util.cc
  2. +1 −1 src/mozc_version_template.txt
@@ -34,6 +34,7 @@
#include <LMCons.h>
#include <Sddl.h>
#include <ShlObj.h>
+#include <VersionHelpers.h>
#else // OS_WIN
#include <pwd.h>
#include <sys/mman.h>
@@ -707,69 +708,6 @@ string SystemUtil::GetDesktopNameAsString() {
#ifdef OS_WIN
namespace {
-// TODO(yukawa): Use API wrapper so that unit test can emulate any case.
-template<DWORD MajorVersion, DWORD MinorVersion>
-class IsWindowsVerXOrLaterCache {
- public:
- IsWindowsVerXOrLaterCache()
- : succeeded_(false),
- is_ver_x_or_later_(true) {
- // Examine if this system is greater than or equal to WinNT ver. X
- {
- OSVERSIONINFOEX osvi = {};
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- osvi.dwMajorVersion = MajorVersion;
- osvi.dwMinorVersion = MinorVersion;
- DWORDLONG conditional = 0;
- VER_SET_CONDITION(conditional, VER_MAJORVERSION, VER_GREATER_EQUAL);
- VER_SET_CONDITION(conditional, VER_MINORVERSION, VER_GREATER_EQUAL);
- const BOOL result = ::VerifyVersionInfo(
- &osvi, VER_MAJORVERSION | VER_MINORVERSION, conditional);
- if (result != FALSE) {
- succeeded_ = true;
- is_ver_x_or_later_ = true;
- return;
- }
- }
-
- // Examine if this system is less than WinNT ver. X
- {
- OSVERSIONINFOEX osvi = {};
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- osvi.dwMajorVersion = MajorVersion;
- osvi.dwMinorVersion = MinorVersion;
- DWORDLONG conditional = 0;
- VER_SET_CONDITION(conditional, VER_MAJORVERSION, VER_LESS);
- VER_SET_CONDITION(conditional, VER_MINORVERSION, VER_LESS);
- const BOOL result = ::VerifyVersionInfo(
- &osvi, VER_MAJORVERSION | VER_MINORVERSION, conditional);
- if (result != FALSE) {
- succeeded_ = true;
- is_ver_x_or_later_ = false;
- return;
- }
- }
-
- // Unexpected situation.
- succeeded_ = false;
- is_ver_x_or_later_ = false;
- }
- const bool succeeded() const {
- return succeeded_;
- }
- const bool is_ver_x_or_later() const {
- return is_ver_x_or_later_;
- }
-
- private:
- bool succeeded_;
- bool is_ver_x_or_later_;
-};
-
-typedef IsWindowsVerXOrLaterCache<6, 0> IsWindowsVistaOrLaterCache;
-typedef IsWindowsVerXOrLaterCache<6, 1> IsWindows7OrLaterCache;
-typedef IsWindowsVerXOrLaterCache<6, 2> IsWindows8OrLaterCache;
-typedef IsWindowsVerXOrLaterCache<6, 3> IsWindows8_1OrLaterCache;
// TODO(yukawa): Use API wrapper so that unit test can emulate any case.
class SystemDirectoryCache {
@@ -794,22 +732,11 @@ class SystemDirectoryCache {
wchar_t path_buffer_[MAX_PATH];
wchar_t *system_dir_;
};
+
} // namespace
// TODO(team): Support other platforms.
bool SystemUtil::EnsureVitalImmutableDataIsAvailable() {
- if (!Singleton<IsWindowsVistaOrLaterCache>::get()->succeeded()) {
- return false;
- }
- if (!Singleton<IsWindows7OrLaterCache>::get()->succeeded()) {
- return false;
- }
- if (!Singleton<IsWindows8OrLaterCache>::get()->succeeded()) {
- return false;
- }
- if (!Singleton<IsWindows8_1OrLaterCache>::get()->succeeded()) {
- return false;
- }
if (!Singleton<SystemDirectoryCache>::get()->succeeded()) {
return false;
}
@@ -928,35 +855,35 @@ bool SystemUtil::IsPlatformSupported() {
bool SystemUtil::IsVistaOrLater() {
#ifdef OS_WIN
- DCHECK(Singleton<IsWindowsVistaOrLaterCache>::get()->succeeded());
- return Singleton<IsWindowsVistaOrLaterCache>::get()->is_ver_x_or_later();
+ static const bool result = ::IsWindowsVistaOrGreater();
+ return result;
#else
return false;
#endif // OS_WIN
}
bool SystemUtil::IsWindows7OrLater() {
#ifdef OS_WIN
- DCHECK(Singleton<IsWindows7OrLaterCache>::get()->succeeded());
- return Singleton<IsWindows7OrLaterCache>::get()->is_ver_x_or_later();
+ static const bool result = ::IsWindows7OrGreater();
+ return result;
#else
return false;
#endif // OS_WIN
}
bool SystemUtil::IsWindows8OrLater() {
#ifdef OS_WIN
- DCHECK(Singleton<IsWindows8OrLaterCache>::get()->succeeded());
- return Singleton<IsWindows8OrLaterCache>::get()->is_ver_x_or_later();
+ static const bool result = ::IsWindows8OrGreater();
+ return result;
#else
return false;
#endif // OS_WIN
}
bool SystemUtil::IsWindows8_1OrLater() {
#ifdef OS_WIN
- DCHECK(Singleton<IsWindows8_1OrLaterCache>::get()->succeeded());
- return Singleton<IsWindows8_1OrLaterCache>::get()->is_ver_x_or_later();
+ static const bool result = ::IsWindows8Point1OrGreater();
+ return result;
#else
return false;
#endif // OS_WIN
@@ -1,6 +1,6 @@
MAJOR=2
MINOR=16
-BUILD=2038
+BUILD=2039
REVISION=102
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
# downloaded by NaCl Mozc.

0 comments on commit 812d5b8

Please sign in to comment.