summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpasko@chromium.org <pasko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-05 19:21:24 +0000
committerpasko@chromium.org <pasko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-05 19:21:24 +0000
commitda93365df4a410d37110a739fb06980792b32f78 (patch)
treed9504486b12412082065a8253e5b08b3601748d6
parente1df9eab568c6c03733c4e6889099c5afa643f26 (diff)
downloadchromium_src-da93365df4a410d37110a739fb06980792b32f78.zip
chromium_src-da93365df4a410d37110a739fb06980792b32f78.tar.gz
chromium_src-da93365df4a410d37110a739fb06980792b32f78.tar.bz2
Simple Cache: restore the high-res timer
This *reverts* the parts of high-res timing that was moved out from simple cache in attempt to have it in base/, here: http://src.chromium.org/viewvc/chrome?view=revision&revision=216478 The changes in base/ are untouched today. This partial revert should be safe because this change just adds (un-removes) a different implementation and switches simple cache to using it. The bug being blocked by this deficiency is in the BUG field, we do not have a specific bug for the problem, it would have required age restriction on the audience. BUG=261618 Review URL: https://chromiumcodereview.appspot.com/23819025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221492 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/disk_cache/simple/simple_util.cc33
-rw-r--r--net/disk_cache/simple/simple_util.h4
2 files changed, 35 insertions, 2 deletions
diff --git a/net/disk_cache/simple/simple_util.cc b/net/disk_cache/simple/simple_util.cc
index e9ec067..4a89f9b 100644
--- a/net/disk_cache/simple/simple_util.cc
+++ b/net/disk_cache/simple/simple_util.cc
@@ -21,6 +21,25 @@ namespace {
// Size of the uint64 hash_key number in Hex format in a string.
const size_t kEntryHashKeyAsHexStringSize = 2 * sizeof(uint64);
+// TODO(clamy, gavinp): this should go in base
+bool GetNanoSecsFromStat(const struct stat& st,
+ time_t* out_sec,
+ long* out_nsec) {
+#if defined(OS_ANDROID)
+ *out_sec = st.st_mtime;
+ *out_nsec = st.st_mtime_nsec;
+#elif defined(OS_LINUX)
+ *out_sec = st.st_mtim.tv_sec;
+ *out_nsec = st.st_mtim.tv_nsec;
+#elif defined(OS_MACOSX) || defined(OS_IOS) || defined(OS_BSD)
+ *out_sec = st.st_mtimespec.tv_sec;
+ *out_nsec = st.st_mtimespec.tv_nsec;
+#else
+ return false;
+#endif
+ return true;
+}
+
} // namespace
namespace disk_cache {
@@ -88,6 +107,20 @@ int64 GetFileOffsetFromKeyAndDataOffset(const std::string& key,
// TODO(clamy, gavinp): this should go in base
bool GetMTime(const base::FilePath& path, base::Time* out_mtime) {
DCHECK(out_mtime);
+#if defined(OS_POSIX)
+ base::ThreadRestrictions::AssertIOAllowed();
+ struct stat file_stat;
+ if (stat(path.value().c_str(), &file_stat) != 0)
+ return false;
+ time_t sec;
+ long nsec;
+ if (GetNanoSecsFromStat(file_stat, &sec, &nsec)) {
+ int64 usec = (nsec / base::Time::kNanosecondsPerMicrosecond);
+ *out_mtime = base::Time::FromTimeT(sec)
+ + base::TimeDelta::FromMicroseconds(usec);
+ return true;
+ }
+#endif
base::PlatformFileInfo file_info;
if (!file_util::GetFileInfo(path, &file_info))
return false;
diff --git a/net/disk_cache/simple/simple_util.h b/net/disk_cache/simple/simple_util.h
index 3bb80b9..ef51869 100644
--- a/net/disk_cache/simple/simple_util.h
+++ b/net/disk_cache/simple/simple_util.h
@@ -63,8 +63,8 @@ NET_EXPORT_PRIVATE int64 GetFileOffsetFromKeyAndDataOffset(
const std::string& key,
int data_offset);
-// Fills |out_time| with the time the file last modified time.
-// TODO(gavinp): Remove this function.
+// Fills |out_time| with the time the file last modified time. Unlike the
+// functions in platform_file.h, the time resolution is milliseconds.
NET_EXPORT_PRIVATE bool GetMTime(const base::FilePath& path,
base::Time* out_mtime);
} // namespace simple_backend