Codebase list mozc / 3c76969
Remove dead code With the removal of the file corruption checker, SystemUtil::{GetFileVersion(), GetFileVersionString()} are no longer used in production code. Hence we can safely remove them. No user-visible change is intended. BUG= TEST= REF_BUG=27182026 REF_CL=114714920 REF_TIME=2016-02-15T18:07:37-08:00 REF_TIME_RAW=1455588457 -0800 Yohei Yukawa 8 years ago
8 changed file(s) with 1 addition(s) and 163 deletion(s). Raw diff Collapse all Expand all
135135 'VCLinkerTool': {
136136 'AdditionalDependencies': [
137137 'aux_ulib.lib', # used in 'win_util.cc'
138 'propsys.lib', # used in 'win_util.cc'
139 'version.lib', # used in 'util.cc'
140138 'KtmW32.lib', # used in 'file_util.cc'
141139 ],
142140 },
767767 return Singleton<SystemDirectoryCache>::get()->system_dir();
768768 }
769769
770 bool SystemUtil::GetFileVersion(const wstring &file_fullpath, int *major,
771 int *minor, int *build, int *revision) {
772 DCHECK(major);
773 DCHECK(minor);
774 DCHECK(build);
775 DCHECK(revision);
776 string path;
777 Util::WideToUTF8(file_fullpath.c_str(), &path);
778
779 // Accoding to KB826496, we should check file existence.
780 // http://support.microsoft.com/kb/826496
781 if (!FileUtil::FileExists(path)) {
782 LOG(ERROR) << "file not found";
783 return false;
784 }
785
786 DWORD handle = 0;
787 const DWORD version_size =
788 ::GetFileVersionInfoSizeW(file_fullpath.c_str(), &handle);
789
790 if (version_size == 0) {
791 LOG(ERROR) << "GetFileVersionInfoSizeW failed."
792 << " error = " << ::GetLastError();
793 return false;
794 }
795
796 unique_ptr<BYTE[]> version_buffer(new BYTE[version_size]);
797
798 if (!::GetFileVersionInfoW(file_fullpath.c_str(), 0,
799 version_size, version_buffer.get())) {
800 LOG(ERROR) << "GetFileVersionInfo failed."
801 << " error = " << ::GetLastError();
802 return false;
803 }
804
805 VS_FIXEDFILEINFO *fixed_fileinfo = nullptr;
806 UINT length = 0;
807 if (!::VerQueryValueW(version_buffer.get(), L"\\",
808 reinterpret_cast<LPVOID *>(&fixed_fileinfo),
809 &length)) {
810 LOG(ERROR) << "VerQueryValue failed."
811 << " error = " << ::GetLastError();
812 return false;
813 }
814
815 *major = HIWORD(fixed_fileinfo->dwFileVersionMS);
816 *minor = LOWORD(fixed_fileinfo->dwFileVersionMS);
817 *build = HIWORD(fixed_fileinfo->dwFileVersionLS);
818 *revision = LOWORD(fixed_fileinfo->dwFileVersionLS);
819
820 return true;
821 }
822
823 string SystemUtil::GetFileVersionString(const wstring &file_fullpath) {
824 int major, minor, build, revision;
825 if (!GetFileVersion(file_fullpath, &major, &minor, &build, &revision)) {
826 return "";
827 }
828
829 stringstream buf;
830 buf << major << "." << minor << "." << build << "." << revision;
831
832 return buf.str();
833 }
834
835770 string SystemUtil::GetMSCTFAsmCacheReadyEventName() {
836771 const string &session_id = GetSessionIdString();
837772 if (session_id.empty()) {
147147 // This function is thread safe.
148148 static const wchar_t *GetSystemDir();
149149
150 // Retrieves version of the specified file.
151 // If the function fails, returns false.
152 static bool GetFileVersion(const wstring &file_fullpath,
153 int *major,
154 int *minor,
155 int *build,
156 int *revision);
157
158 // Retrieves version string of the specified file.
159 // The version string consists of 4 digits separated by comma
160 // like "X.YY.ZZZ.WWWW".
161 // If the function fails, the return value is an empty string.
162 static string GetFileVersionString(const wstring &file_fullpath);
163
164150 // Returns "MSCTF.AsmCacheReady.<desktop name><session #>" to work around
165151 // b/5765783.
166152 // Returns an empty string if fails.
6060 SystemUtil::IS_WINDOWS_X64_DEFAULT_MODE);
6161 }
6262
63 #ifdef OS_WIN
64 TEST_F(SystemUtilTest, GetFileVersion) {
65 const wchar_t kDllName[] = L"kernel32.dll";
66
67 wstring path = SystemUtil::GetSystemDir();
68 path += L"\\";
69 path += kDllName;
70
71 int major, minor, build, revision;
72 EXPECT_TRUE(
73 SystemUtil::GetFileVersion(path, &major, &minor, &build, &revision));
74 }
75
76 TEST_F(SystemUtilTest, GetFileVersionStringTest) {
77 const wchar_t kDllName[] = L"kernel32.dll";
78
79 wstring path = SystemUtil::GetSystemDir();
80 path += L"\\";
81 path += kDllName;
82
83 const string version_string = SystemUtil::GetFileVersionString(path);
84
85 vector<string> numbers;
86 Util::SplitStringUsing(version_string, ".", &numbers);
87
88 // must be 4 digits.
89 ASSERT_EQ(numbers.size(), 4);
90
91 // must be integer.
92 uint32 dummy = 0;
93 ASSERT_TRUE(NumberUtil::SafeStrToUInt32(numbers[0], &dummy));
94 ASSERT_TRUE(NumberUtil::SafeStrToUInt32(numbers[1], &dummy));
95 ASSERT_TRUE(NumberUtil::SafeStrToUInt32(numbers[2], &dummy));
96 ASSERT_TRUE(NumberUtil::SafeStrToUInt32(numbers[3], &dummy));
97 }
98 #endif // OS_WIN
99
10063 #ifndef OS_NACL
10164 TEST_F(SystemUtilTest, GetTotalPhysicalMemoryTest) {
10265 EXPECT_GT(SystemUtil::GetTotalPhysicalMemory(), 0);
00 MAJOR=2
11 MINOR=17
2 BUILD=2491
2 BUILD=2492
33 REVISION=102
44 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
55 # downloaded by NaCl Mozc.
9797 },
9898 'VCLinkerTool': {
9999 'DelayLoadDLLs': [
100 'version.dll',
101100 'wininet.dll',
102101 ],
103102 },
3535
3636 #include <string>
3737
38 #include "base/system_util.h"
3938 #include "base/util.h"
4039 #include "base/win_util.h"
4140 #include "win32/base/accessible_object.h"
6968 }
7069
7170 } // namespace
72
73 BrowserInfo::Version::Version()
74 : major(0),
75 minor(0),
76 build(0),
77 revision(0) {}
7871
7972 // static
8073 BrowserInfo::BrowserType BrowserInfo::GetBrowerType() {
189182 }
190183
191184 // static
192 BrowserInfo::Version BrowserInfo::GetProcessModuleVersion() {
193 if (!g_exe_module_ver_initialized_) {
194 bool loder_locked = false;
195 if (!WinUtil::IsDLLSynchronizationHeld(&loder_locked) ||
196 loder_locked) {
197 return Version();
198 }
199
200 const wstring &exe_path = GetProcessModuleName();
201 if (!exe_path.empty()) {
202 SystemUtil::GetFileVersion(exe_path,
203 &g_exe_module_ver_major_,
204 &g_exe_module_ver_minor_,
205 &g_exe_module_ver_build_,
206 &g_exe_module_ver_revision_);
207 }
208 g_exe_module_ver_initialized_ = true;
209 }
210
211 Version version;
212 version.major = g_exe_module_ver_major_;
213 version.minor = g_exe_module_ver_minor_;
214 version.build = g_exe_module_ver_build_;
215 version.revision = g_exe_module_ver_revision_;
216 return version;
217 }
218
219 // static
220185 void BrowserInfo::OnDllProcessAttach(HINSTANCE module_handle,
221186 bool static_loading) {
222187 const DWORD copied_len_without_null = ::GetModuleFileName(
4747 kBrowserTypeIE,
4848 kBrowserTypeOpera,
4949 };
50 struct Version {
51 Version();
52 int major;
53 int minor;
54 int build;
55 int revision;
56 };
5750
5851 static BrowserType GetBrowerType();
59 static Version GetProcessModuleVersion();
6052
6153 static bool IsInIncognitoMode(
6254 const FocusHierarchyObserver &focus_hierarchy_observer);