diff options
author | pasko@chromium.org <pasko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-04 17:02:53 +0000 |
---|---|---|
committer | pasko@chromium.org <pasko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-04 17:02:53 +0000 |
commit | 88f3561a8feea33ba5fa4b11abe5eb5b6339f9f9 (patch) | |
tree | 7094b7903dccfc303ca9f974e98f903679f0d3dd /net/disk_cache | |
parent | 44c1357d307979826a9bf26fa6a2b2b71b460df6 (diff) | |
download | chromium_src-88f3561a8feea33ba5fa4b11abe5eb5b6339f9f9.zip chromium_src-88f3561a8feea33ba5fa4b11abe5eb5b6339f9f9.tar.gz chromium_src-88f3561a8feea33ba5fa4b11abe5eb5b6339f9f9.tar.bz2 |
Revert 220123 "Remove simple_util::GetMTime from simple cache."
> Remove simple_util::GetMTime from simple cache.
>
> With base::PlatformFile::GetPlatformFileInfo now being high resolution, there's
> no need for this system specific cruft in the simple disk cache.
>
> R=clamy,pasko
> BUG=None
>
> Review URL: https://chromiumcodereview.appspot.com/22571011
Reason: GetFileInfo is being used, and it is not high resolution right now.
TBR=gavinp@chromium.org
Review URL: https://codereview.chromium.org/23597016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221206 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/simple/simple_backend_impl.cc | 7 | ||||
-rw-r--r-- | net/disk_cache/simple/simple_index_file.cc | 13 | ||||
-rw-r--r-- | net/disk_cache/simple/simple_index_file_unittest.cc | 34 | ||||
-rw-r--r-- | net/disk_cache/simple/simple_synchronous_entry.cc | 6 | ||||
-rw-r--r-- | net/disk_cache/simple/simple_util.cc | 12 | ||||
-rw-r--r-- | net/disk_cache/simple/simple_util.h | 6 |
6 files changed, 47 insertions, 31 deletions
diff --git a/net/disk_cache/simple/simple_backend_impl.cc b/net/disk_cache/simple/simple_backend_impl.cc index 191d903..9ae613f 100644 --- a/net/disk_cache/simple/simple_backend_impl.cc +++ b/net/disk_cache/simple/simple_backend_impl.cc @@ -411,10 +411,9 @@ SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk( << path.LossyDisplayName(); result.net_error = net::ERR_FAILED; } else { - base::PlatformFileInfo file_info; - bool file_info_result = file_util::GetFileInfo(path, &file_info); - DCHECK(file_info_result); - result.cache_dir_mtime = file_info.last_modified; + bool mtime_result = + disk_cache::simple_util::GetMTime(path, &result.cache_dir_mtime); + DCHECK(mtime_result); if (!result.max_size) { int64 available = base::SysInfo::AmountOfFreeDiskSpace(path); if (available < 0) diff --git a/net/disk_cache/simple/simple_index_file.cc b/net/disk_cache/simple/simple_index_file.cc index 9f92906..61318c8 100644 --- a/net/disk_cache/simple/simple_index_file.cc +++ b/net/disk_cache/simple/simple_index_file.cc @@ -250,10 +250,9 @@ void SimpleIndexFile::SyncLoadIndexEntries( index_file_state = INDEX_STATE_STALE; } else { index_file_state = INDEX_STATE_FRESH; - base::PlatformFileInfo file_info; - bool file_info_result = file_util::GetFileInfo(index_file_path, &file_info); - DCHECK(file_info_result); - if (IsIndexFileStale(file_info.last_modified, index_file_path)) { + base::Time latest_dir_mtime; + if (simple_util::GetMTime(cache_directory, &latest_dir_mtime) && + IsIndexFileStale(latest_dir_mtime, index_file_path)) { // A file operation has updated the directory since we last looked at it // during backend initialization. index_file_state = INDEX_STATE_FRESH_CONCURRENT_UPDATES; @@ -431,10 +430,10 @@ void SimpleIndexFile::SyncRestoreFromDisk( // static bool SimpleIndexFile::IsIndexFileStale(base::Time cache_last_modified, const base::FilePath& index_file_path) { - base::PlatformFileInfo file_info; - if (!file_util::GetFileInfo(index_file_path, &file_info)) + base::Time index_mtime; + if (!simple_util::GetMTime(index_file_path, &index_mtime)) return true; - return file_info.last_modified < cache_last_modified; + return index_mtime < cache_last_modified; } } // namespace disk_cache diff --git a/net/disk_cache/simple/simple_index_file_unittest.cc b/net/disk_cache/simple/simple_index_file_unittest.cc index 2d81352..b75237e 100644 --- a/net/disk_cache/simple/simple_index_file_unittest.cc +++ b/net/disk_cache/simple/simple_index_file_unittest.cc @@ -138,34 +138,34 @@ TEST_F(SimpleIndexFileTest, Serialize) { TEST_F(SimpleIndexFileTest, IsIndexFileStale) { base::ScopedTempDir cache_dir; ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); - base::PlatformFileInfo file_info; + base::Time cache_mtime; const base::FilePath cache_path = cache_dir.path(); - ASSERT_TRUE(file_util::GetFileInfo(cache_path, &file_info)); + ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime)); WrappedSimpleIndexFile simple_index_file(cache_path); const base::FilePath& index_path = simple_index_file.GetIndexFilePath(); - EXPECT_TRUE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified, + EXPECT_TRUE(WrappedSimpleIndexFile::IsIndexFileStale(cache_mtime, index_path)); const std::string kDummyData = "nothing to be seen here"; EXPECT_EQ(static_cast<int>(kDummyData.size()), file_util::WriteFile(index_path, kDummyData.data(), kDummyData.size())); - ASSERT_TRUE(file_util::GetFileInfo(cache_path, &file_info)); - EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified, + ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime)); + EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(cache_mtime, index_path)); const base::Time past_time = base::Time::Now() - base::TimeDelta::FromSeconds(10); EXPECT_TRUE(file_util::TouchFile(index_path, past_time, past_time)); EXPECT_TRUE(file_util::TouchFile(cache_path, past_time, past_time)); - ASSERT_TRUE(file_util::GetFileInfo(cache_path, &file_info)); - EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified, + ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime)); + EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(cache_mtime, index_path)); const base::Time even_older = past_time - base::TimeDelta::FromSeconds(10); EXPECT_TRUE(file_util::TouchFile(index_path, even_older, even_older)); - EXPECT_TRUE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified, + EXPECT_TRUE(WrappedSimpleIndexFile::IsIndexFileStale(cache_mtime, index_path)); } @@ -194,11 +194,11 @@ TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) { } WrappedSimpleIndexFile simple_index_file(cache_dir.path()); - base::PlatformFileInfo file_info; - ASSERT_TRUE(file_util::GetFileInfo(simple_index_file.GetIndexFilePath(), - &file_info)); + base::Time fake_cache_mtime; + ASSERT_TRUE(simple_util::GetMTime(simple_index_file.GetIndexFilePath(), + &fake_cache_mtime)); SimpleIndexLoadResult load_index_result; - simple_index_file.LoadIndexEntries(file_info.last_modified, + simple_index_file.LoadIndexEntries(fake_cache_mtime, GetCallback(), &load_index_result); base::RunLoop().RunUntilIdle(); @@ -224,14 +224,14 @@ TEST_F(SimpleIndexFileTest, LoadCorruptIndex) { file_util::WriteFile(index_path, kDummyData.data(), kDummyData.size())); - base::PlatformFileInfo file_info; - ASSERT_TRUE(file_util::GetFileInfo(simple_index_file.GetIndexFilePath(), - &file_info)); - EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified, + base::Time fake_cache_mtime; + ASSERT_TRUE(simple_util::GetMTime(simple_index_file.GetIndexFilePath(), + &fake_cache_mtime)); + EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(fake_cache_mtime, index_path)); SimpleIndexLoadResult load_index_result; - simple_index_file.LoadIndexEntries(file_info.last_modified, + simple_index_file.LoadIndexEntries(fake_cache_mtime, GetCallback(), &load_index_result); base::RunLoop().RunUntilIdle(); diff --git a/net/disk_cache/simple/simple_synchronous_entry.cc b/net/disk_cache/simple/simple_synchronous_entry.cc index d06b9a9..ed91fab 100644 --- a/net/disk_cache/simple/simple_synchronous_entry.cc +++ b/net/disk_cache/simple/simple_synchronous_entry.cc @@ -524,12 +524,16 @@ bool SimpleSynchronousEntry::OpenOrCreateFiles( for (int i = 0; i < kSimpleEntryFileCount; ++i) { PlatformFileInfo file_info; bool success = GetPlatformFileInfo(files_[i], &file_info); + base::Time file_last_modified; if (!success) { DLOG(WARNING) << "Could not get platform file info."; continue; } out_entry_stat->last_used = file_info.last_accessed; - out_entry_stat->last_modified = file_info.last_modified; + if (simple_util::GetMTime(path_, &file_last_modified)) + out_entry_stat->last_modified = file_last_modified; + else + out_entry_stat->last_modified = file_info.last_modified; base::TimeDelta entry_age = base::Time::Now() - out_entry_stat->last_modified; diff --git a/net/disk_cache/simple/simple_util.cc b/net/disk_cache/simple/simple_util.cc index 2317549..e9ec067 100644 --- a/net/disk_cache/simple/simple_util.cc +++ b/net/disk_cache/simple/simple_util.cc @@ -85,6 +85,16 @@ int64 GetFileOffsetFromKeyAndDataOffset(const std::string& key, return headers_size + data_offset; } -} // namespace simple_util +// TODO(clamy, gavinp): this should go in base +bool GetMTime(const base::FilePath& path, base::Time* out_mtime) { + DCHECK(out_mtime); + base::PlatformFileInfo file_info; + if (!file_util::GetFileInfo(path, &file_info)) + return false; + *out_mtime = file_info.last_modified; + return true; +} + +} // namespace simple_backend } // namespace disk_cache diff --git a/net/disk_cache/simple/simple_util.h b/net/disk_cache/simple/simple_util.h index 154ee23..3bb80b9 100644 --- a/net/disk_cache/simple/simple_util.h +++ b/net/disk_cache/simple/simple_util.h @@ -63,7 +63,11 @@ NET_EXPORT_PRIVATE int64 GetFileOffsetFromKeyAndDataOffset( const std::string& key, int data_offset); -} // namespace simple_util +// Fills |out_time| with the time the file last modified time. +// TODO(gavinp): Remove this function. +NET_EXPORT_PRIVATE bool GetMTime(const base::FilePath& path, + base::Time* out_mtime); +} // namespace simple_backend } // namespace disk_cache |