Skip to content

Commit

Permalink
Bug 1383682 - Part 2. Rename IProgressObserver::SetNotificationsDefer…
Browse files Browse the repository at this point in the history
…red to make purpose clear. r=tnikkel

IProgressObserver::SetNotificationsDeferred is now used just for
ProgressTracker to track when there is a pending notification for
an observer. It has been renamed to MarkPendingNotify and
ClearPendingNotify to make a clear distinction.
  • Loading branch information
aosmond committed Feb 7, 2018
1 parent b3dda3a commit 5dd197b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
3 changes: 2 additions & 1 deletion image/IProgressObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class IProgressObserver : public SupportsWeakPtr<IProgressObserver>
// Other, internal-only methods:
virtual void SetHasImage() = 0;
virtual bool NotificationsDeferred() const = 0;
virtual void SetNotificationsDeferred(bool aDeferNotifications) = 0;
virtual void MarkPendingNotify() = 0;
virtual void ClearPendingNotify() = 0;

virtual already_AddRefed<nsIEventTarget> GetEventTarget() const
{
Expand Down
17 changes: 12 additions & 5 deletions image/MultipartImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class NextPartObserver : public IProgressObserver
// Other notifications are ignored.
virtual void SetHasImage() override { }
virtual bool NotificationsDeferred() const override { return false; }
virtual void SetNotificationsDeferred(bool) override { }
virtual void MarkPendingNotify() override { }
virtual void ClearPendingNotify() override { }

private:
virtual ~NextPartObserver() { }
Expand All @@ -122,7 +123,7 @@ class NextPartObserver : public IProgressObserver

MultipartImage::MultipartImage(Image* aFirstPart)
: ImageWrapper(aFirstPart)
, mDeferNotifications(false)
, mPendingNotify(false)
{
mNextPartObserver = new NextPartObserver(this);
}
Expand Down Expand Up @@ -333,13 +334,19 @@ MultipartImage::SetHasImage()
bool
MultipartImage::NotificationsDeferred() const
{
return mDeferNotifications;
return mPendingNotify;
}

void
MultipartImage::SetNotificationsDeferred(bool aDeferNotifications)
MultipartImage::MarkPendingNotify()
{
mDeferNotifications = aDeferNotifications;
mPendingNotify = true;
}

void
MultipartImage::ClearPendingNotify()
{
mPendingNotify = false;
}

} // namespace image
Expand Down
5 changes: 3 additions & 2 deletions image/MultipartImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class MultipartImage
virtual void OnLoadComplete(bool aLastPart) override;
virtual void SetHasImage() override;
virtual bool NotificationsDeferred() const override;
virtual void SetNotificationsDeferred(bool aDeferNotifications) override;
virtual void MarkPendingNotify() override;
virtual void ClearPendingNotify() override;

protected:
virtual ~MultipartImage();
Expand All @@ -76,7 +77,7 @@ class MultipartImage
RefPtr<ProgressTracker> mTracker;
RefPtr<NextPartObserver> mNextPartObserver;
RefPtr<Image> mNextPart;
bool mDeferNotifications : 1;
bool mPendingNotify : 1;
};

} // namespace image
Expand Down
10 changes: 5 additions & 5 deletions image/ProgressTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class AsyncNotifyRunnable : public Runnable
MOZ_ASSERT(NS_IsMainThread(), "Should be running on the main thread");
MOZ_ASSERT(mTracker, "mTracker should not be null");
for (uint32_t i = 0; i < mObservers.Length(); ++i) {
mObservers[i]->SetNotificationsDeferred(false);
mObservers[i]->ClearPendingNotify();
mTracker->SyncNotify(mObservers[i]);
}

Expand Down Expand Up @@ -190,7 +190,7 @@ ProgressTracker::Notify(IProgressObserver* aObserver)
}
}

aObserver->SetNotificationsDeferred(true);
aObserver->MarkPendingNotify();

// If we have an existing runnable that we can use, we just append this
// observer to its list of observers to be notified. This ensures we don't
Expand Down Expand Up @@ -226,7 +226,7 @@ class AsyncNotifyCurrentStateRunnable : public Runnable
NS_IMETHOD Run() override
{
MOZ_ASSERT(NS_IsMainThread(), "Should be running on the main thread");
mObserver->SetNotificationsDeferred(false);
mObserver->ClearPendingNotify();

mProgressTracker->SyncNotify(mObserver);
return NS_OK;
Expand Down Expand Up @@ -261,7 +261,7 @@ ProgressTracker::NotifyCurrentState(IProgressObserver* aObserver)
"ProgressTracker::NotifyCurrentState", "uri", spec.get());
}

aObserver->SetNotificationsDeferred(true);
aObserver->MarkPendingNotify();

nsCOMPtr<nsIRunnable> ev = new AsyncNotifyCurrentStateRunnable(this,
aObserver);
Expand Down Expand Up @@ -526,7 +526,7 @@ ProgressTracker::RemoveObserver(IProgressObserver* aObserver)

if (aObserver->NotificationsDeferred() && runnable) {
runnable->RemoveObserver(aObserver);
aObserver->SetNotificationsDeferred(false);
aObserver->ClearPendingNotify();
}

return removed;
Expand Down
2 changes: 1 addition & 1 deletion image/imgRequestProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ imgRequestProxy::imgRequestProxy() :
mForceDispatchLoadGroup(false),
mListenerIsStrongRef(false),
mDecodeRequested(false),
mDeferNotifications(false),
mPendingNotify(false),
mValidating(false),
mHadListener(false),
mHadDispatch(false)
Expand Down
12 changes: 8 additions & 4 deletions image/imgRequestProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ class imgRequestProxy : public imgIRequest,
// an event it has scheduled has been fired and/or validation is complete.
virtual bool NotificationsDeferred() const override
{
return IsValidating() || mDeferNotifications;
return IsValidating() || mPendingNotify;
}
virtual void SetNotificationsDeferred(bool aDeferNotifications) override
virtual void MarkPendingNotify() override
{
mDeferNotifications = aDeferNotifications;
mPendingNotify = true;
}
virtual void ClearPendingNotify() override
{
mPendingNotify = false;
}
bool IsValidating() const
{
Expand Down Expand Up @@ -250,7 +254,7 @@ class imgRequestProxy : public imgIRequest,

// Whether we want to defer our notifications by the non-virtual Observer
// interfaces as image loads proceed.
bool mDeferNotifications : 1;
bool mPendingNotify : 1;
bool mValidating : 1;
bool mHadListener : 1;
bool mHadDispatch : 1;
Expand Down

0 comments on commit 5dd197b

Please sign in to comment.