RedirectChannelRegistrar.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "RedirectChannelRegistrar.h"
  5. namespace mozilla {
  6. namespace net {
  7. NS_IMPL_ISUPPORTS(RedirectChannelRegistrar, nsIRedirectChannelRegistrar)
  8. RedirectChannelRegistrar::RedirectChannelRegistrar()
  9. : mRealChannels(32)
  10. , mParentChannels(32)
  11. , mId(1)
  12. , mLock("RedirectChannelRegistrar")
  13. {
  14. }
  15. NS_IMETHODIMP
  16. RedirectChannelRegistrar::RegisterChannel(nsIChannel *channel,
  17. uint32_t *_retval)
  18. {
  19. MutexAutoLock lock(mLock);
  20. mRealChannels.Put(mId, channel);
  21. *_retval = mId;
  22. ++mId;
  23. // Ensure we always provide positive ids
  24. if (!mId)
  25. mId = 1;
  26. return NS_OK;
  27. }
  28. NS_IMETHODIMP
  29. RedirectChannelRegistrar::GetRegisteredChannel(uint32_t id,
  30. nsIChannel **_retval)
  31. {
  32. MutexAutoLock lock(mLock);
  33. if (!mRealChannels.Get(id, _retval))
  34. return NS_ERROR_NOT_AVAILABLE;
  35. return NS_OK;
  36. }
  37. NS_IMETHODIMP
  38. RedirectChannelRegistrar::LinkChannels(uint32_t id,
  39. nsIParentChannel *channel,
  40. nsIChannel** _retval)
  41. {
  42. MutexAutoLock lock(mLock);
  43. if (!mRealChannels.Get(id, _retval))
  44. return NS_ERROR_NOT_AVAILABLE;
  45. mParentChannels.Put(id, channel);
  46. return NS_OK;
  47. }
  48. NS_IMETHODIMP
  49. RedirectChannelRegistrar::GetParentChannel(uint32_t id,
  50. nsIParentChannel **_retval)
  51. {
  52. MutexAutoLock lock(mLock);
  53. if (!mParentChannels.Get(id, _retval))
  54. return NS_ERROR_NOT_AVAILABLE;
  55. return NS_OK;
  56. }
  57. NS_IMETHODIMP
  58. RedirectChannelRegistrar::DeregisterChannels(uint32_t id)
  59. {
  60. MutexAutoLock lock(mLock);
  61. mRealChannels.Remove(id);
  62. mParentChannels.Remove(id);
  63. return NS_OK;
  64. }
  65. } // namespace net
  66. } // namespace mozilla