From d4317501c52ed475d91a56cb25deaa68abef4667 Mon Sep 17 00:00:00 2001 From: Oliver Henshaw Date: Tue, 20 Oct 2015 10:45:25 +0530 Subject: [PATCH] Bug 1180715 (1/4) - Track image LoadTime to compare with file mtime. review=seth mTouchedTime is not appropriate for this as it is updated when an image load re-uses the same imgRequest, especially as it has one second granularity. A timestamp that is updated every time the backing file is re-read should work better. A millisecond granularity timestamp would be preferable, and would be achievable on most or all supported platforms. But some older filesystems have timestamp granularity of a second or worse, notably ext3 and FAT32 (and even ext4 filesytems created with inode_size < 256 bytes, e.g. with 'mke2fs -t small' - see https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Inode_Timestamps for details.) --- image/imgLoader.cpp | 8 +++++++- image/imgLoader.h | 8 ++++++++ image/imgRequest.cpp | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index b350bea31e5d..1528ffd14ce7 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -862,6 +862,7 @@ imgCacheEntry::imgCacheEntry(imgLoader* loader, imgRequest* request, mRequest(request), mDataSize(0), mTouchedTime(SecondsFromPRTime(PR_Now())), + mLoadTime(SecondsFromPRTime(PR_Now())), mExpiryTime(0), mMustValidate(false), // We start off as evicted so we don't try to update the cache. PutIntoCache @@ -898,6 +899,11 @@ imgCacheEntry::UpdateCache(int32_t diff /* = 0 */) } } +void imgCacheEntry::UpdateLoadTime() +{ + mLoadTime = SecondsFromPRTime(PR_Now()); +} + void imgCacheEntry::SetHasNoProxies(bool hasNoProxies) { @@ -1710,7 +1716,7 @@ imgLoader::ValidateEntry(imgCacheEntry* aEntry, // Special treatment for file URLs - aEntry has expired if file has changed nsCOMPtr fileUrl(do_QueryInterface(aURI)); if (fileUrl) { - uint32_t lastModTime = aEntry->GetTouchedTime(); + uint32_t lastModTime = aEntry->GetLoadTime(); nsCOMPtr theFile; rv = fileUrl->GetFile(getter_AddRefs(theFile)); diff --git a/image/imgLoader.h b/image/imgLoader.h index be98fcb6364e..12db620929cf 100644 --- a/image/imgLoader.h +++ b/image/imgLoader.h @@ -91,6 +91,13 @@ public: Touch(/* updateTime = */ false); } + uint32_t GetLoadTime() const + { + return mLoadTime; + } + + void UpdateLoadTime(); + int32_t GetExpiryTime() const { return mExpiryTime; @@ -164,6 +171,7 @@ private: // data RefPtr mRequest; uint32_t mDataSize; int32_t mTouchedTime; + uint32_t mLoadTime; int32_t mExpiryTime; nsExpirationState mExpirationState; bool mMustValidate : 1; diff --git a/image/imgRequest.cpp b/image/imgRequest.cpp index 916d8d30f8bf..4afe6009075b 100644 --- a/image/imgRequest.cpp +++ b/image/imgRequest.cpp @@ -159,6 +159,7 @@ imgRequest::Init(nsIURI *aURI, mChannel->SetNotificationCallbacks(this); mCacheEntry = aCacheEntry; + mCacheEntry->UpdateLoadTime(); SetLoadId(aCX);