Bug 1383682 - Part 2. Rename IProgressObserver::SetNotificationsDeferred 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.
This commit is contained in:
Andrew Osmond 2018-02-07 07:27:27 -05:00
parent dab9b6216c
commit b1c05068b8
6 changed files with 31 additions and 18 deletions

View File

@ -43,7 +43,8 @@ public:
// Other, internal-only methods: // Other, internal-only methods:
virtual void SetHasImage() = 0; virtual void SetHasImage() = 0;
virtual bool NotificationsDeferred() const = 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 virtual already_AddRefed<nsIEventTarget> GetEventTarget() const
{ {

View File

@ -95,7 +95,8 @@ public:
// Other notifications are ignored. // Other notifications are ignored.
virtual void SetHasImage() override { } virtual void SetHasImage() override { }
virtual bool NotificationsDeferred() const override { return false; } virtual bool NotificationsDeferred() const override { return false; }
virtual void SetNotificationsDeferred(bool) override { } virtual void MarkPendingNotify() override { }
virtual void ClearPendingNotify() override { }
private: private:
virtual ~NextPartObserver() { } virtual ~NextPartObserver() { }
@ -122,7 +123,7 @@ private:
MultipartImage::MultipartImage(Image* aFirstPart) MultipartImage::MultipartImage(Image* aFirstPart)
: ImageWrapper(aFirstPart) : ImageWrapper(aFirstPart)
, mDeferNotifications(false) , mPendingNotify(false)
{ {
mNextPartObserver = new NextPartObserver(this); mNextPartObserver = new NextPartObserver(this);
} }
@ -333,13 +334,19 @@ MultipartImage::SetHasImage()
bool bool
MultipartImage::NotificationsDeferred() const MultipartImage::NotificationsDeferred() const
{ {
return mDeferNotifications; return mPendingNotify;
} }
void void
MultipartImage::SetNotificationsDeferred(bool aDeferNotifications) MultipartImage::MarkPendingNotify()
{ {
mDeferNotifications = aDeferNotifications; mPendingNotify = true;
}
void
MultipartImage::ClearPendingNotify()
{
mPendingNotify = false;
} }
} // namespace image } // namespace image

View File

@ -59,7 +59,8 @@ public:
virtual void OnLoadComplete(bool aLastPart) override; virtual void OnLoadComplete(bool aLastPart) override;
virtual void SetHasImage() override; virtual void SetHasImage() override;
virtual bool NotificationsDeferred() const override; virtual bool NotificationsDeferred() const override;
virtual void SetNotificationsDeferred(bool aDeferNotifications) override; virtual void MarkPendingNotify() override;
virtual void ClearPendingNotify() override;
protected: protected:
virtual ~MultipartImage(); virtual ~MultipartImage();
@ -76,7 +77,7 @@ private:
RefPtr<ProgressTracker> mTracker; RefPtr<ProgressTracker> mTracker;
RefPtr<NextPartObserver> mNextPartObserver; RefPtr<NextPartObserver> mNextPartObserver;
RefPtr<Image> mNextPart; RefPtr<Image> mNextPart;
bool mDeferNotifications : 1; bool mPendingNotify : 1;
}; };
} // namespace image } // namespace image

View File

@ -141,7 +141,7 @@ class AsyncNotifyRunnable : public Runnable
MOZ_ASSERT(NS_IsMainThread(), "Should be running on the main thread"); MOZ_ASSERT(NS_IsMainThread(), "Should be running on the main thread");
MOZ_ASSERT(mTracker, "mTracker should not be null"); MOZ_ASSERT(mTracker, "mTracker should not be null");
for (uint32_t i = 0; i < mObservers.Length(); ++i) { for (uint32_t i = 0; i < mObservers.Length(); ++i) {
mObservers[i]->SetNotificationsDeferred(false); mObservers[i]->ClearPendingNotify();
mTracker->SyncNotify(mObservers[i]); mTracker->SyncNotify(mObservers[i]);
} }
@ -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 // 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 // observer to its list of observers to be notified. This ensures we don't
@ -226,7 +226,7 @@ class AsyncNotifyCurrentStateRunnable : public Runnable
NS_IMETHOD Run() override NS_IMETHOD Run() override
{ {
MOZ_ASSERT(NS_IsMainThread(), "Should be running on the main thread"); MOZ_ASSERT(NS_IsMainThread(), "Should be running on the main thread");
mObserver->SetNotificationsDeferred(false); mObserver->ClearPendingNotify();
mProgressTracker->SyncNotify(mObserver); mProgressTracker->SyncNotify(mObserver);
return NS_OK; return NS_OK;
@ -261,7 +261,7 @@ ProgressTracker::NotifyCurrentState(IProgressObserver* aObserver)
"ProgressTracker::NotifyCurrentState", "uri", spec.get()); "ProgressTracker::NotifyCurrentState", "uri", spec.get());
} }
aObserver->SetNotificationsDeferred(true); aObserver->MarkPendingNotify();
nsCOMPtr<nsIRunnable> ev = new AsyncNotifyCurrentStateRunnable(this, nsCOMPtr<nsIRunnable> ev = new AsyncNotifyCurrentStateRunnable(this,
aObserver); aObserver);
@ -526,7 +526,7 @@ ProgressTracker::RemoveObserver(IProgressObserver* aObserver)
if (aObserver->NotificationsDeferred() && runnable) { if (aObserver->NotificationsDeferred() && runnable) {
runnable->RemoveObserver(aObserver); runnable->RemoveObserver(aObserver);
aObserver->SetNotificationsDeferred(false); aObserver->ClearPendingNotify();
} }
return removed; return removed;

View File

@ -120,7 +120,7 @@ imgRequestProxy::imgRequestProxy() :
mForceDispatchLoadGroup(false), mForceDispatchLoadGroup(false),
mListenerIsStrongRef(false), mListenerIsStrongRef(false),
mDecodeRequested(false), mDecodeRequested(false),
mDeferNotifications(false), mPendingNotify(false),
mValidating(false), mValidating(false),
mHadListener(false), mHadListener(false),
mHadDispatch(false) mHadDispatch(false)

View File

@ -115,11 +115,15 @@ public:
// an event it has scheduled has been fired and/or validation is complete. // an event it has scheduled has been fired and/or validation is complete.
virtual bool NotificationsDeferred() const override 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 bool IsValidating() const
{ {
@ -250,7 +254,7 @@ private:
// Whether we want to defer our notifications by the non-virtual Observer // Whether we want to defer our notifications by the non-virtual Observer
// interfaces as image loads proceed. // interfaces as image loads proceed.
bool mDeferNotifications : 1; bool mPendingNotify : 1;
bool mValidating : 1; bool mValidating : 1;
bool mHadListener : 1; bool mHadListener : 1;
bool mHadDispatch : 1; bool mHadDispatch : 1;