Bug 1299498 - Keep a main thread only pointer to the underlying nsIURI for ImageURL. r=tnikkel

This commit is contained in:
Andrew Osmond 2016-11-28 08:40:42 -05:00
parent 118ed51896
commit 1f7abbe2a9

View File

@ -11,6 +11,7 @@
#include "nsNetUtil.h"
#include "mozilla/HashFunctions.h"
#include "nsHashKeys.h"
#include "nsProxyRelease.h"
namespace mozilla {
namespace image {
@ -33,6 +34,7 @@ class ImageURL
{
public:
explicit ImageURL(nsIURI* aURI, nsresult& aRv)
: mURI(new nsMainThreadPtrHolder<nsIURI>(aURI))
{
MOZ_ASSERT(NS_IsMainThread(), "Cannot use nsIURI off main thread!");
@ -97,10 +99,7 @@ public:
already_AddRefed<nsIURI> ToIURI()
{
MOZ_ASSERT(NS_IsMainThread(),
"Convert to nsIURI on main thread only; it is not threadsafe.");
nsCOMPtr<nsIURI> newURI;
NS_NewURI(getter_AddRefs(newURI), mSpec);
nsCOMPtr<nsIURI> newURI = mURI.get();
return newURI.forget();
}
@ -133,6 +132,8 @@ private:
return HashString(mSpec);
}
nsMainThreadPtrHandle<nsIURI> mURI;
// Since this is a basic storage class, no duplication of spec parsing is
// included in the functionality. Instead, the class depends upon the
// parsing implementation in the nsIURI class used in object construction.