Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/simpledb/ActorsChild.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 file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "ActorsChild.h"
8
9
#include "nsVariant.h"
10
#include "SDBConnection.h"
11
#include "SDBRequest.h"
12
#include "SDBResults.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
/*******************************************************************************
18
 * SDBConnectionChild
19
 ******************************************************************************/
20
21
SDBConnectionChild::SDBConnectionChild(SDBConnection* aConnection)
22
  : mConnection(aConnection)
23
0
{
24
0
  AssertIsOnOwningThread();
25
0
  MOZ_ASSERT(aConnection);
26
0
27
0
  MOZ_COUNT_CTOR(SDBConnectionChild);
28
0
}
29
30
SDBConnectionChild::~SDBConnectionChild()
31
0
{
32
0
  AssertIsOnOwningThread();
33
0
34
0
  MOZ_COUNT_DTOR(SDBConnectionChild);
35
0
}
36
37
void
38
SDBConnectionChild::SendDeleteMeInternal()
39
0
{
40
0
  AssertIsOnOwningThread();
41
0
42
0
  if (mConnection) {
43
0
    mConnection->ClearBackgroundActor();
44
0
    mConnection = nullptr;
45
0
46
0
    MOZ_ALWAYS_TRUE(PBackgroundSDBConnectionChild::SendDeleteMe());
47
0
  }
48
0
}
49
50
void
51
SDBConnectionChild::ActorDestroy(ActorDestroyReason aWhy)
52
0
{
53
0
  AssertIsOnOwningThread();
54
0
55
0
  if (mConnection) {
56
0
    mConnection->ClearBackgroundActor();
57
#ifdef DEBUG
58
    mConnection = nullptr;
59
#endif
60
  }
61
0
}
62
63
PBackgroundSDBRequestChild*
64
SDBConnectionChild::AllocPBackgroundSDBRequestChild(
65
                                                const SDBRequestParams& aParams)
66
0
{
67
0
  AssertIsOnOwningThread();
68
0
69
0
  MOZ_CRASH("PBackgroundSDBRequestChild actors should be manually "
70
0
            "constructed!");
71
0
}
72
73
bool
74
SDBConnectionChild::DeallocPBackgroundSDBRequestChild(
75
                                             PBackgroundSDBRequestChild* aActor)
76
0
{
77
0
  AssertIsOnOwningThread();
78
0
  MOZ_ASSERT(aActor);
79
0
80
0
  delete static_cast<SDBRequestChild*>(aActor);
81
0
  return true;
82
0
}
83
84
mozilla::ipc::IPCResult
85
SDBConnectionChild::RecvAllowToClose()
86
0
{
87
0
  AssertIsOnOwningThread();
88
0
89
0
  if (mConnection) {
90
0
    mConnection->AllowToClose();
91
0
  }
92
0
93
0
  return IPC_OK();
94
0
}
95
96
mozilla::ipc::IPCResult
97
SDBConnectionChild::RecvClosed()
98
0
{
99
0
  AssertIsOnOwningThread();
100
0
101
0
  if (mConnection) {
102
0
    mConnection->OnClose(/* aAbnormal */ true);
103
0
  }
104
0
105
0
  return IPC_OK();
106
0
}
107
108
/*******************************************************************************
109
 * SDBRequestChild
110
 ******************************************************************************/
111
112
SDBRequestChild::SDBRequestChild(SDBRequest* aRequest)
113
  : mConnection(aRequest->GetConnection())
114
  , mRequest(aRequest)
