diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 02:28:37 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-03 02:28:37 +0000 |
commit | 2f0193c279b1b40a82a6ad027ec9468272eb25b2 (patch) | |
tree | 9d2e2f5bcf09837a1189723567906fb8de45c7e2 /base | |
parent | 4c56ef5fbed46794f2b16b9f8ed88ac179d65309 (diff) | |
download | chromium_src-2f0193c279b1b40a82a6ad027ec9468272eb25b2.zip chromium_src-2f0193c279b1b40a82a6ad027ec9468272eb25b2.tar.gz chromium_src-2f0193c279b1b40a82a6ad027ec9468272eb25b2.tar.bz2 |
Moving file_util::FileInfo to base::PlatformFileInfo, and adding the
last_accessed and creation_time fields.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3347005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58454 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/file_util.cc | 2 | ||||
-rw-r--r-- | base/file_util.h | 16 | ||||
-rw-r--r-- | base/file_util_posix.cc | 4 | ||||
-rw-r--r-- | base/file_util_proxy.cc | 2 | ||||
-rw-r--r-- | base/file_util_proxy.h | 7 | ||||
-rw-r--r-- | base/file_util_unittest.cc | 2 | ||||
-rw-r--r-- | base/file_util_win.cc | 6 | ||||
-rw-r--r-- | base/platform_file.h | 24 | ||||
-rw-r--r-- | base/time.h | 1 |
9 files changed, 38 insertions, 26 deletions
diff --git a/base/file_util.cc b/base/file_util.cc index 4dae03b..e618903 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -185,7 +185,7 @@ FILE* CreateAndOpenTemporaryFile(FilePath* path) { } bool GetFileSize(const FilePath& file_path, int64* file_size) { - FileInfo info; + base::PlatformFileInfo info; if (!GetFileInfo(file_path, &info)) return false; *file_size = info.size; diff --git a/base/file_util.h b/base/file_util.h index ce30b5e..415a192 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -315,22 +315,8 @@ bool NormalizeFilePath(const FilePath& path, FilePath* real_path); bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path); #endif -// Used to hold information about a given file path. See GetFileInfo below. -struct FileInfo { - // The size of the file in bytes. Undefined when is_directory is true. - int64 size; - - // True if the file corresponds to a directory. - bool is_directory; - - // The last modified time of a file. - base::Time last_modified; - - // Add additional fields here as needed. -}; - // Returns information about the given file path. -bool GetFileInfo(const FilePath& file_path, FileInfo* info); +bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* info); // Set the time of the last modification. Useful for unit tests. bool SetLastModifiedTime(const FilePath& file_path, base::Time last_modified); diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index 13798d3..99e15fe 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -474,13 +474,15 @@ bool CreateDirectory(const FilePath& full_path) { return true; } -bool GetFileInfo(const FilePath& file_path, FileInfo* results) { +bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { stat_wrapper_t file_info; if (CallStat(file_path.value().c_str(), &file_info) != 0) return false; results->is_directory = S_ISDIR(file_info.st_mode); results->size = file_info.st_size; results->last_modified = base::Time::FromTimeT(file_info.st_mtime); + results->last_accessed = base::Time::FromTimeT(file_info.st_atime); + results->creation_time = base::Time::FromTimeT(file_info.st_ctime); return true; } diff --git a/base/file_util_proxy.cc b/base/file_util_proxy.cc index d356ed3..1e6100e 100644 --- a/base/file_util_proxy.cc +++ b/base/file_util_proxy.cc @@ -423,7 +423,7 @@ class RelayGetFileInfo : public MessageLoopRelay { private: base::FileUtilProxy::GetFileInfoCallback* callback_; FilePath file_path_; - file_util::FileInfo file_info_; + base::PlatformFileInfo file_info_; }; bool Start(const tracked_objects::Location& from_here, diff --git a/base/file_util_proxy.h b/base/file_util_proxy.h index 3fe7d58..9e9b95e 100644 --- a/base/file_util_proxy.h +++ b/base/file_util_proxy.h @@ -14,10 +14,6 @@ #include "base/ref_counted.h" #include "base/tracked_objects.h" -namespace file_util { -struct FileInfo; -} - namespace base { namespace file_util_proxy { @@ -31,6 +27,7 @@ struct Entry { } // namespace file_util_proxy class MessageLoopProxy; +class Time; // This class provides asynchronous access to common file routines. class FileUtilProxy { @@ -68,7 +65,7 @@ class FileUtilProxy { // Retrieves the information about a file. It is invalid to pass NULL for the // callback. typedef Callback2<base::PlatformFileError /* error code */, - const file_util::FileInfo& /*file_info*/ + const base::PlatformFileInfo& /* file_info */ >::Type GetFileInfoCallback; static bool GetFileInfo( scoped_refptr<MessageLoopProxy> message_loop_proxy, diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index 26eb42d..b0bd274 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -1777,7 +1777,7 @@ TEST_F(FileUtilTest, LastModified) { ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", &modification_time)); ASSERT_TRUE(file_util::SetLastModifiedTime(foobar, modification_time)); - file_util::FileInfo file_info; + base::PlatformFileInfo file_info; ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info)); ASSERT_TRUE(file_info.last_modified == modification_time); } diff --git a/base/file_util_win.cc b/base/file_util_win.cc index cef0df4..f538c20 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -127,7 +127,7 @@ bool Delete(const FilePath& path, bool recursive) { if (!recursive) { // If not recursing, then first check to see if |path| is a directory. // If it is, then remove it with RemoveDirectory. - FileInfo file_info; + base::PlatformFileInfo file_info; if (GetFileInfo(path, &file_info) && file_info.is_directory) return RemoveDirectory(path.value().c_str()) != 0; @@ -675,7 +675,7 @@ bool CreateDirectoryExtraLogging(const FilePath& full_path, } } -bool GetFileInfo(const FilePath& file_path, FileInfo* results) { +bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { WIN32_FILE_ATTRIBUTE_DATA attr; if (!GetFileAttributesEx(file_path.value().c_str(), GetFileExInfoStandard, &attr)) { @@ -690,6 +690,8 @@ bool GetFileInfo(const FilePath& file_path, FileInfo* results) { results->is_directory = (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; results->last_modified = base::Time::FromFileTime(attr.ftLastWriteTime); + results->last_accessed = base::Time::FromFileTime(attr.ftLastAccessTime); + results->creation_time = base::Time::FromFileTime(attr.ftCreationTime); return true; } diff --git a/base/platform_file.h b/base/platform_file.h index 0e4d05c..802102c 100644 --- a/base/platform_file.h +++ b/base/platform_file.h @@ -6,7 +6,9 @@ #define BASE_PLATFORM_FILE_H_ #pragma once +#include "base/basictypes.h" #include "build/build_config.h" +#include "base/time.h" #if defined(OS_WIN) #include <windows.h> #endif @@ -55,6 +57,28 @@ enum PlatformFileError { PLATFORM_FILE_ERROR_INVALID_OPERATION = -10 }; +// Used to hold information about a given file. +// If you add more fields to this structure (platform-specific fields are OK), +// make sure to update all functions that use it in file_util_{win|posix}.cc +// too, and the ParamTraits<base::PlatformFileInfo> implementation in +// chrome/common/common_param_traits.cc. +struct PlatformFileInfo { + // The size of the file in bytes. Undefined when is_directory is true. + int64 size; + + // True if the file corresponds to a directory. + bool is_directory; + + // The last modified time of a file. + base::Time last_modified; + + // The last accessed time of a file. + base::Time last_accessed; + + // The creation time of a file. + base::Time creation_time; +}; + // Creates or opens the given file. If PLATFORM_FILE_OPEN_ALWAYS is used, and // |created| is provided, |created| will be set to true if the file was created // or to false in case the file was just opened. |error_code| can be NULL. diff --git a/base/time.h b/base/time.h index 539cc14..0f5eb5d 100644 --- a/base/time.h +++ b/base/time.h @@ -259,6 +259,7 @@ class Time { #if defined(OS_WIN) static Time FromFileTime(FILETIME ft); FILETIME ToFileTime() const; + static Time FromLargeInteger(LARGE_INTEGER li); // The minimum time of a low resolution timer. This is basically a windows // constant of ~15.6ms. While it does vary on some older OS versions, we'll |