Bug 1325088 - Part 2: Expose the index-update to cache entry. r=michal

--HG--
extra : rebase_source : 8c8eaf6cea7eb3491de4cdf9dbe9783491296130
This commit is contained in:
Junior Hsu 2017-03-28 12:02:45 +08:00
parent 6dc5f1d10e
commit 6d4fca1d99
6 changed files with 124 additions and 23 deletions

View File

@ -1075,6 +1075,26 @@ NS_IMETHODIMP CacheEntry::GetExpirationTime(uint32_t *aExpirationTime)
return mFile->GetExpirationTime(aExpirationTime);
}
nsresult CacheEntry::GetOnStartTime(uint64_t *aTime)
{
NS_ENSURE_SUCCESS(mFileStatus, NS_ERROR_NOT_AVAILABLE);
return mFile->GetOnStartTime(aTime);
}
nsresult CacheEntry::GetOnStopTime(uint64_t *aTime)
{
NS_ENSURE_SUCCESS(mFileStatus, NS_ERROR_NOT_AVAILABLE);
return mFile->GetOnStopTime(aTime);
}
nsresult CacheEntry::SetNetworkTimes(uint64_t aOnStartTime, uint64_t aOnStopTime)
{
if (NS_SUCCEEDED(mFileStatus)) {
return mFile->SetNetworkTimes(aOnStartTime, aOnStopTime);
}
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP CacheEntry::GetIsForcedValid(bool *aIsForcedValid)
{
NS_ENSURE_ARG(aIsForcedValid);

View File

@ -1198,9 +1198,78 @@ CacheFile::GetFrecency(uint32_t *_retval)
return mMetadata->GetFrecency(_retval);
}
nsresult CacheFile::SetNetworkTimes(uint64_t aOnStartTime, uint64_t aOnStopTime)
{
CacheFileAutoLock lock(this);
LOG(("CacheFile::SetNetworkTimes() this=%p, aOnStartTime=%" PRIu64
", aOnStopTime=%" PRIu64 "", this, aOnStartTime, aOnStopTime));
MOZ_ASSERT(mMetadata);
NS_ENSURE_TRUE(mMetadata, NS_ERROR_UNEXPECTED);
MOZ_ASSERT(aOnStartTime != kIndexTimeNotAvailable);
MOZ_ASSERT(aOnStopTime != kIndexTimeNotAvailable);
PostWriteTimer();
nsAutoCString onStartTime;
onStartTime.AppendInt(aOnStartTime);
nsresult rv = mMetadata->SetElement("net-response-time-onstart", onStartTime.get());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsAutoCString onStopTime;
onStopTime.AppendInt(aOnStopTime);
rv = mMetadata->SetElement("net-response-time-onstop", onStopTime.get());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
uint16_t onStartTime16 = aOnStartTime <= kIndexTimeOutOfBound ? aOnStartTime : kIndexTimeOutOfBound;
uint16_t onStopTime16 = aOnStopTime <= kIndexTimeOutOfBound ? aOnStopTime : kIndexTimeOutOfBound;
if (mHandle && !mHandle->IsDoomed()) {
CacheFileIOManager::UpdateIndexEntry(mHandle, nullptr, nullptr, nullptr,
&onStartTime16, &onStopTime16);
}
return NS_OK;
}
nsresult CacheFile::GetOnStartTime(uint64_t *_retval)
{
CacheFileAutoLock lock(this);
MOZ_ASSERT(mMetadata);
const char *onStartTimeStr = mMetadata->GetElement("net-response-time-onstart");
if (!onStartTimeStr) {
return NS_ERROR_NOT_AVAILABLE;
}
nsresult rv;
*_retval = nsCString(onStartTimeStr).ToInteger64(&rv);
MOZ_ASSERT(NS_SUCCEEDED(rv));
return NS_OK;
}
nsresult CacheFile::GetOnStopTime(uint64_t *_retval)
{
CacheFileAutoLock lock(this);
MOZ_ASSERT(mMetadata);
const char *onStopTimeStr = mMetadata->GetElement("net-response-time-onstop");
if (!onStopTimeStr) {
return NS_ERROR_NOT_AVAILABLE;
}
nsresult rv;
*_retval = nsCString(onStopTimeStr).ToInteger64(&rv);
MOZ_ASSERT(NS_SUCCEEDED(rv));
return NS_OK;
}
nsresult
CacheFile::SetAltMetadata(const char* aAltMetadata)
{
AssertOwnsLock();
LOG(("CacheFile::SetAltMetadata() this=%p, aAltMetadata=%s",
this, aAltMetadata ? aAltMetadata : ""));

View File

@ -102,6 +102,9 @@ public:
nsresult GetExpirationTime(uint32_t *_retval);
nsresult SetFrecency(uint32_t aFrecency);
nsresult GetFrecency(uint32_t *_retval);
nsresult SetNetworkTimes(uint64_t aOnStartTime, uint64_t aOnStopTime);
nsresult GetOnStartTime(uint64_t *_retval);
nsresult GetOnStopTime(uint64_t *_retval);
nsresult GetLastModified(uint32_t *_retval);
nsresult GetLastFetched(uint32_t *_retval);
nsresult GetFetchCount(uint32_t *_retval);

View File

@ -135,6 +135,18 @@ public:
{
return mOldInfo->GetDataSize(aDataSize);
}
NS_IMETHOD GetOnStartTime(uint64_t *aTime) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD GetOnStopTime(uint64_t *aTime) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD SetNetworkTimes(uint64_t aOnStartTime, uint64_t aOnStopTime) override
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD GetLoadContextInfo(nsILoadContextInfo** aInfo) override
{
return NS_ERROR_NOT_IMPLEMENTED;

View File

@ -60,6 +60,19 @@ interface nsICacheEntry : nsISupports
*/
void setExpirationTime(in uint32_t expirationTime);
/**
* Get the last network response times for onStartReqeust/onStopRequest (in ms).
* @throws
* - NS_ERROR_NOT_AVAILABLE if onStartTime/onStopTime does not exist.
*/
readonly attribute uint64_t onStartTime;
readonly attribute uint64_t onStopTime;
/**
* Set the network response times for onStartReqeust/onStopRequest (in ms).
*/
void setNetworkTimes(in uint64_t onStartTime, in uint64_t onStopTime);
/**
* This method is intended to override the per-spec cache validation
* decisions for a duration specified in seconds. The current state can

View File

@ -6915,13 +6915,9 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st
if (request == mTransactionPump && mCacheEntry && !mDidReval &&
!mCustomConditionalRequest &&
!mAsyncOpenTime.IsNull() && !mOnStartRequestTimestamp.IsNull()) {
nsAutoCString onStartTime;
onStartTime.AppendInt( (uint64_t) (mOnStartRequestTimestamp - mAsyncOpenTime).ToMilliseconds());
mCacheEntry->SetMetaDataElement("net-response-time-onstart", onStartTime.get());
nsAutoCString responseTime;
responseTime.AppendInt( (uint64_t) (TimeStamp::Now() - mAsyncOpenTime).ToMilliseconds());
mCacheEntry->SetMetaDataElement("net-response-time-onstop", responseTime.get());
uint64_t onStartTime = (mOnStartRequestTimestamp - mAsyncOpenTime).ToMilliseconds();
uint64_t onStopTime = (TimeStamp::Now() - mAsyncOpenTime).ToMilliseconds();
Unused << mCacheEntry->SetNetworkTimes(onStartTime, onStopTime);
}
// at this point, we're done with the transaction
@ -8609,25 +8605,13 @@ nsHttpChannel::ReportNetVSCacheTelemetry()
return;
}
nsXPIDLCString tmpStr;
rv = mCacheEntry->GetMetaDataElement("net-response-time-onstart",
getter_Copies(tmpStr));
if (NS_FAILED(rv)) {
return;
}
uint64_t onStartNetTime = tmpStr.ToInteger64(&rv);
if (NS_FAILED(rv)) {
uint64_t onStartNetTime = 0;
if (NS_FAILED(mCacheEntry->GetOnStartTime(&onStartNetTime))) {
return;
}
tmpStr.Truncate();
rv = mCacheEntry->GetMetaDataElement("net-response-time-onstop",
getter_Copies(tmpStr));
if (NS_FAILED(rv)) {
return;
}
uint64_t onStopNetTime = tmpStr.ToInteger64(&rv);
if (NS_FAILED(rv)) {
uint64_t onStopNetTime = 0;
if (NS_FAILED(mCacheEntry->GetOnStopTime(&onStopNetTime))) {
return;
}