Bug 1271019 - Don't call on nsIURI on non-main threads from HTTP cache back end. r=michal

This commit is contained in:
Honza Bambas 2016-05-12 06:38:00 -04:00
Родитель cbc57001d9
Коммит d9981dcb53
5 изменённых файлов: 48 добавлений и 49 удалений

Просмотреть файл

@ -195,7 +195,7 @@ NS_IMPL_ISUPPORTS(CacheEntry,
CacheFileListener)
CacheEntry::CacheEntry(const nsACString& aStorageID,
nsIURI* aURI,
const nsACString& aURI,
const nsACString& aEnhanceID,
bool aUseDisk,
bool aSkipSizeCheck,
@ -220,9 +220,8 @@ CacheEntry::CacheEntry(const nsACString& aStorageID,
, mWriter(nullptr)
, mPredictedDataSize(0)
, mUseCount(0)
, mReleaseThread(NS_GetCurrentThread())
{
MOZ_COUNT_CTOR(CacheEntry);
LOG(("CacheEntry::CacheEntry [this=%p]", this));
mService = CacheStorageService::Self();
@ -232,10 +231,7 @@ CacheEntry::CacheEntry(const nsACString& aStorageID,
CacheEntry::~CacheEntry()
{
ProxyRelease(mURI, mReleaseThread);
LOG(("CacheEntry::~CacheEntry [this=%p]", this));
MOZ_COUNT_DTOR(CacheEntry);
}
char const * CacheEntry::StateString(uint32_t aState)
@ -1034,7 +1030,8 @@ NS_IMETHODIMP CacheEntry::GetPersistent(bool *aPersistToDisk)
NS_IMETHODIMP CacheEntry::GetKey(nsACString & aKey)
{
return mURI->GetAsciiSpec(aKey);
aKey.Assign(mURI);
return NS_OK;
}
NS_IMETHODIMP CacheEntry::GetFetchCount(int32_t *aFetchCount)
@ -1809,11 +1806,7 @@ size_t CacheEntry::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
n += mFile->SizeOfIncludingThis(mallocSizeOf);
}
sizeOf = do_QueryInterface(mURI);
if (sizeOf) {
n += sizeOf->SizeOfIncludingThis(mallocSizeOf);
}
n += mURI.SizeOfExcludingThisIfUnshared(mallocSizeOf);
n += mEnhanceID.SizeOfExcludingThisIfUnshared(mallocSizeOf);
n += mStorageID.SizeOfExcludingThisIfUnshared(mallocSizeOf);

Просмотреть файл

@ -54,7 +54,7 @@ public:
NS_DECL_NSICACHEENTRY
NS_DECL_NSIRUNNABLE
CacheEntry(const nsACString& aStorageID, nsIURI* aURI, const nsACString& aEnhanceID,
CacheEntry(const nsACString& aStorageID, const nsACString& aURI, const nsACString& aEnhanceID,
bool aUseDisk, bool aSkipSizeCheck, bool aPin);
void AsyncOpen(nsICacheEntryOpenCallback* aCallback, uint32_t aFlags);
@ -68,7 +68,7 @@ public:
uint32_t GetMetadataMemoryConsumption();
nsCString const &GetStorageID() const { return mStorageID; }
nsCString const &GetEnhanceID() const { return mEnhanceID; }
nsIURI* GetURI() const { return mURI; }
nsCString const &GetURI() const { return mURI; }
// Accessible at any time
bool IsUsingDisk() const { return mUseDisk; }
bool IsReferenced() const;
@ -288,7 +288,7 @@ private:
// When mFileStatus is read and found success it is ensured there is mFile and
// that it is after a successful call to Init().
::mozilla::Atomic<nsresult, ::mozilla::ReleaseAcquire> mFileStatus;
nsCOMPtr<nsIURI> mURI;
nsCString mURI;
nsCString mEnhanceID;
nsCString mStorageID;
@ -375,7 +375,6 @@ private:
int64_t mPredictedDataSize;
mozilla::TimeStamp mLoadStart;
uint32_t mUseCount;
nsCOMPtr<nsIThread> mReleaseThread;
};

Просмотреть файл

@ -71,6 +71,10 @@ NS_IMETHODIMP CacheStorage::AsyncOpenURI(nsIURI *aURI,
rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString asciiSpec;
rv = noRefURI->GetAsciiSpec(asciiSpec);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIApplicationCache> appCache;
if (LookupAppCache()) {
rv = ChooseApplicationCache(noRefURI, getter_AddRefs(appCache));
@ -83,16 +87,12 @@ NS_IMETHODIMP CacheStorage::AsyncOpenURI(nsIURI *aURI,
}
if (appCache) {
nsAutoCString cacheKey;
rv = noRefURI->GetAsciiSpec(cacheKey);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString scheme;
rv = noRefURI->GetScheme(scheme);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<_OldCacheLoad> appCacheLoad =
new _OldCacheLoad(scheme, cacheKey, aCallback, appCache,
new _OldCacheLoad(scheme, asciiSpec, aCallback, appCache,
LoadInfo(), WriteToDisk(), aFlags);
rv = appCacheLoad->Start();
NS_ENSURE_SUCCESS(rv, rv);
@ -103,7 +103,7 @@ NS_IMETHODIMP CacheStorage::AsyncOpenURI(nsIURI *aURI,
RefPtr<CacheEntryHandle> entry;
rv = CacheStorageService::Self()->AddStorageEntry(
this, noRefURI, aIdExtension,
this, asciiSpec, aIdExtension,
truncate, // replace any existing one?
getter_AddRefs(entry));
NS_ENSURE_SUCCESS(rv, rv);
@ -127,9 +127,13 @@ NS_IMETHODIMP CacheStorage::OpenTruncate(nsIURI *aURI, const nsACString & aIdExt
rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString asciiSpec;
rv = noRefURI->GetAsciiSpec(asciiSpec);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<CacheEntryHandle> handle;
rv = CacheStorageService::Self()->AddStorageEntry(
this, noRefURI, aIdExtension,
this, asciiSpec, aIdExtension,
true, // replace any existing one
getter_AddRefs(handle));
NS_ENSURE_SUCCESS(rv, rv);
@ -159,8 +163,12 @@ NS_IMETHODIMP CacheStorage::Exists(nsIURI *aURI, const nsACString & aIdExtension
rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString asciiSpec;
rv = noRefURI->GetAsciiSpec(asciiSpec);
NS_ENSURE_SUCCESS(rv, rv);
return CacheStorageService::Self()->CheckStorageEntry(
this, noRefURI, aIdExtension, aResult);
this, asciiSpec, aIdExtension, aResult);
}
NS_IMETHODIMP CacheStorage::AsyncDoomURI(nsIURI *aURI, const nsACString & aIdExtension,
@ -169,8 +177,18 @@ NS_IMETHODIMP CacheStorage::AsyncDoomURI(nsIURI *aURI, const nsACString & aIdExt
if (!CacheStorageService::Self())
return NS_ERROR_NOT_INITIALIZED;
nsresult rv = CacheStorageService::Self()->DoomStorageEntry(
this, aURI, aIdExtension, aCallback);
nsresult rv;
nsCOMPtr<nsIURI> noRefURI;
rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString asciiSpec;
rv = noRefURI->GetAsciiSpec(asciiSpec);
NS_ENSURE_SUCCESS(rv, rv);
rv = CacheStorageService::Self()->DoomStorageEntry(
this, asciiSpec, aIdExtension, aCallback);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;

Просмотреть файл

@ -1403,7 +1403,7 @@ CacheStorageService::MemoryPool::PurgeAll(uint32_t aWhat)
nsresult
CacheStorageService::AddStorageEntry(CacheStorage const* aStorage,
nsIURI* aURI,
const nsACString & aURI,
const nsACString & aIdExtension,
bool aReplace,
CacheEntryHandle** aResult)
@ -1425,7 +1425,7 @@ CacheStorageService::AddStorageEntry(CacheStorage const* aStorage,
nsresult
CacheStorageService::AddStorageEntry(nsCSubstring const& aContextKey,
nsIURI* aURI,
const nsACString & aURI,
const nsACString & aIdExtension,
bool aWriteToDisk,
bool aSkipSizeCheck,
@ -1433,8 +1433,6 @@ CacheStorageService::AddStorageEntry(nsCSubstring const& aContextKey,
bool aReplace,
CacheEntryHandle** aResult)
{
NS_ENSURE_ARG(aURI);
nsresult rv;
nsAutoCString entryKey;
@ -1515,7 +1513,7 @@ CacheStorageService::AddStorageEntry(nsCSubstring const& aContextKey,
nsresult
CacheStorageService::CheckStorageEntry(CacheStorage const* aStorage,
nsIURI* aURI,
const nsACString & aURI,
const nsACString & aIdExtension,
bool* aResult)
{
@ -1528,12 +1526,8 @@ CacheStorageService::CheckStorageEntry(CacheStorage const* aStorage,
AppendMemoryStorageID(contextKey);
}
if (LOG_ENABLED()) {
nsAutoCString uriSpec;
aURI->GetAsciiSpec(uriSpec);
LOG(("CacheStorageService::CheckStorageEntry [uri=%s, eid=%s, contextKey=%s]",
uriSpec.get(), aIdExtension.BeginReading(), contextKey.get()));
}
LOG(("CacheStorageService::CheckStorageEntry [uri=%s, eid=%s, contextKey=%s]",
aURI.BeginReading(), aIdExtension.BeginReading(), contextKey.get()));
{
mozilla::MutexAutoLock lock(mLock);
@ -1634,14 +1628,13 @@ NS_IMPL_ISUPPORTS(CacheEntryDoomByKeyCallback, CacheFileIOListener, nsIRunnable)
nsresult
CacheStorageService::DoomStorageEntry(CacheStorage const* aStorage,
nsIURI *aURI,
const nsACString & aURI,
const nsACString & aIdExtension,
nsICacheEntryDoomCallback* aCallback)
{
LOG(("CacheStorageService::DoomStorageEntry"));
NS_ENSURE_ARG(aStorage);
NS_ENSURE_ARG(aURI);
nsAutoCString contextKey;
CacheFileUtils::AppendKeyPrefix(aStorage->LoadInfo(), contextKey);
@ -1945,13 +1938,9 @@ void
CacheStorageService::GetCacheEntryInfo(CacheEntry* aEntry,
EntryInfoCallback *aCallback)
{
nsIURI* uri = aEntry->GetURI();
nsAutoCString uriSpec;
if (uri) {
uri->GetAsciiSpec(uriSpec);
}
nsCString const uriSpec = aEntry->GetURI();
nsCString const enhanceId = aEntry->GetEnhanceID();
uint32_t dataSize;
if (NS_FAILED(aEntry->GetStorageDataSize(&dataSize))) {
dataSize = 0;

Просмотреть файл

@ -200,7 +200,7 @@ private:
* and uri+id extension.
*/
nsresult AddStorageEntry(CacheStorage const* aStorage,
nsIURI* aURI,
const nsACString & aURI,
const nsACString & aIdExtension,
bool aReplace,
CacheEntryHandle** aResult);
@ -210,7 +210,7 @@ private:
* when the information cannot be obtained synchronously w/o blocking.
*/
nsresult CheckStorageEntry(CacheStorage const* aStorage,
nsIURI* aURI,
const nsACString & aURI,
const nsACString & aIdExtension,
bool* aResult);
@ -219,7 +219,7 @@ private:
* and returns it.
*/
nsresult DoomStorageEntry(CacheStorage const* aStorage,
nsIURI* aURI,
const nsACString & aURI,
const nsACString & aIdExtension,
nsICacheEntryDoomCallback* aCallback);
@ -292,7 +292,7 @@ private:
bool aPin,
nsICacheEntryDoomCallback* aCallback);
nsresult AddStorageEntry(nsCSubstring const& aContextKey,
nsIURI* aURI,
const nsACString & aURI,
const nsACString & aIdExtension,
bool aWriteToDisk,
bool aSkipSizeCheck,