mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1112972 (Part 1) - Minor refactoring to prepare for MultipartImage. r=tn
This commit is contained in:
parent
af8da03583
commit
3072a3e4c7
@ -65,7 +65,7 @@ protected:
|
||||
explicit ImageWrapper(Image* aInnerImage)
|
||||
: mInnerImage(aInnerImage)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aInnerImage, "Cannot wrap a null image");
|
||||
MOZ_ASSERT(aInnerImage, "Need an image to wrap");
|
||||
}
|
||||
|
||||
virtual ~ImageWrapper() { }
|
||||
@ -73,7 +73,13 @@ protected:
|
||||
/**
|
||||
* Returns a weak reference to the inner image wrapped by this ImageWrapper.
|
||||
*/
|
||||
Image* InnerImage() { return mInnerImage.get(); }
|
||||
Image* InnerImage() const { return mInnerImage.get(); }
|
||||
|
||||
void SetInnerImage(Image* aInnerImage)
|
||||
{
|
||||
MOZ_ASSERT(aInnerImage, "Need an image to wrap");
|
||||
mInnerImage = aInnerImage;
|
||||
}
|
||||
|
||||
private:
|
||||
nsRefPtr<Image> mInnerImage;
|
||||
|
@ -29,10 +29,10 @@ ProgressTrackerInit::ProgressTrackerInit(Image* aImage,
|
||||
|
||||
if (aTracker) {
|
||||
mTracker = aTracker;
|
||||
mTracker->SetImage(aImage);
|
||||
} else {
|
||||
mTracker = new ProgressTracker(aImage);
|
||||
mTracker = new ProgressTracker();
|
||||
}
|
||||
mTracker->SetImage(aImage);
|
||||
aImage->SetProgressTracker(mTracker);
|
||||
MOZ_ASSERT(mTracker);
|
||||
}
|
||||
@ -425,8 +425,7 @@ ProgressTracker::SyncNotify(IProgressObserver* aObserver)
|
||||
}
|
||||
|
||||
void
|
||||
ProgressTracker::EmulateRequestFinished(IProgressObserver* aObserver,
|
||||
nsresult aStatus)
|
||||
ProgressTracker::EmulateRequestFinished(IProgressObserver* aObserver)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(),
|
||||
"SyncNotifyState and mObservers are not threadsafe");
|
||||
@ -448,9 +447,8 @@ ProgressTracker::AddObserver(IProgressObserver* aObserver)
|
||||
mObservers.AppendElementUnlessExists(aObserver);
|
||||
}
|
||||
|
||||
// XXX - The last argument should go away.
|
||||
bool
|
||||
ProgressTracker::RemoveObserver(IProgressObserver* aObserver, nsresult aStatus)
|
||||
ProgressTracker::RemoveObserver(IProgressObserver* aObserver)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -460,7 +458,7 @@ ProgressTracker::RemoveObserver(IProgressObserver* aObserver, nsresult aStatus)
|
||||
// Observers can get confused if they don't get all the proper teardown
|
||||
// notifications. Part ways on good terms.
|
||||
if (removed && !aObserver->NotificationsDeferred()) {
|
||||
EmulateRequestFinished(aObserver, aStatus);
|
||||
EmulateRequestFinished(aObserver);
|
||||
}
|
||||
|
||||
// Make sure we don't give callbacks to an observer that isn't interested in
|
||||
|
@ -77,11 +77,8 @@ public:
|
||||
MOZ_DECLARE_REFCOUNTED_TYPENAME(ProgressTracker)
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ProgressTracker)
|
||||
|
||||
// aImage is the image that will be passed to the observers in SyncNotify()
|
||||
// and EmulateRequestFinished(), and must be alive as long as this instance
|
||||
// is, because we hold a weak reference to it.
|
||||
explicit ProgressTracker(Image* aImage)
|
||||
: mImage(aImage)
|
||||
ProgressTracker()
|
||||
: mImage(nullptr)
|
||||
, mProgress(NoProgress)
|
||||
{ }
|
||||
|
||||
@ -159,7 +156,7 @@ public:
|
||||
// We manage a set of observers that are using an image and thus concerned
|
||||
// with its loading progress. Weak pointers.
|
||||
void AddObserver(IProgressObserver* aObserver);
|
||||
bool RemoveObserver(IProgressObserver* aObserver, nsresult aStatus);
|
||||
bool RemoveObserver(IProgressObserver* aObserver);
|
||||
size_t ObserverCount() const {
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Use mObservers on main thread only");
|
||||
return mObservers.Length();
|
||||
@ -195,7 +192,7 @@ private:
|
||||
// Send some notifications that would be necessary to make |aObserver| believe
|
||||
// the request is finished downloading and decoding. We only send
|
||||
// FLAG_LOAD_COMPLETE and FLAG_ONLOAD_UNBLOCKED, and only if necessary.
|
||||
void EmulateRequestFinished(IProgressObserver* aObserver, nsresult aStatus);
|
||||
void EmulateRequestFinished(IProgressObserver* aObserver);
|
||||
|
||||
// Main thread only because it deals with the observer service.
|
||||
void FireFailureNotification();
|
||||
|
@ -62,7 +62,7 @@ NS_IMPL_ISUPPORTS(imgRequest,
|
||||
|
||||
imgRequest::imgRequest(imgLoader* aLoader)
|
||||
: mLoader(aLoader)
|
||||
, mProgressTracker(new ProgressTracker(nullptr))
|
||||
, mProgressTracker(new ProgressTracker())
|
||||
, mValidator(nullptr)
|
||||
, mInnerWindowId(0)
|
||||
, mCORSMode(imgIRequest::CORS_NONE)
|
||||
@ -204,7 +204,7 @@ nsresult imgRequest::RemoveProxy(imgRequestProxy *proxy, nsresult aStatus)
|
||||
// before Cancel() returns, leaving the image in a different state then the
|
||||
// one it was in at this point.
|
||||
nsRefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
||||
if (!progressTracker->RemoveObserver(proxy, aStatus))
|
||||
if (!progressTracker->RemoveObserver(proxy))
|
||||
return NS_OK;
|
||||
|
||||
if (progressTracker->ObserverCount() == 0) {
|
||||
@ -897,7 +897,7 @@ imgRequest::OnDataAvailable(nsIRequest *aRequest, nsISupports *ctxt,
|
||||
MOZ_ASSERT(mIsMultiPartChannel, "Resniffing a non-multipart image");
|
||||
|
||||
// Initialize a new status tracker.
|
||||
nsRefPtr<ProgressTracker> freshTracker = new ProgressTracker(nullptr);
|
||||
nsRefPtr<ProgressTracker> freshTracker = new ProgressTracker();
|
||||
freshTracker->SetIsMultipart();
|
||||
|
||||
// Replace the old status tracker with it.
|
||||
|
Loading…
Reference in New Issue
Block a user