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
709710namespace {
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.
775713class 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.
800739bool 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
929856bool 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
938865bool 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
947874bool 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
956883bool 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
0 commit comments