зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1271701 - Make about:cache channels cancelable. r=michal
This commit is contained in:
Родитель
79a85728e0
Коммит
9c4215a1fb
|
@ -186,6 +186,7 @@ protected:
|
|||
, mSize(0)
|
||||
, mNotifyStorage(true)
|
||||
, mVisitEntries(aVisitEntries)
|
||||
, mCancel(false)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
}
|
||||
|
@ -204,6 +205,8 @@ protected:
|
|||
|
||||
bool mNotifyStorage : 1;
|
||||
bool mVisitEntries : 1;
|
||||
|
||||
Atomic<bool> mCancel;
|
||||
};
|
||||
|
||||
// WalkMemoryCacheRunnable
|
||||
|
@ -274,10 +277,10 @@ private:
|
|||
mNotifyStorage = false;
|
||||
|
||||
} else {
|
||||
LOG((" entry [left=%d]", mEntryArray.Length()));
|
||||
LOG((" entry [left=%d, canceled=%d]", mEntryArray.Length(), (bool)mCancel));
|
||||
|
||||
// Third, notify each entry until depleted
|
||||
if (!mEntryArray.Length()) {
|
||||
// Third, notify each entry until depleted or canceled
|
||||
if (!mEntryArray.Length() || mCancel) {
|
||||
mCallback->OnCacheEntryVisitCompleted();
|
||||
return NS_OK; // done
|
||||
}
|
||||
|
@ -310,13 +313,20 @@ private:
|
|||
uint32_t aLastModifiedTime, uint32_t aExpirationTime,
|
||||
bool aPinned)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURISpec);
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
nsresult rv;
|
||||
|
||||
mCallback->OnCacheEntryInfo(uri, aIdEnhance, aDataSize, aFetchCount,
|
||||
aLastModifiedTime, aExpirationTime, aPinned);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), aURISpec);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
rv = mCallback->OnCacheEntryInfo(uri, aIdEnhance, aDataSize, aFetchCount,
|
||||
aLastModifiedTime, aExpirationTime, aPinned);
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG((" callback failed, canceling the walk"));
|
||||
mCancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -369,14 +379,21 @@ private:
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), mURISpec);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_OK;
|
||||
nsresult rv;
|
||||
|
||||
mWalker->mCallback->OnCacheEntryInfo(
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), mURISpec);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = mWalker->mCallback->OnCacheEntryInfo(
|
||||
uri, mIdEnhance, mDataSize, mFetchCount,
|
||||
mLastModifiedTime, mExpirationTime, mPinned);
|
||||
if (NS_FAILED(rv)) {
|
||||
mWalker->mCancel = true;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -432,7 +449,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
while (!mCancel) {
|
||||
if (CacheIOThread::YieldAndRerun())
|
||||
return NS_OK;
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ nsAboutCache::Channel::Init(nsIURI* aURI, nsILoadInfo* aLoadInfo)
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
mCancel = false;
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
rv = NS_NewPipe(getter_AddRefs(inputStream), getter_AddRefs(mStream),
|
||||
16384, (uint32_t)-1,
|
||||
|
@ -359,7 +361,8 @@ nsAboutCache::Channel::OnCacheEntryInfo(nsIURI *aURI, const nsACString & aIdEnha
|
|||
bool aPinned)
|
||||
{
|
||||
// We need mStream for this
|
||||
if (!mStream) {
|
||||
if (!mStream || mCancel) {
|
||||
// Returning a failure from this callback stops the iteration
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -470,8 +473,7 @@ nsAboutCache::Channel::OnCacheEntryInfo(nsIURI *aURI, const nsACString & aIdEnha
|
|||
// Entry is done...
|
||||
mBuffer.AppendLiteral(" </tr>\n");
|
||||
|
||||
FlushBuffer();
|
||||
return NS_OK;
|
||||
return FlushBuffer();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -503,12 +505,20 @@ nsAboutCache::Channel::OnCacheEntryVisitCompleted()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsresult
|
||||
nsAboutCache::Channel::FlushBuffer()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
uint32_t bytesWritten;
|
||||
mStream->Write(mBuffer.get(), mBuffer.Length(), &bytesWritten);
|
||||
rv = mStream->Write(mBuffer.get(), mBuffer.Length(), &bytesWritten);
|
||||
mBuffer.Truncate();
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
mCancel = true;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -64,8 +64,10 @@ protected:
|
|||
nsresult VisitStorage(nsACString const & storageName);
|
||||
|
||||
// Writes content of mBuffer to mStream and truncates
|
||||
// the buffer.
|
||||
void FlushBuffer();
|
||||
// the buffer. It may fail when the input stream is closed by canceling
|
||||
// the input stream channel. It can be used to stop the cache iteration
|
||||
// process.
|
||||
nsresult FlushBuffer();
|
||||
|
||||
// Whether we are showing overview status of all available
|
||||
// storages.
|
||||
|
@ -75,6 +77,9 @@ protected:
|
|||
// been added to the output HTML.
|
||||
bool mEntriesHeaderAdded;
|
||||
|
||||
// Cancelation flag
|
||||
bool mCancel;
|
||||
|
||||
// The context we are working with.
|
||||
nsCOMPtr<nsILoadContextInfo> mLoadInfo;
|
||||
nsCString mContextString;
|
||||
|
|
Загрузка…
Ссылка в новой задаче