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 "mozilla/dom/cache/CacheStreamControlParent.h"
8 :
9 : #include "mozilla/Unused.h"
10 : #include "mozilla/dom/cache/CacheTypes.h"
11 : #include "mozilla/dom/cache/ReadStream.h"
12 : #include "mozilla/dom/cache/StreamList.h"
13 : #include "mozilla/ipc/FileDescriptorSetParent.h"
14 : #include "mozilla/ipc/PBackgroundParent.h"
15 : #include "mozilla/ipc/PFileDescriptorSetParent.h"
16 : #include "nsISupportsImpl.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 : namespace cache {
21 :
22 : using mozilla::dom::OptionalFileDescriptorSet;
23 : using mozilla::ipc::FileDescriptor;
24 : using mozilla::ipc::FileDescriptorSetParent;
25 : using mozilla::ipc::PFileDescriptorSetParent;
26 :
27 : // declared in ActorUtils.h
28 : void
29 0 : DeallocPCacheStreamControlParent(PCacheStreamControlParent* aActor)
30 : {
31 0 : delete aActor;
32 0 : }
33 :
34 0 : CacheStreamControlParent::CacheStreamControlParent()
35 : {
36 0 : MOZ_COUNT_CTOR(cache::CacheStreamControlParent);
37 0 : }
38 :
39 0 : CacheStreamControlParent::~CacheStreamControlParent()
40 : {
41 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
42 0 : MOZ_DIAGNOSTIC_ASSERT(!mStreamList);
43 0 : MOZ_COUNT_DTOR(cache::CacheStreamControlParent);
44 0 : }
45 :
46 : void
47 0 : CacheStreamControlParent::SerializeControl(CacheReadStream* aReadStreamOut)
48 : {
49 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
50 0 : MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut);
51 0 : aReadStreamOut->controlChild() = nullptr;
52 0 : aReadStreamOut->controlParent() = this;
53 0 : }
54 :
55 : void
56 0 : CacheStreamControlParent::SerializeStream(CacheReadStream* aReadStreamOut,
57 : nsIInputStream* aStream,
58 : nsTArray<UniquePtr<AutoIPCStream>>& aStreamCleanupList)
59 : {
60 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
61 0 : MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut);
62 0 : MOZ_DIAGNOSTIC_ASSERT(aStream);
63 :
64 0 : UniquePtr<AutoIPCStream> autoStream(new AutoIPCStream(aReadStreamOut->stream()));
65 0 : DebugOnly<bool> ok = autoStream->Serialize(aStream, Manager());
66 0 : MOZ_ASSERT(ok);
67 :
68 0 : aStreamCleanupList.AppendElement(Move(autoStream));
69 0 : }
70 :
71 : void
72 0 : CacheStreamControlParent::NoteClosedAfterForget(const nsID& aId)
73 : {
74 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
75 0 : RecvNoteClosed(aId);
76 0 : }
77 :
78 : #ifdef DEBUG
79 : void
80 0 : CacheStreamControlParent::AssertOwningThread()
81 : {
82 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
83 0 : }
84 : #endif
85 :
86 : void
87 0 : CacheStreamControlParent::ActorDestroy(ActorDestroyReason aReason)
88 : {
89 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
90 0 : CloseAllReadStreamsWithoutReporting();
91 : // If the initial SendPStreamControlConstructor() fails we will
92 : // be called before mStreamList is set.
93 0 : if (!mStreamList) {
94 0 : return;
95 : }
96 0 : mStreamList->RemoveStreamControl(this);
97 0 : mStreamList->NoteClosedAll();
98 0 : mStreamList = nullptr;
99 : }
100 :
101 : mozilla::ipc::IPCResult
102 0 : CacheStreamControlParent::RecvNoteClosed(const nsID& aId)
103 : {
104 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
105 0 : MOZ_DIAGNOSTIC_ASSERT(mStreamList);
106 0 : mStreamList->NoteClosed(aId);
107 0 : return IPC_OK();
108 : }
109 :
110 : void
111 0 : CacheStreamControlParent::SetStreamList(StreamList* aStreamList)
112 : {
113 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
114 0 : MOZ_DIAGNOSTIC_ASSERT(!mStreamList);
115 0 : mStreamList = aStreamList;
116 0 : }
117 :
118 : void
119 0 : CacheStreamControlParent::Close(const nsID& aId)
120 : {
121 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
122 0 : NotifyClose(aId);
123 0 : Unused << SendClose(aId);
124 0 : }
125 :
126 : void
127 0 : CacheStreamControlParent::CloseAll()
128 : {
129 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
130 0 : NotifyCloseAll();
131 0 : Unused << SendCloseAll();
132 0 : }
133 :
134 : void
135 0 : CacheStreamControlParent::Shutdown()
136 : {
137 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
138 0 : if (!Send__delete__(this)) {
139 : // child process is gone, allow actor to be destroyed normally
140 0 : NS_WARNING("Cache failed to delete stream actor.");
141 0 : return;
142 : }
143 : }
144 :
145 : void
146 0 : CacheStreamControlParent::NotifyClose(const nsID& aId)
147 : {
148 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
149 0 : CloseReadStreams(aId);
150 0 : }
151 :
152 : void
153 0 : CacheStreamControlParent::NotifyCloseAll()
154 : {
155 0 : NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
156 0 : CloseAllReadStreams();
157 0 : }
158 :
159 : } // namespace cache
160 : } // namespace dom
161 : } // namespace mozilla
|