2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-11-24 01:56:06 +03:00
|
|
|
|
|
|
|
#include "RedirectChannelRegistrar.h"
|
2018-08-22 07:37:28 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2018-10-29 14:22:40 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2010-11-24 01:56:06 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2018-10-29 14:22:58 +03:00
|
|
|
StaticRefPtr<RedirectChannelRegistrar> RedirectChannelRegistrar::gSingleton;
|
2018-08-22 07:37:28 +03:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(RedirectChannelRegistrar, nsIRedirectChannelRegistrar)
|
2010-11-24 01:56:06 +03:00
|
|
|
|
|
|
|
RedirectChannelRegistrar::RedirectChannelRegistrar()
|
2014-08-06 17:31:21 +04:00
|
|
|
: mRealChannels(32),
|
|
|
|
mParentChannels(32),
|
2013-09-02 12:41:57 +04:00
|
|
|
mId(1),
|
2015-12-04 11:55:00 +03:00
|
|
|
mLock("RedirectChannelRegistrar") {
|
2018-08-22 07:37:28 +03:00
|
|
|
MOZ_ASSERT(!gSingleton);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<nsIRedirectChannelRegistrar>
|
|
|
|
RedirectChannelRegistrar::GetOrCreate() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (!gSingleton) {
|
|
|
|
gSingleton = new RedirectChannelRegistrar();
|
|
|
|
}
|
|
|
|
return do_AddRef(gSingleton);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void RedirectChannelRegistrar::Shutdown() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
gSingleton = nullptr;
|
2010-11-24 01:56:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
RedirectChannelRegistrar::RegisterChannel(nsIChannel* channel,
|
|
|
|
uint32_t* _retval) {
|
2015-12-04 11:55:00 +03:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
2010-11-24 01:56:06 +03:00
|
|
|
mRealChannels.Put(mId, channel);
|
|
|
|
*_retval = mId;
|
|
|
|
|
|
|
|
++mId;
|
|
|
|
|
|
|
|
// Ensure we always provide positive ids
|
|
|
|
if (!mId) mId = 1;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
RedirectChannelRegistrar::GetRegisteredChannel(uint32_t id,
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIChannel** _retval) {
|
2015-12-04 11:55:00 +03:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
2010-11-24 01:56:06 +03:00
|
|
|
if (!mRealChannels.Get(id, _retval)) return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-01 11:47:10 +03:00
|
|
|
RedirectChannelRegistrar::LinkChannels(uint32_t id, nsIParentChannel* channel,
|
|
|
|
nsIChannel** _retval) {
|
2015-12-04 11:55:00 +03:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
2010-11-24 01:56:06 +03:00
|
|
|
if (!mRealChannels.Get(id, _retval)) return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
mParentChannels.Put(id, channel);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
RedirectChannelRegistrar::GetParentChannel(uint32_t id,
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIParentChannel** _retval) {
|
2015-12-04 11:55:00 +03:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
2010-11-24 01:56:06 +03:00
|
|
|
if (!mParentChannels.Get(id, _retval)) return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
RedirectChannelRegistrar::DeregisterChannels(uint32_t id) {
|
2015-12-04 11:55:00 +03:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
2010-11-24 01:56:06 +03:00
|
|
|
mRealChannels.Remove(id);
|
|
|
|
mParentChannels.Remove(id);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|