netwerk/base/src/RedirectChannelRegistrar.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/base/src/RedirectChannelRegistrar.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "RedirectChannelRegistrar.h"
     1.9 +
    1.10 +namespace mozilla {
    1.11 +namespace net {
    1.12 +
    1.13 +NS_IMPL_ISUPPORTS(RedirectChannelRegistrar, nsIRedirectChannelRegistrar)
    1.14 +
    1.15 +RedirectChannelRegistrar::RedirectChannelRegistrar()
    1.16 +  : mRealChannels(64)
    1.17 +  , mParentChannels(64)
    1.18 +  , mId(1)
    1.19 +{
    1.20 +}
    1.21 +
    1.22 +NS_IMETHODIMP
    1.23 +RedirectChannelRegistrar::RegisterChannel(nsIChannel *channel,
    1.24 +                                          uint32_t *_retval)
    1.25 +{
    1.26 +  mRealChannels.Put(mId, channel);
    1.27 +  *_retval = mId;
    1.28 +
    1.29 +  ++mId;
    1.30 +
    1.31 +  // Ensure we always provide positive ids
    1.32 +  if (!mId)
    1.33 +    mId = 1;
    1.34 +
    1.35 +  return NS_OK;
    1.36 +}
    1.37 +
    1.38 +NS_IMETHODIMP
    1.39 +RedirectChannelRegistrar::GetRegisteredChannel(uint32_t id,
    1.40 +                                               nsIChannel **_retval)
    1.41 +{
    1.42 +  if (!mRealChannels.Get(id, _retval))
    1.43 +    return NS_ERROR_NOT_AVAILABLE;
    1.44 +
    1.45 +  return NS_OK;
    1.46 +}
    1.47 +
    1.48 +NS_IMETHODIMP
    1.49 +RedirectChannelRegistrar::LinkChannels(uint32_t id,
    1.50 +                                       nsIParentChannel *channel,
    1.51 +                                       nsIChannel** _retval)
    1.52 +{
    1.53 +  if (!mRealChannels.Get(id, _retval))
    1.54 +    return NS_ERROR_NOT_AVAILABLE;
    1.55 +
    1.56 +  mParentChannels.Put(id, channel);
    1.57 +  return NS_OK;
    1.58 +}
    1.59 +
    1.60 +NS_IMETHODIMP
    1.61 +RedirectChannelRegistrar::GetParentChannel(uint32_t id,
    1.62 +                                           nsIParentChannel **_retval)
    1.63 +{
    1.64 +  if (!mParentChannels.Get(id, _retval))
    1.65 +    return NS_ERROR_NOT_AVAILABLE;
    1.66 +
    1.67 +  return NS_OK;
    1.68 +}
    1.69 +
    1.70 +NS_IMETHODIMP
    1.71 +RedirectChannelRegistrar::DeregisterChannels(uint32_t id)
    1.72 +{
    1.73 +  mRealChannels.Remove(id);
    1.74 +  mParentChannels.Remove(id);
    1.75 +  return NS_OK;
    1.76 +}
    1.77 +
    1.78 +}
    1.79 +}

mercurial