Permalink
Browse files

Demove dead code that is never used in Windows Vista or later

Now that Mozc for Windows does not support Windows XP, we can safely get rid of SystemUtil::IsVistaOrLater() as well as the dead code conditionally used behind that.

This is just dead-code removal.  No behavior change is intended.

BUG=none
TEST=unittest

git-svn-id: https://mozc.googlecode.com/svn/trunk@523 a6090854-d499-a067-5803-1114d4e51264
  • Loading branch information...
1 parent 812d5b8 commit b782c5af17f7fe17f4024098959e20c99381bf14 @yukawa yukawa committed Jan 31, 2015
View
@@ -144,6 +144,7 @@
'aux_ulib.lib', # used in 'win_util.cc'
'propsys.lib', # used in 'win_util.cc'
'version.lib', # used in 'util.cc'
+ 'KtmW32.lib', # used in 'file_util.cc'
],
},
},
View
@@ -31,6 +31,7 @@
#ifdef OS_WIN
#include <Windows.h>
+#include <KtmW32.h>
#else
#include <sys/stat.h>
#include <sys/types.h>
@@ -45,7 +46,6 @@
#include "base/pepper_file_util.h"
#endif // MOZC_USE_PEPPER_FILE_IO
#include "base/scoped_handle.h"
-#include "base/system_util.h"
#include "base/util.h"
#include "base/win_util.h"
@@ -168,97 +168,10 @@ bool FileUtil::DirectoryExists(const string &dirname) {
#ifdef OS_WIN
namespace {
-typedef HANDLE (WINAPI *FPCreateTransaction)(LPSECURITY_ATTRIBUTES,
- LPGUID,
- DWORD,
- DWORD,
- DWORD,
- DWORD,
- LPWSTR);
-typedef BOOL (WINAPI *FPMoveFileTransactedW)(LPCTSTR,
- LPCTSTR,
- LPPROGRESS_ROUTINE,
- LPVOID,
- DWORD,
- HANDLE);
-typedef BOOL (WINAPI *FPGetFileAttributesTransactedW)(LPCTSTR,
- GET_FILEEX_INFO_LEVELS,
- LPVOID,
- HANDLE);
-typedef BOOL (WINAPI *FPSetFileAttributesTransactedW)(LPCTSTR,
- DWORD,
- HANDLE);
-typedef BOOL (WINAPI *FPCommitTransaction)(HANDLE);
-
-FPCreateTransaction g_create_transaction = nullptr;
-FPMoveFileTransactedW g_move_file_transactedw = nullptr;
-FPGetFileAttributesTransactedW g_get_file_attributes_transactedw = nullptr;
-FPSetFileAttributesTransactedW g_set_file_attributes_transactedw = nullptr;
-FPCommitTransaction g_commit_transaction = nullptr;
-
-static once_t g_init_tx_move_file_once = MOZC_ONCE_INIT;
-
-void InitTxMoveFile() {
- if (!SystemUtil::IsVistaOrLater()) {
- return;
- }
-
- const HMODULE lib_ktmw = WinUtil::LoadSystemLibrary(L"ktmw32.dll");
- if (lib_ktmw == nullptr) {
- LOG(ERROR) << "LoadSystemLibrary for ktmw32.dll failed.";
- return;
- }
-
- const HMODULE lib_kernel = WinUtil::GetSystemModuleHandle(L"kernel32.dll");
- if (lib_kernel == nullptr) {
- LOG(ERROR) << "LoadSystemLibrary for kernel32.dll failed.";
- return;
- }
-
- g_create_transaction =
- reinterpret_cast<FPCreateTransaction>
- (::GetProcAddress(lib_ktmw, "CreateTransaction"));
-
- g_move_file_transactedw =
- reinterpret_cast<FPMoveFileTransactedW>
- (::GetProcAddress(lib_kernel, "MoveFileTransactedW"));
-
- g_get_file_attributes_transactedw =
- reinterpret_cast<FPGetFileAttributesTransactedW>
- (::GetProcAddress(lib_kernel, "GetFileAttributesTransactedW"));
-
- g_set_file_attributes_transactedw =
- reinterpret_cast<FPSetFileAttributesTransactedW>
- (::GetProcAddress(lib_kernel, "SetFileAttributesTransactedW"));
-
- g_commit_transaction =
- reinterpret_cast<FPCommitTransaction>
- (::GetProcAddress(lib_ktmw, "CommitTransaction"));
-
- LOG_IF(ERROR, g_create_transaction == nullptr)
- << "CreateTransaction init failed";
- LOG_IF(ERROR, g_move_file_transactedw == nullptr)
- << "MoveFileTransactedW init failed";
- LOG_IF(ERROR, g_get_file_attributes_transactedw == nullptr)
- << "GetFileAttributesTransactedW init failed";
- LOG_IF(ERROR, g_set_file_attributes_transactedw == nullptr)
- << "SetFileAttributesTransactedW init failed";
- LOG_IF(ERROR, g_commit_transaction == nullptr)
- << "CommitTransaction init failed";
-}
bool TransactionalMoveFile(const wstring &from, const wstring &to) {
- CallOnce(&g_init_tx_move_file_once, &InitTxMoveFile);
-
- if (g_commit_transaction == nullptr || g_move_file_transactedw == nullptr ||
- g_set_file_attributes_transactedw == nullptr ||
- g_create_transaction == nullptr) {
- // Transactional NTFS is not available.
- return false;
- }
-
const DWORD kTimeout = 5000; // 5 sec.
- ScopedHandle handle((*g_create_transaction)(
+ ScopedHandle handle(::CreateTransaction(
nullptr, 0, 0, 0, 0, kTimeout, nullptr));
const DWORD create_transaction_error = ::GetLastError();
if (handle.get() == 0) {
@@ -267,37 +180,32 @@ bool TransactionalMoveFile(const wstring &from, const wstring &to) {
}
WIN32_FILE_ATTRIBUTE_DATA file_attribute_data = {};
- if (!(*g_get_file_attributes_transactedw)(from.c_str(), GetFileExInfoStandard,
- &file_attribute_data,
- handle.get())) {
+ if (!::GetFileAttributesTransactedW(from.c_str(), GetFileExInfoStandard,
+ &file_attribute_data, handle.get())) {
const DWORD get_file_attributes_error = ::GetLastError();
LOG(ERROR) << "GetFileAttributesTransactedW failed: "
<< get_file_attributes_error;
return false;
}
- if (!(*g_move_file_transactedw)(from.c_str(), to.c_str(),
- nullptr, nullptr,
- MOVEFILE_COPY_ALLOWED |
- MOVEFILE_REPLACE_EXISTING,
- handle.get())) {
+ if (!::MoveFileTransactedW(from.c_str(), to.c_str(), nullptr, nullptr,
+ MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING,
+ handle.get())) {
const DWORD move_file_transacted_error = ::GetLastError();
LOG(ERROR) << "MoveFileTransactedW failed: "
<< move_file_transacted_error;
return false;
}
- if (!(*g_set_file_attributes_transactedw)(
- to.c_str(),
- file_attribute_data.dwFileAttributes,
- handle.get())) {
+ if (!::SetFileAttributesTransactedW(
+ to.c_str(), file_attribute_data.dwFileAttributes, handle.get())) {
const DWORD set_file_attributes_error = ::GetLastError();
LOG(ERROR) << "SetFileAttributesTransactedW failed: "
<< set_file_attributes_error;
return false;
}
- if (!(*g_commit_transaction)(handle.get())) {
+ if (!::CommitTransaction(handle.get())) {
const DWORD commit_transaction_error = ::GetLastError();
LOG(ERROR) << "CommitTransaction failed: " << commit_transaction_error;
return false;
@@ -307,9 +215,7 @@ bool TransactionalMoveFile(const wstring &from, const wstring &to) {
}
} // namespace
-#endif // OS_WIN
-#ifdef OS_WIN
bool FileUtil::HideFile(const string &filename) {
return HideFileWithExtraAttributes(filename, 0);
}
View
@@ -85,12 +85,6 @@ bool IsDifferentUser(const HANDLE hToken) {
// SourceName is not always null-terminated.
// We're looking for the cases marked '->'.
- // XP SP2 (Normal): "User32 "
- // XP SP2 (Scheduler while logon): "User32 "
- // XP SP2 (Scheduler while logoff): "advapi "
- // -> XP SP2 (RunAs): "seclogon"
- // Server 2003 SP2 (Normal): "User32 "
- // -> Server 2003 SP2 (RunAs): "seclogon"
// Vista SP1 (Normal) "User32 \0"
// -> Vista SP1 (RunAs): "seclogo\0"
// -> Vista SP1 (Over-the-shoulder UAC): "CredPro\0"
@@ -109,11 +103,6 @@ bool IsDifferentUser(const HANDLE hToken) {
// or if failed to determine.
// This code is written by thatanaka
bool IsElevatedByUAC(const HANDLE hToken) {
- // UAC is supported only on Vista or later.
- if (!SystemUtil::IsVistaOrLater()) {
- return false;
- }
-
// Get TokenElevationType.
DWORD dwSize;
TOKEN_ELEVATION_TYPE ElevationType;
@@ -342,10 +331,6 @@ bool RunLevel::IsProcessInJob() {
bool RunLevel::IsElevatedByUAC() {
#ifdef OS_WIN
- if (!SystemUtil::IsVistaOrLater()) {
- return false;
- }
-
// Get process token
HANDLE hProcessToken = NULL;
if (!::OpenProcessToken(::GetCurrentProcess(),
@@ -147,29 +147,7 @@ class LocalAppDataDirectoryCache {
if (in_app_container) {
return TryGetLocalAppDataForAppContainer(dir);
}
- if (SystemUtil::IsVistaOrLater()) {
- return TryGetLocalAppDataLow(dir);
- }
-
- // Windows XP: use "%USERPROFILE%\Local Settings\Application Data"
-
- // Retrieve the directory "%USERPROFILE%\Local Settings\Application Data",
- // which is a user directory which serves a data repository for local
- // applications, to avoid user profiles from being roamed by indexers.
- wchar_t config[MAX_PATH] = {};
- const HRESULT result = ::SHGetFolderPathW(
- nullptr, CSIDL_LOCAL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, &config[0]);
- if (FAILED(result)) {
- return result;
- }
-
- string buffer;
- if (Util::WideToUTF8(&config[0], &buffer) == 0) {
- return E_FAIL;
- }
-
- *dir = buffer;
- return S_OK;
+ return TryGetLocalAppDataLow(dir);
}
static HRESULT TryGetLocalAppDataForAppContainer(string *dir) {
@@ -205,42 +183,17 @@ class LocalAppDataDirectoryCache {
}
dir->clear();
- if (!SystemUtil::IsVistaOrLater()) {
- return E_NOTIMPL;
- }
-
- // Windows Vista: use LocalLow
- // Call SHGetKnownFolderPath dynamically.
- // http://msdn.microsoft.com/en-us/library/bb762188(VS.85).aspx
- // http://msdn.microsoft.com/en-us/library/bb762584(VS.85).aspx
- // GUID: {A520A1A4-1780-4FF6-BD18-167343C5AF16}
- const HMODULE hLib = WinUtil::LoadSystemLibrary(L"shell32.dll");
- if (hLib == nullptr) {
- return E_NOTIMPL;
- }
-
- typedef HRESULT (WINAPI *FPSHGetKnownFolderPath)(
- const GUID &, DWORD, HANDLE, PWSTR *);
- FPSHGetKnownFolderPath func = reinterpret_cast<FPSHGetKnownFolderPath>
- (::GetProcAddress(hLib, "SHGetKnownFolderPath"));
- if (func == nullptr) {
- ::FreeLibrary(hLib);
- return E_NOTIMPL;
- }
-
wchar_t *task_mem_buffer = nullptr;
- const HRESULT result =
- (*func)(FOLDERID_LocalAppDataLow, 0, nullptr, &task_mem_buffer);
+ const HRESULT result = ::SHGetKnownFolderPath(
+ FOLDERID_LocalAppDataLow, 0, nullptr, &task_mem_buffer);
if (FAILED(result)) {
if (task_mem_buffer != nullptr) {
::CoTaskMemFree(task_mem_buffer);
}
- ::FreeLibrary(hLib);
return result;
}
if (task_mem_buffer == nullptr) {
- ::FreeLibrary(hLib);
return E_UNEXPECTED;
}
@@ -249,13 +202,10 @@ class LocalAppDataDirectoryCache {
string path;
if (Util::WideToUTF8(wpath, &path) == 0) {
- ::FreeLibrary(hLib);
return E_UNEXPECTED;
}
*dir = path;
-
- ::FreeLibrary(hLib);
return S_OK;
}
@@ -853,15 +803,6 @@ bool SystemUtil::IsPlatformSupported() {
#endif // OS_LINUX, OS_MACOSX, OS_WIN
}
-bool SystemUtil::IsVistaOrLater() {
-#ifdef OS_WIN
- static const bool result = ::IsWindowsVistaOrGreater();
- return result;
-#else
- return false;
-#endif // OS_WIN
-}
-
bool SystemUtil::IsWindows7OrLater() {
#ifdef OS_WIN
static const bool result = ::IsWindows7OrGreater();
@@ -46,8 +46,6 @@ namespace mozc {
class SystemUtil {
public:
// return "~/.mozc" for Unix/Mac
- // return "%USERPROFILE%\\Local Settings\\Application\\"
- // "Google\\Google Japanese Input" for Windows XP.
// return "%USERPROFILE%\\AppData\\LocalLow\\"
// "Google\\Google Japanese Input" for Windows Vista and later.
static string GetUserProfileDirectory();
@@ -114,7 +112,6 @@ class SystemUtil {
// EnsureVitalImmutableDataIsAvailable is a simple fail-fast mechanism to
// this situation. This function simply returns false instead of making
// the process crash if any of following functions cannot work as expected.
- // - IsVistaOrLaterCache
// - SystemDirectoryCache
// - ProgramFilesX86Cache
// - LocalAppDataDirectoryCache
@@ -146,9 +143,6 @@ class SystemUtil {
// TODO(yukawa): support Mac and Linux.
static bool IsPlatformSupported();
- // returns true if the version of Windows is Vista or later.
- static bool IsVistaOrLater();
-
// returns true if the version of Windows is 6.1 or later.
static bool IsWindows7OrLater();
Oops, something went wrong.

0 comments on commit b782c5a

Please sign in to comment.