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