Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/protocol/http/BackgroundChannelRegistrar.cpp
Line
Count
Source (jump to first uncovered line)
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
NS_IMPL_ISUPPORTS(BackgroundChannelRegistrar, nsIBackgroundChannelRegistrar)
18
19
BackgroundChannelRegistrar::BackgroundChannelRegistrar()
20
0
{
21
0
  // BackgroundChannelRegistrar is a main-thread-only object.
22
0
  // All the operations should be run on main thread.
23
0
  // It should be used on chrome process only.
24
0
  MOZ_ASSERT(XRE_IsParentProcess());
25
0
  MOZ_ASSERT(NS_IsMainThread());
26
0
}
27
28
BackgroundChannelRegistrar::~BackgroundChannelRegistrar()
29
0
{
30
0
  MOZ_ASSERT(NS_IsMainThread());
31
0
}
32
33
void
34
BackgroundChannelRegistrar::NotifyChannelLinked(
35
  HttpChannelParent* aChannelParent,
36
  HttpBackgroundChannelParent* aBgParent)
37
0
{
38
0
  MOZ_ASSERT(NS_IsMainThread());
39
0
  MOZ_ASSERT(aChannelParent);
40
0
  MOZ_ASSERT(aBgParent);
41
0
42
0
  aBgParent->LinkToChannel(aChannelParent);
43
0
  aChannelParent->OnBackgroundParentReady(aBgParent);
44
0
}
45
46
// nsIBackgroundChannelRegistrar
47
void
48
BackgroundChannelRegistrar::DeleteChannel(uint64_t aKey)
49
0
{
50
0
  MOZ_ASSERT(NS_IsMainThread());
51
0
52
0
  mChannels.Remove(aKey);
53
0
  mBgChannels.Remove(aKey);
54
0
}
55
56
void
57
BackgroundChannelRegistrar::LinkHttpChannel(
58
  uint64_t aKey,
59
  HttpChannelParent* aChannel)
60
0
{
61
0
  MOZ_ASSERT(NS_IsMainThread());
62
0
  MOZ_ASSERT(aChannel);
63
0
64
0
  RefPtr<HttpBackgroundChannelParent> bgParent;
65
0
  bool found = mBgChannels.Remove(aKey, getter_AddRefs(bgParent));
66
0
67
0
  if (!found) {
68
0
    mChannels.Put(aKey, aChannel);
69
0
    return;
70
0
  }
71
0
72
0
  MOZ_ASSERT(bgParent);
73
0
  NotifyChannelLinked(aChannel, bgParent);
74
0
}
75
76
void
77
BackgroundChannelRegistrar::LinkBackgroundChannel(
78
  uint64_t aKey,
79
  HttpBackgroundChannelParent* aBgChannel)
80
0
{
81
0
  MOZ_ASSERT(NS_IsMainThread());
82
0
  MOZ_ASSERT(aBgChannel);
83
0
84
0
  RefPtr<HttpChannelParent> parent;
85
0
  bool found = mChannels.Remove(aKey, getter_AddRefs(parent));
86
0
87
0
  if (!found) {
88
0
    mBgChannels.Put(aKey, aBgChannel);
89
0
    return;
90
0
  }
91
0
92
0
  MOZ_ASSERT(parent);
93
0
  NotifyChannelLinked(parent, aBgChannel);
94
0
}
95
96
} // namespace net
97
} // namespace mozilla