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 #ifndef mozilla_dom_simpledb_ActorsChild_h
8 #define mozilla_dom_simpledb_ActorsChild_h
9 
10 #include "mozilla/dom/PBackgroundSDBConnectionChild.h"
11 #include "mozilla/dom/PBackgroundSDBRequestChild.h"
12 
13 namespace mozilla {
14 namespace ipc {
15 
16 class BackgroundChildImpl;
17 
18 }  // namespace ipc
19 
20 namespace dom {
21 
22 class SDBConnection;
23 class SDBRequest;
24 
25 class SDBConnectionChild final : public PBackgroundSDBConnectionChild {
26   friend class mozilla::ipc::BackgroundChildImpl;
27   friend class SDBConnection;
28 
29   SDBConnection* mConnection;
30 
31   NS_DECL_OWNINGTHREAD
32 
33  public:
AssertIsOnOwningThread()34   void AssertIsOnOwningThread() const {
35     NS_ASSERT_OWNINGTHREAD(SDBConnectionChild);
36   }
37 
38  private:
39   // Only created by SDBConnection.
40   explicit SDBConnectionChild(SDBConnection* aConnection);
41 
42   // Only destroyed by mozilla::ipc::BackgroundChildImpl.
43   ~SDBConnectionChild();
44 
45   void SendDeleteMeInternal();
46 
47   // IPDL methods are only called by IPDL.
48   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
49 
50   virtual PBackgroundSDBRequestChild* AllocPBackgroundSDBRequestChild(
51       const SDBRequestParams& aParams) override;
52 
53   virtual bool DeallocPBackgroundSDBRequestChild(
54       PBackgroundSDBRequestChild* aActor) override;
55 
56   virtual mozilla::ipc::IPCResult RecvAllowToClose() override;
57 
58   virtual mozilla::ipc::IPCResult RecvClosed() override;
59 };
60 
61 class SDBRequestChild final : public PBackgroundSDBRequestChild {
62   friend class SDBConnectionChild;
63   friend class SDBConnection;
64 
65   RefPtr<SDBConnection> mConnection;
66   RefPtr<SDBRequest> mRequest;
67 
68  public:
69   void AssertIsOnOwningThread() const
70 #ifdef DEBUG
71       ;
72 #else
73   {
74   }
75 #endif
76 
77  private:
78   // Only created by SDBConnection.
79   explicit SDBRequestChild(SDBRequest* aRequest);
80 
81   // Only destroyed by SDBConnectionChild.
82   ~SDBRequestChild();
83 
84   void HandleResponse(nsresult aResponse);
85 
86   void HandleResponse();
87 
88   void HandleResponse(const nsCString& aResponse);
89 
90   // IPDL methods are only called by IPDL.
91   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
92 
93   virtual mozilla::ipc::IPCResult Recv__delete__(
94       const SDBRequestResponse& aResponse) override;
95 };
96 
97 }  // namespace dom
98 }  // namespace mozilla
99 
100 #endif  // mozilla_dom_simpledb_ActorsChild_h
101