diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-15 16:39:17 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-15 16:39:17 +0000 |
commit | a4cbaa5de0dc12cfbbe5e9a4ddccd8d24329a995 (patch) | |
tree | 02b41210767c574660a844d9bc772ff43dc4cf9e /base | |
parent | 74eb4ceef0aee9d59839816800016a150a8e446f (diff) | |
download | chromium_src-a4cbaa5de0dc12cfbbe5e9a4ddccd8d24329a995.zip chromium_src-a4cbaa5de0dc12cfbbe5e9a4ddccd8d24329a995.tar.gz chromium_src-a4cbaa5de0dc12cfbbe5e9a4ddccd8d24329a995.tar.bz2 |
Submitting http://codereview.chromium.org/73075 on behalf of shinichiro.hamaji@gmail.com
Review URL: http://codereview.chromium.org/73083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13748 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/file_util.h | 11 | ||||
-rw-r--r-- | base/file_util_unittest.cc | 17 | ||||
-rw-r--r-- | base/file_util_win.cc | 11 |
3 files changed, 21 insertions, 18 deletions
diff --git a/base/file_util.h b/base/file_util.h index 6c916dd..20d98b0 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -27,6 +27,10 @@ #include "base/scoped_ptr.h" #include "base/file_path.h" +namespace base { +class Time; +} + namespace file_util { //----------------------------------------------------------------------------- @@ -135,10 +139,9 @@ void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char); #if defined(OS_WIN) // Returns the number of files matching the current path that were -// created on or after the given FILETIME. Doesn't count ".." or ".". -// Filetime is UTC filetime, not LocalFiletime. -int CountFilesCreatedAfter(const std::wstring& path, - const FILETIME& file_time); +// created on or after the given |file_time|. Doesn't count ".." or ".". +int CountFilesCreatedAfter(const FilePath& path, + const base::Time& file_time); #endif // defined(OS_WIN) // Deletes the given path, whether it's a file or a directory. diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index 7f24fc5..df30817 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -20,6 +20,7 @@ #include "base/logging.h" #include "base/path_service.h" #include "base/string_util.h" +#include "base/time.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -316,30 +317,26 @@ TEST_F(FileUtilTest, GetDirectoryFromPath) { #if defined OS_WIN TEST_F(FileUtilTest, CountFilesCreatedAfter) { // Create old file (that we don't want to count) - FilePath old_file_name = test_dir_.Append(L"Old File.txt"); + FilePath old_file_name = test_dir_.Append(FILE_PATH_LITERAL("Old File.txt")); CreateTextFile(old_file_name, L"Just call me Mr. Creakybits"); // Age to perfection Sleep(100); // Establish our cutoff time - FILETIME test_start_time; - GetSystemTimeAsFileTime(&test_start_time); - EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_.value(), - test_start_time)); + base::Time now(base::Time::Now()); + EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); // Create a new file (that we do want to count) - FilePath new_file_name = test_dir_.Append(L"New File.txt"); + FilePath new_file_name = test_dir_.Append(FILE_PATH_LITERAL("New File.txt")); CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah."); // We should see only the new file. - EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_.value(), - test_start_time)); + EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_, now)); // Delete new file, we should see no files after cutoff now EXPECT_TRUE(file_util::Delete(new_file_name, false)); - EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_.value(), - test_start_time)); + EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); } #endif diff --git a/base/file_util_win.cc b/base/file_util_win.cc index 841cd28..8b3d4f5 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -14,6 +14,7 @@ #include "base/logging.h" #include "base/scoped_handle.h" #include "base/string_util.h" +#include "base/time.h" #include "base/win_util.h" namespace file_util { @@ -39,12 +40,14 @@ bool AbsolutePath(FilePath* path) { return true; } -int CountFilesCreatedAfter(const std::wstring& path, - const FILETIME& comparison_time) { +int CountFilesCreatedAfter(const FilePath& path, + const base::Time& comparison_time) { int file_count = 0; + FILETIME comparison_filetime(comparison_time.ToFileTime()); WIN32_FIND_DATA find_file_data; - std::wstring filename_spec = path + L"\\*"; // All files in given dir + // All files in given dir + std::wstring filename_spec = path.Append(L"*").value(); HANDLE find_handle = FindFirstFile(filename_spec.c_str(), &find_file_data); if (find_handle != INVALID_HANDLE_VALUE) { do { @@ -54,7 +57,7 @@ int CountFilesCreatedAfter(const std::wstring& path, continue; long result = CompareFileTime(&find_file_data.ftCreationTime, - &comparison_time); + &comparison_filetime); // File was created after or on comparison time if ((result == 1) || (result == 0)) ++file_count; |