зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1728760 - move the nsHttpChannel nsITimerCallback implementation to a nested subclass to avoid issues when an object implements both nsIChannel and nsIRequest, r=smaug,necko-reviewers,kershaw.
Differential Revision: https://phabricator.services.mozilla.com/D124385
This commit is contained in:
Родитель
998adb18ea
Коммит
ba40523537
|
@ -3546,7 +3546,8 @@ nsresult nsHttpChannel::OpenCacheEntryInternal(bool isHttps) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// calls nsHttpChannel::Notify after `mCacheOpenDelay` milliseconds
|
// calls nsHttpChannel::Notify after `mCacheOpenDelay` milliseconds
|
||||||
NS_NewTimerWithCallback(getter_AddRefs(mCacheOpenTimer), this,
|
auto callback = MakeRefPtr<TimerCallback>(this);
|
||||||
|
NS_NewTimerWithCallback(getter_AddRefs(mCacheOpenTimer), callback,
|
||||||
mCacheOpenDelay, nsITimer::TYPE_ONE_SHOT);
|
mCacheOpenDelay, nsITimer::TYPE_ONE_SHOT);
|
||||||
}
|
}
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
@ -5351,8 +5352,6 @@ NS_INTERFACE_MAP_BEGIN(nsHttpChannel)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsICorsPreflightCallback)
|
NS_INTERFACE_MAP_ENTRY(nsICorsPreflightCallback)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIRaceCacheWithNetwork)
|
NS_INTERFACE_MAP_ENTRY(nsIRaceCacheWithNetwork)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
|
||||||
NS_INTERFACE_MAP_ENTRY(nsINamed)
|
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIRequestTailUnblockCallback)
|
NS_INTERFACE_MAP_ENTRY(nsIRequestTailUnblockCallback)
|
||||||
NS_INTERFACE_MAP_ENTRY_CONCRETE(nsHttpChannel)
|
NS_INTERFACE_MAP_ENTRY_CONCRETE(nsHttpChannel)
|
||||||
NS_INTERFACE_MAP_END_INHERITING(HttpBaseChannel)
|
NS_INTERFACE_MAP_END_INHERITING(HttpBaseChannel)
|
||||||
|
@ -8969,7 +8968,9 @@ nsresult nsHttpChannel::TriggerNetworkWithDelay(uint32_t aDelay) {
|
||||||
if (!mNetworkTriggerTimer) {
|
if (!mNetworkTriggerTimer) {
|
||||||
mNetworkTriggerTimer = NS_NewTimer();
|
mNetworkTriggerTimer = NS_NewTimer();
|
||||||
}
|
}
|
||||||
mNetworkTriggerTimer->InitWithCallback(this, aDelay, nsITimer::TYPE_ONE_SHOT);
|
auto callback = MakeRefPtr<TimerCallback>(this);
|
||||||
|
mNetworkTriggerTimer->InitWithCallback(callback, aDelay,
|
||||||
|
nsITimer::TYPE_ONE_SHOT);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9091,20 +9092,24 @@ nsHttpChannel::Test_triggerNetwork(int32_t aTimeout) {
|
||||||
return TriggerNetworkWithDelay(aTimeout);
|
return TriggerNetworkWithDelay(aTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsHttpChannel::TimerCallback::TimerCallback(nsHttpChannel* aChannel)
|
||||||
|
: mChannel(aChannel) {}
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(nsHttpChannel::TimerCallback, nsITimerCallback, nsINamed)
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsHttpChannel::GetName(nsACString& aName) {
|
nsHttpChannel::TimerCallback::GetName(nsACString& aName) {
|
||||||
aName.AssignLiteral("nsHttpChannel");
|
aName.AssignLiteral("nsHttpChannel");
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsHttpChannel::Notify(nsITimer* aTimer) {
|
nsHttpChannel::TimerCallback::Notify(nsITimer* aTimer) {
|
||||||
RefPtr<nsHttpChannel> self(this);
|
if (aTimer == mChannel->mCacheOpenTimer) {
|
||||||
if (aTimer == mCacheOpenTimer) {
|
return mChannel->Test_triggerDelayedOpenCacheEntry();
|
||||||
return Test_triggerDelayedOpenCacheEntry();
|
|
||||||
}
|
}
|
||||||
if (aTimer == mNetworkTriggerTimer) {
|
if (aTimer == mChannel->mNetworkTriggerTimer) {
|
||||||
return TriggerNetwork();
|
return mChannel->TriggerNetwork();
|
||||||
}
|
}
|
||||||
MOZ_CRASH("Unknown timer");
|
MOZ_CRASH("Unknown timer");
|
||||||
|
|
||||||
|
|
|
@ -74,9 +74,7 @@ class nsHttpChannel final : public HttpBaseChannel,
|
||||||
public nsSupportsWeakReference,
|
public nsSupportsWeakReference,
|
||||||
public nsICorsPreflightCallback,
|
public nsICorsPreflightCallback,
|
||||||
public nsIRaceCacheWithNetwork,
|
public nsIRaceCacheWithNetwork,
|
||||||
public nsIRequestTailUnblockCallback,
|
public nsIRequestTailUnblockCallback {
|
||||||
public nsITimerCallback,
|
|
||||||
public nsINamed {
|
|
||||||
public:
|
public:
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
NS_DECL_NSIREQUESTOBSERVER
|
NS_DECL_NSIREQUESTOBSERVER
|
||||||
|
@ -93,8 +91,6 @@ class nsHttpChannel final : public HttpBaseChannel,
|
||||||
NS_DECL_NSIDNSLISTENER
|
NS_DECL_NSIDNSLISTENER
|
||||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_HTTPCHANNEL_IID)
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_HTTPCHANNEL_IID)
|
||||||
NS_DECL_NSIRACECACHEWITHNETWORK
|
NS_DECL_NSIRACECACHEWITHNETWORK
|
||||||
NS_DECL_NSITIMERCALLBACK
|
|
||||||
NS_DECL_NSINAMED
|
|
||||||
NS_DECL_NSIREQUESTTAILUNBLOCKCALLBACK
|
NS_DECL_NSIREQUESTTAILUNBLOCKCALLBACK
|
||||||
|
|
||||||
// nsIHttpAuthenticableChannel. We can't use
|
// nsIHttpAuthenticableChannel. We can't use
|
||||||
|
@ -734,6 +730,23 @@ class nsHttpChannel final : public HttpBaseChannel,
|
||||||
// True if the channel is reading from cache.
|
// True if the channel is reading from cache.
|
||||||
Atomic<bool> mIsReadingFromCache{false};
|
Atomic<bool> mIsReadingFromCache{false};
|
||||||
|
|
||||||
|
// nsITimerCallback is implemented on a subclass so that the name attribute
|
||||||
|
// doesn't conflict with the name attribute of the nsIRequest interface that
|
||||||
|
// might be present on the same object (as seen from JavaScript code).
|
||||||
|
class TimerCallback final : public nsITimerCallback, public nsINamed {
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSITIMERCALLBACK
|
||||||
|
NS_DECL_NSINAMED
|
||||||
|
|
||||||
|
explicit TimerCallback(nsHttpChannel* aChannel);
|
||||||
|
|
||||||
|
private:
|
||||||
|
~TimerCallback() = default;
|
||||||
|
|
||||||
|
RefPtr<nsHttpChannel> mChannel;
|
||||||
|
};
|
||||||
|
|
||||||
// These next members are only used in unit tests to delay the call to
|
// These next members are only used in unit tests to delay the call to
|
||||||
// cache->AsyncOpenURI in order to race the cache with the network.
|
// cache->AsyncOpenURI in order to race the cache with the network.
|
||||||
nsCOMPtr<nsITimer> mCacheOpenTimer;
|
nsCOMPtr<nsITimer> mCacheOpenTimer;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче