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.)
This commit is contained in:
Oliver Henshaw 2015-10-20 10:45:25 +05:30
parent e1aee30f50
commit b9c6244413
3 changed files with 16 additions and 1 deletions

View File

@ -862,6 +862,7 @@ imgCacheEntry::imgCacheEntry(imgLoader* loader, imgRequest* request,
mRequest(request), mRequest(request),
mDataSize(0), mDataSize(0),
mTouchedTime(SecondsFromPRTime(PR_Now())), mTouchedTime(SecondsFromPRTime(PR_Now())),
mLoadTime(SecondsFromPRTime(PR_Now())),
mExpiryTime(0), mExpiryTime(0),
mMustValidate(false), mMustValidate(false),
// We start off as evicted so we don't try to update the cache. PutIntoCache // 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 void
imgCacheEntry::SetHasNoProxies(bool hasNoProxies) imgCacheEntry::SetHasNoProxies(bool hasNoProxies)
{ {
@ -1710,7 +1716,7 @@ imgLoader::ValidateEntry(imgCacheEntry* aEntry,
// Special treatment for file URLs - aEntry has expired if file has changed // Special treatment for file URLs - aEntry has expired if file has changed
nsCOMPtr<nsIFileURL> fileUrl(do_QueryInterface(aURI)); nsCOMPtr<nsIFileURL> fileUrl(do_QueryInterface(aURI));
if (fileUrl) { if (fileUrl) {
uint32_t lastModTime = aEntry->GetTouchedTime(); uint32_t lastModTime = aEntry->GetLoadTime();
nsCOMPtr<nsIFile> theFile; nsCOMPtr<nsIFile> theFile;
rv = fileUrl->GetFile(getter_AddRefs(theFile)); rv = fileUrl->GetFile(getter_AddRefs(theFile));

View File

@ -91,6 +91,13 @@ public:
Touch(/* updateTime = */ false); Touch(/* updateTime = */ false);
} }
uint32_t GetLoadTime() const
{
return mLoadTime;
}
void UpdateLoadTime();
int32_t GetExpiryTime() const int32_t GetExpiryTime() const
{ {
return mExpiryTime; return mExpiryTime;
@ -164,6 +171,7 @@ private: // data
RefPtr<imgRequest> mRequest; RefPtr<imgRequest> mRequest;
uint32_t mDataSize; uint32_t mDataSize;
int32_t mTouchedTime; int32_t mTouchedTime;
uint32_t mLoadTime;
int32_t mExpiryTime; int32_t mExpiryTime;
nsExpirationState mExpirationState; nsExpirationState mExpirationState;
bool mMustValidate : 1; bool mMustValidate : 1;

View File

@ -159,6 +159,7 @@ imgRequest::Init(nsIURI *aURI,
mChannel->SetNotificationCallbacks(this); mChannel->SetNotificationCallbacks(this);
mCacheEntry = aCacheEntry; mCacheEntry = aCacheEntry;
mCacheEntry->UpdateLoadTime();
SetLoadId(aCX); SetLoadId(aCX);