Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/protocol/http/AltDataOutputStreamParent.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 sw=2 ts=8 et tw=80 : */
3
4
/* This Source Code Form is subject to the terms of the Mozilla Public
5
 * License, v. 2.0. If a copy of the MPL was not distributed with this
6
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8
#include "mozilla/net/AltDataOutputStreamParent.h"
9
#include "mozilla/Unused.h"
10
11
namespace mozilla {
12
namespace net {
13
14
NS_IMPL_ISUPPORTS0(AltDataOutputStreamParent)
15
16
AltDataOutputStreamParent::AltDataOutputStreamParent(nsIOutputStream* aStream)
17
  : mOutputStream(aStream)
18
  , mStatus(NS_OK)
19
  , mIPCOpen(true)
20
0
{
21
0
  MOZ_ASSERT(NS_IsMainThread(), "Main thread only");
22
0
}
23
24
AltDataOutputStreamParent::~AltDataOutputStreamParent()
25
0
{
26
0
  MOZ_ASSERT(NS_IsMainThread(), "Main thread only");
27
0
}
28
29
mozilla::ipc::IPCResult
30
AltDataOutputStreamParent::RecvWriteData(const nsCString& data)
31
0
{
32
0
  if (NS_FAILED(mStatus)) {
33
0
    if (mIPCOpen) {
34
0
      Unused << SendError(mStatus);
35
0
    }
36
0
    return IPC_OK();
37
0
  }
38
0
  nsresult rv;
39
0
  uint32_t n;
40
0
  if (mOutputStream) {
41
0
    rv = mOutputStream->Write(data.BeginReading(), data.Length(), &n);
42
0
    MOZ_ASSERT(n == data.Length() || NS_FAILED(rv));
43
0
    if (NS_FAILED(rv) && mIPCOpen) {
44
0
      Unused << SendError(rv);
45
0
    }
46
0
  }
47
0
  return IPC_OK();
48
0
}
49
50
mozilla::ipc::IPCResult
51
AltDataOutputStreamParent::RecvClose()
52
0
{
53
0
  if (NS_FAILED(mStatus)) {
54
0
    if (mIPCOpen) {
55
0
      Unused << SendError(mStatus);
56
0
    }
57
0
    return IPC_OK();
58
0
  }
59
0
  nsresult rv;
60
0
  if (mOutputStream) {
61
0
    rv = mOutputStream->Close();
62
0
    if (NS_FAILED(rv) && mIPCOpen) {
63
0
      Unused << SendError(rv);
64
0
    }
65
0
    mOutputStream = nullptr;
66
0
  }
67
0
  return IPC_OK();
68
0
}
69
70
void
71
AltDataOutputStreamParent::ActorDestroy(ActorDestroyReason aWhy)
72
0
{
73
0
  mIPCOpen = false;
74
0
}
75
76
mozilla::ipc::IPCResult
77
AltDataOutputStreamParent::RecvDeleteSelf()
78
0
{
79
0
  mIPCOpen = false;
80
0
  Unused << SendDeleteSelf();
81
0
  return IPC_OK();
82
0
}
83
84
} // namespace net
85
} // namespace mozilla