115
0
{
116
0
  AssertIsOnOwningThread();
117
0
  MOZ_ASSERT(aRequest);
118
0
119
0
  MOZ_COUNT_CTOR(SDBRequestChild);
120
0
}
121
122
SDBRequestChild::~SDBRequestChild()
123
0
{
124
0
  AssertIsOnOwningThread();
125
0
126
0
  MOZ_COUNT_DTOR(SDBRequestChild);
127
0
}
128
129
#ifdef DEBUG
130
131
void
132
SDBRequestChild::AssertIsOnOwningThread() const
133
{
134
  MOZ_ASSERT(mRequest);
135
  mRequest->AssertIsOnOwningThread();
136
}
137
138
#endif // DEBUG
139
140
void
141
SDBRequestChild::HandleResponse(nsresult aResponse)
142
0
{
143
0
  AssertIsOnOwningThread();
144
0
  MOZ_ASSERT(NS_FAILED(aResponse));
145
0
  MOZ_ASSERT(mRequest);
146
0
147
0
  mRequest->SetError(aResponse);
148
0
}
149
150
void
151
SDBRequestChild::HandleResponse()
152
0
{
153
0
  AssertIsOnOwningThread();
154
0
  MOZ_ASSERT(mRequest);
155
0
156
0
  RefPtr<nsVariant> variant = new nsVariant();
157
0
  variant->SetAsVoid();
158
0
159
0
  mRequest->SetResult(variant);
160
0
}
161
162
void
163
SDBRequestChild::HandleResponse(const nsCString& aResponse)
164
0
{
165
0
  AssertIsOnOwningThread();
166
0
  MOZ_ASSERT(mRequest);
167
0
168
0
  RefPtr<SDBResult> result = new SDBResult(aResponse);
169
0
170
0
  RefPtr<nsVariant> variant = new nsVariant();
171
0
  variant->SetAsInterface(NS_GET_IID(nsISDBResult), result);
172
0
173
0
  mRequest->SetResult(variant);
174
0
}
175
176
void
177
SDBRequestChild::ActorDestroy(ActorDestroyReason aWhy)
178
0
{
179
0
  AssertIsOnOwningThread();
180
0
181
0
  if (mConnection) {
182
0
    mConnection->AssertIsOnOwningThread();
183
0
184
0
    mConnection->OnRequestFinished();
185
#ifdef DEBUG
186
    mConnection = nullptr;
187
#endif
188
  }
189
0
}
190
191
mozilla::ipc::IPCResult
192
SDBRequestChild::Recv__delete__(const SDBRequestResponse& aResponse)
193
0
{
194
0
  AssertIsOnOwningThread();
195
0
  MOZ_ASSERT(mRequest);
196
0
  MOZ_ASSERT(mConnection);
197
0
198
0
  switch (aResponse.type()) {
199
0
    case SDBRequestResponse::Tnsresult:
200
0
      HandleResponse(aResponse.get_nsresult());
201
0
      break;
202
0
203
0
    case SDBRequestResponse::TSDBRequestOpenResponse:
204
0
      HandleResponse();
205
0
206
0
      mConnection->OnOpen();
207
0
208
0
      break;
209
0
210
0
    case SDBRequestResponse::TSDBRequestSeekResponse:
211
0
      HandleResponse();
212
0
      break;
213
0
214
0
    case SDBRequestResponse::TSDBRequestReadResponse:
215
0
      HandleResponse(aResponse.get_SDBRequestReadResponse().data());
216
0
      break;
217
0
218
0
    case SDBRequestResponse::TSDBRequestWriteResponse:
219
0
      HandleResponse();
220
0
      break;
221
0
222
0
    case SDBRequestResponse::TSDBRequestCloseResponse:
223
0
      HandleResponse();
224
0
225
0
      mConnection->OnClose(/* aAbnormal */ false);
226
0
227
0
      break;
228
0
229
0
    default:
230
0
      MOZ_CRASH("Unknown response type!");
231
0
  }
232
0
233
0
  mConnection->OnRequestFinished();
234
0
235
0
  // Null this out so that we don't try to call OnRequestFinished() again in
236
0
  // ActorDestroy.
237
0
  mConnection = nullptr;
238
0
239
0
  return IPC_OK();
240
0
}
241
242
} // namespace dom
243
} // namespace mozilla