Skip to content

Commit

Permalink
Moving file_util::FileInfo to base::PlatformFileInfo, and adding the
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dumi@chromium.org committed Sep 3, 2010
1 parent 4c56ef5 commit 2f0193c
Show file tree
Hide file tree
Showing 42 changed files with 298 additions and 279 deletions.
2 changes: 1 addition & 1 deletion base/file_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 1 addition & 15 deletions base/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion base/file_util_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion base/file_util_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions base/file_util_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion base/file_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions base/file_util_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions base/platform_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions base/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/browsing_data_database_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void BrowsingDataDatabaseHelper::FetchDatabaseInfoInFileThread() {
for (std::vector<string16>::const_iterator db = databases.begin();
db != databases.end(); ++db) {
FilePath file_path = tracker_->GetFullDBFilePath(ori->GetOrigin(), *db);
file_util::FileInfo file_info;
base::PlatformFileInfo file_info;
if (file_util::GetFileInfo(file_path, &file_info)) {
database_info_.push_back(DatabaseInfo(
web_security_origin.host().utf8(),
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/browsing_data_local_storage_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void BrowsingDataLocalStorageHelper::FetchLocalStorageInfoInWebKitThread() {
// Extension state is not considered browsing data.
continue;
}
file_util::FileInfo file_info;
base::PlatformFileInfo file_info;
bool ret = file_util::GetFileInfo(file_path, &file_info);
if (ret) {
local_storage_info_.push_back(LocalStorageInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ TEST_F(SandboxedExtensionUnpackerTest, WithCatalogsSuccess) {
messages_file = GetInstallPath().Append(Extension::kLocaleFolder)
.AppendASCII("en_US")
.Append(Extension::kMessagesFilename);
file_util::FileInfo old_info;
base::PlatformFileInfo old_info;
EXPECT_TRUE(file_util::GetFileInfo(messages_file, &old_info));

// unpacker_->Run unpacks the extension. OnUnpackSucceeded overwrites some
Expand All @@ -191,7 +191,7 @@ TEST_F(SandboxedExtensionUnpackerTest, WithCatalogsSuccess) {
OnUnpackSucceeded();

// Check that there is newer _locales/en_US/messages.json file.
file_util::FileInfo new_info;
base::PlatformFileInfo new_info;
EXPECT_TRUE(file_util::GetFileInfo(messages_file, &new_info));

EXPECT_TRUE(new_info.last_modified > old_info.last_modified);
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/file_path_watcher_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void FilePathWatcherImpl::OnFilePathChanged() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
DCHECK(!target_.empty());

file_util::FileInfo file_info;
base::PlatformFileInfo file_info;
bool file_exists = file_util::GetFileInfo(target_, &file_info);
if (file_exists && (last_modified_.is_null() ||
last_modified_ != file_info.last_modified)) {
Expand Down Expand Up @@ -150,7 +150,7 @@ bool FilePathWatcherImpl::Watch(const FilePath& path,

FSEventStreamEventId start_event = FSEventsGetCurrentEventId();

file_util::FileInfo file_info;
base::PlatformFileInfo file_info;
if (file_util::GetFileInfo(target_, &file_info)) {
last_modified_ = file_info.last_modified;
first_notification_ = base::Time::Now();
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/file_path_watcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void FilePathWatcherImpl::OnObjectSignaled(HANDLE object) {
}

// Check whether the event applies to |target_| and notify the delegate.
file_util::FileInfo file_info;
base::PlatformFileInfo file_info;
bool file_exists = file_util::GetFileInfo(target_, &file_info);
if (file_exists && (last_modified_.is_null() ||
last_modified_ != file_info.last_modified)) {
Expand Down Expand Up @@ -183,7 +183,7 @@ bool FilePathWatcherImpl::UpdateWatch() {
if (handle_ != INVALID_HANDLE_VALUE)
DestroyWatch();

file_util::FileInfo file_info;
base::PlatformFileInfo file_info;
if (file_util::GetFileInfo(target_, &file_info)) {
last_modified_ = file_info.last_modified;
first_notification_ = base::Time::Now();
Expand Down
Loading

0 comments on commit 2f0193c

Please sign in to comment.