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
diff --git a/src/base/system_util.cc b/src/base/system_util.cc
index 5b76f93..2654bfb 100644
--- a/src/base/system_util.cc
+++ b/src/base/system_util.cc
@@ -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 @@
#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 @@
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,8 +855,8 @@
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
@@ -937,8 +864,8 @@
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
@@ -946,8 +873,8 @@
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
@@ -955,8 +882,8 @@
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
diff --git a/src/mozc_version_template.txt b/src/mozc_version_template.txt
index 1644008..3a98503 100644
--- a/src/mozc_version_template.txt
+++ b/src/mozc_version_template.txt
@@ -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.