diff options
author | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-17 21:34:59 +0000 |
---|---|---|
committer | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-17 21:34:59 +0000 |
commit | 75a26d89c3b7517f2fbd5b67e21cb35185f1994f (patch) | |
tree | e5a1898f0038e0076c7ea7110aefc387f7e9a376 /chrome | |
parent | d1dccfcc206dcda315eba4f07c602f665203a6e5 (diff) | |
download | chromium_src-75a26d89c3b7517f2fbd5b67e21cb35185f1994f.zip chromium_src-75a26d89c3b7517f2fbd5b67e21cb35185f1994f.tar.gz chromium_src-75a26d89c3b7517f2fbd5b67e21cb35185f1994f.tar.bz2 |
Switch from wcsftime to GetDateFormat to avoid crash in setup.
TEST=Fix for crash in setup. See bug for details.
BUG=73212
Review URL: http://codereview.chromium.org/6533009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75305 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/installer/setup/install_worker.cc | 13 | ||||
-rw-r--r-- | chrome/installer/util/install_util.cc | 14 | ||||
-rw-r--r-- | chrome/installer/util/install_util.h | 3 | ||||
-rw-r--r-- | chrome/installer/util/install_util_unittest.cc | 19 |
4 files changed, 40 insertions, 9 deletions
diff --git a/chrome/installer/setup/install_worker.cc b/chrome/installer/setup/install_worker.cc index bfb03eb..46eb559 100644 --- a/chrome/installer/setup/install_worker.cc +++ b/chrome/installer/setup/install_worker.cc @@ -220,15 +220,10 @@ void AddUninstallShortcutWorkItems(const InstallerState& installer_state, L"DisplayVersion", UTF8ToWide(new_version.GetString()), true); - time_t rawtime = time(NULL); - struct tm timeinfo = {0}; - localtime_s(&timeinfo, &rawtime); - wchar_t buffer[9]; - if (wcsftime(buffer, 9, L"%Y%m%d", &timeinfo) == 8) { - install_list->AddSetRegValueWorkItem(reg_root, uninstall_reg, - L"InstallDate", - buffer, false); - } + install_list->AddSetRegValueWorkItem(reg_root, uninstall_reg, + L"InstallDate", + InstallUtil::GetCurrentDate(), + false); } } diff --git a/chrome/installer/util/install_util.cc b/chrome/installer/util/install_util.cc index bc0a656..78642fc 100644 --- a/chrome/installer/util/install_util.cc +++ b/chrome/installer/util/install_util.cc @@ -263,3 +263,17 @@ void InstallUtil::MakeUninstallCommand(const std::wstring& exe_path, *command_line = CommandLine::FromString(command); } } + +std::wstring InstallUtil::GetCurrentDate() { + static const wchar_t kDateFormat[] = L"yyyyMMdd"; + wchar_t date_str[arraysize(kDateFormat)] = {0}; + int len = GetDateFormatW(LOCALE_INVARIANT, 0, NULL, kDateFormat, + date_str, arraysize(date_str)); + if (len) { + --len; // Subtract terminating \0. + } else { + PLOG(DFATAL) << "GetDateFormat"; + } + + return std::wstring(date_str, len); +} diff --git a/chrome/installer/util/install_util.h b/chrome/installer/util/install_util.h index 0ce5758..98cbc6d 100644 --- a/chrome/installer/util/install_util.h +++ b/chrome/installer/util/install_util.h @@ -112,6 +112,9 @@ class InstallUtil { const std::wstring& arguments, CommandLine* command_line); + // Returns a string in the form YYYYMMDD of the current date. + static std::wstring GetCurrentDate(); + private: DISALLOW_COPY_AND_ASSIGN(InstallUtil); }; diff --git a/chrome/installer/util/install_util_unittest.cc b/chrome/installer/util/install_util_unittest.cc index a5cb86f..37e38bc 100644 --- a/chrome/installer/util/install_util_unittest.cc +++ b/chrome/installer/util/install_util_unittest.cc @@ -102,3 +102,22 @@ TEST_F(InstallUtilTest, MakeUninstallCommand) { } } } + +TEST_F(InstallUtilTest, GetCurrentDate) { + std::wstring date(InstallUtil::GetCurrentDate()); + EXPECT_EQ(8, date.length()); + if (date.length() == 8) { + // For an invalid date value, SystemTimeToFileTime will fail. + // We use this to validate that we have a correct date string. + SYSTEMTIME systime = {0}; + FILETIME ft = {0}; + // Just to make sure our assumption holds. + EXPECT_FALSE(SystemTimeToFileTime(&systime, &ft)); + // Now fill in the values from our string. + systime.wYear = _wtoi(date.substr(0, 4).c_str()); + systime.wMonth = _wtoi(date.substr(4, 2).c_str()); + systime.wDay = _wtoi(date.substr(6, 2).c_str()); + // Check if they make sense. + EXPECT_TRUE(SystemTimeToFileTime(&systime, &ft)); + } +} |