Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "BackgroundChannelRegistrar.h"
8 :
9 : #include "HttpBackgroundChannelParent.h"
10 : #include "HttpChannelParent.h"
11 : #include "nsIInterfaceRequestor.h"
12 : #include "nsXULAppAPI.h"
13 :
14 : namespace mozilla {
15 : namespace net {
16 :
17 21 : NS_IMPL_ISUPPORTS(BackgroundChannelRegistrar, nsIBackgroundChannelRegistrar)
18 :
19 1 : BackgroundChannelRegistrar::BackgroundChannelRegistrar()
20 : {
21 : // BackgroundChannelRegistrar is a main-thread-only object.
22 : // All the operations should be run on main thread.
23 : // It should be used on chrome process only.
24 1 : MOZ_ASSERT(XRE_IsParentProcess());
25 1 : MOZ_ASSERT(NS_IsMainThread());
26 1 : }
27 :
28 0 : BackgroundChannelRegistrar::~BackgroundChannelRegistrar()
29 : {
30 0 : MOZ_ASSERT(NS_IsMainThread());
31 0 : }
32 :
33 : void
34 3 : BackgroundChannelRegistrar::NotifyChannelLinked(
35 : HttpChannelParent* aChannelParent,
36 : HttpBackgroundChannelParent* aBgParent)
37 : {
38 3 : MOZ_ASSERT(NS_IsMainThread());
39 3 : MOZ_ASSERT(aChannelParent);
40 3 : MOZ_ASSERT(aBgParent);
41 :
42 3 : aBgParent->LinkToChannel(aChannelParent);
43 3 : aChannelParent->OnBackgroundParentReady(aBgParent);
44 3 : }
45 :
46 : // nsIBackgroundChannelRegistrar
47 : void
48 0 : BackgroundChannelRegistrar::DeleteChannel(uint64_t aKey)
49 : {
50 0 : MOZ_ASSERT(NS_IsMainThread());
51 :
52 0 : mChannels.Remove(aKey);
53 0 : mBgChannels.Remove(aKey);
54 0 : }
55 :
56 : void
57 3 : BackgroundChannelRegistrar::LinkHttpChannel(
58 : uint64_t aKey,
59 : HttpChannelParent* aChannel)
60 : {
61 3 : MOZ_ASSERT(NS_IsMainThread());
62 3 : MOZ_ASSERT(aChannel);
63 :
64 3 : RefPtr<HttpBackgroundChannelParent> bgParent;
65 3 : bool found = mBgChannels.Remove(aKey, getter_AddRefs(bgParent));
66 :
67 3 : if (!found) {
68 3 : mChannels.Put(aKey, aChannel);
69 3 : return;
70 : }
71 :
72 0 : MOZ_ASSERT(bgParent);
73 0 : NotifyChannelLinked(aChannel, bgParent);
74 : }
75 :
76 : void
77 3 : BackgroundChannelRegistrar::LinkBackgroundChannel(
78 : uint64_t aKey,
79 : HttpBackgroundChannelParent* aBgChannel)
80 : {
81 3 : MOZ_ASSERT(NS_IsMainThread());
82 3 : MOZ_ASSERT(aBgChannel);
83 :
84 6 : RefPtr<HttpChannelParent> parent;
85 3 : bool found = mChannels.Remove(aKey, getter_AddRefs(parent));
86 :
87 3 : if (!found) {
88 0 : mBgChannels.Put(aKey, aBgChannel);
89 0 : return;
90 : }
91 :
92 3 : MOZ_ASSERT(parent);
93 3 : NotifyChannelLinked(parent, aBgChannel);
94 : }
95 :
96 : } // namespace net
97 : } // namespace mozilla
|