Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/file/ipc/IPCBlobInputStreamChild.h
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
#ifndef mozilla_dom_ipc_IPCBlobInputStreamChild_h
8
#define mozilla_dom_ipc_IPCBlobInputStreamChild_h
9
10
#include "mozilla/ipc/PIPCBlobInputStreamChild.h"
11
#include "mozilla/Mutex.h"
12
#include "mozilla/UniquePtr.h"
13
#include "nsIThread.h"
14
#include "nsTArray.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
class IPCBlobInputStream;
20
class ThreadSafeWorkerRef;
21
22
class IPCBlobInputStreamChild final
23
  : public mozilla::ipc::PIPCBlobInputStreamChild
24
{
25
public:
26
  enum ActorState
27
  {
28
    // The actor is connected via IPDL to the parent.
29
    eActive,
30
31
    // The actor is disconnected.
32
    eInactive,
33
34
    // The actor is waiting to be disconnected. Once it has been disconnected,
35
    // it will be reactivated on the DOM-File thread.
36
    eActiveMigrating,
37
38
    // The actor has been disconnected and it's waiting to be connected on the
39
    // DOM-File thread.
40
    eInactiveMigrating,
41
  };
42
43
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(IPCBlobInputStreamChild)
44
45
  IPCBlobInputStreamChild(const nsID& aID, uint64_t aSize);
46
47
  void
48
  ActorDestroy(IProtocol::ActorDestroyReason aReason) override;
49
50
  ActorState
51
  State();
52
53
  already_AddRefed<IPCBlobInputStream>
54
  CreateStream();
55
56
  void
57
  ForgetStream(IPCBlobInputStream* aStream);
58
59
  const nsID&
60
  ID() const
61
0
  {
62
0
    return mID;
63
0
  }
64
65
  uint64_t
66
  Size() const
67
0
  {
68
0
    return mSize;
69
0
  }
70
71
  void
72
  StreamNeeded(IPCBlobInputStream* aStream,
73
               nsIEventTarget* aEventTarget);
74
75
  mozilla::ipc::IPCResult
76
  RecvStreamReady(const OptionalIPCStream& aStream) override;
77
78
  void
79
  LengthNeeded(IPCBlobInputStream* aStream,
80
               nsIEventTarget* aEventTarget);
81
82
  mozilla::ipc::IPCResult
83
  RecvLengthReady(const int64_t& aLength) override;
84
85
  void
86
  Shutdown();
87
88
  void
89
  Migrated();
90
91
private:
92
  ~IPCBlobInputStreamChild();
93
94
  // Raw pointers because these streams keep this actor alive. When the last
95
  // stream is unregister, the actor will be deleted. This list is protected by
96
  // mutex.
97
  nsTArray<IPCBlobInputStream*> mStreams;
98
99
  // This mutex protects mStreams because that can be touched in any thread.
100
  Mutex mMutex;
101
102
  const nsID mID;
103
  const uint64_t mSize;
104
105
  ActorState  mState;
106
107
  // This struct and the array are used for creating streams when needed.
108
  struct PendingOperation
109
  {
110
    RefPtr<IPCBlobInputStream> mStream;
111
    nsCOMPtr<nsIEventTarget> mEventTarget;
112
    enum
113
    {
114
      eStreamNeeded,
115
      eLengthNeeded,
116
    } mOp;
117
  };
118
  nsTArray<PendingOperation> mPendingOperations;
119
120
  nsCOMPtr<nsISerialEventTarget> mOwningEventTarget;
121
122
  RefPtr<ThreadSafeWorkerRef> mWorkerRef;
123
};
124
125
} // namespace dom
126
} // namespace mozilla
127
128
#endif // mozilla_dom_ipc_IPCBlobInputStreamChild_h