Attachment #8832152: Part 3.1 (interdiff): IPC for bug #1217544

View | Details | Raw Unified | Return to bug 1217544
Collapse All | Expand All

(-)a/dom/backgroundsync/BackgroundSync.cpp (-3 / +3 lines)
Line     Link Here 
 Lines 58-74   public: Link Here 
58
    MOZ_ASSERT(mActor);
58
    MOZ_ASSERT(mActor);
59
    if (mActor->IsActorDestroyed()) {
59
    if (mActor->IsActorDestroyed()) {
60
      return NS_OK;
60
      return NS_OK;
61
    }
61
    }
62
62
63
    return mActor->ExecuteOp(mPromise, mOp);
63
    return mActor->ExecuteOp(mPromise, mOp);
64
  }
64
  }
65
65
66
  NS_IMETHOD Cancel() override
66
  nsresult Cancel() override
67
  {
67
  {
68
    mActor = nullptr;
68
    mActor = nullptr;
69
    mPromise = nullptr;
69
    mPromise = nullptr;
70
    mOp = nullptr;
70
    mOp = nullptr;
71
    return NS_OK;
71
    return NS_OK;
72
  }
72
  }
73
73
74
private:
74
private:
 Lines 97-113   public: Link Here 
97
  {
97
  {
98
    MOZ_ASSERT(mActor);
98
    MOZ_ASSERT(mActor);
99
    if (!mActor->IsActorDestroyed()) {
99
    if (!mActor->IsActorDestroyed()) {
100
      mActor->SendShutdown();
100
      mActor->SendShutdown();
101
    }
101
    }
102
    return NS_OK;
102
    return NS_OK;
103
  }
103
  }
104
104
105
  NS_IMETHOD Cancel() override
105
  nsresult Cancel() override
106
  {
106
  {
107
    mActor = nullptr;
107
    mActor = nullptr;
108
    return NS_OK;
108
    return NS_OK;
109
  }
109
  }
110
110
111
private:
111
private:
112
  ~TeardownRunnable() {};
112
  ~TeardownRunnable() {};
113
113
 Lines 135-151   public: Link Here 
135
      mManager->Shutdown();
135
      mManager->Shutdown();
136
    }
136
    }
137
    return true;
137
    return true;
138
  }
138
  }
139
139
140
private:
140
private:
141
  ~BackgroundSyncHolder()
141
  ~BackgroundSyncHolder()
142
  {
142
  {
143
    MOZ_COUNT_CTOR(BackgroundSyncHolder);
143
    MOZ_COUNT_DTOR(BackgroundSyncHolder);
144
  }
144
  }
145
};
145
};
146
146
147
// BackgroundSync
147
// BackgroundSync
148
148
149
// static
149
// static
150
already_AddRefed<BackgroundSync>
150
already_AddRefed<BackgroundSync>
151
BackgroundSync::CreateOnMainThread(nsIGlobalObject* aGlobal,
151
BackgroundSync::CreateOnMainThread(nsIGlobalObject* aGlobal,
(-)a/dom/backgroundsync/BackgroundSyncChild.cpp (-6 / +6 lines)
Line     Link Here 
 Lines 92-129   BackgroundSyncChild::ExecuteOp(Promise* Link Here 
92
  nsresult rv = StorePendingRequest(aPromise, requestId);
92
  nsresult rv = StorePendingRequest(aPromise, requestId);
93
  NS_ENSURE_SUCCESS(rv, rv);
93
  NS_ENSURE_SUCCESS(rv, rv);
94
94
95
  Unused << SendRequest(requestId, *aOp);
95
  Unused << SendRequest(requestId, *aOp);
96
96
97
  return NS_OK;
97
  return NS_OK;
98
}
98
}
99
99
100
bool
100
mozilla::ipc::IPCResult
101
BackgroundSyncChild::RecvResponse(const nsID& aRequestId,
101
BackgroundSyncChild::RecvResponse(const nsID& aRequestId,
102
                                  const SyncOpResponse& aResponse)
102
                                  const SyncOpResponse& aResponse)
103
{
103
{
104
  Promise* p = GetPendingRequest(aRequestId);
104
  Promise* p = GetPendingRequest(aRequestId);
105
  if (NS_WARN_IF(!p)) {
105
  if (NS_WARN_IF(!p)) {
106
    // This should never happen.
106
    // This should never happen.
107
    return false;
107
    return IPC_FAIL_NO_REASON(this);
108
  }
108
  }
109
109
110
  switch(aResponse.type()) {
110
  switch(aResponse.type()) {
111
    case SyncOpResponse::TSyncRegisterResponse:
111
    case SyncOpResponse::TSyncRegisterResponse:
112
      p->MaybeResolve(true);
112
      p->MaybeResolve(true);
113
      return true;
113
      return IPC_OK();
114
    case SyncOpResponse::TSyncGetTagsResponse:
114
    case SyncOpResponse::TSyncGetTagsResponse:
115
      p->MaybeResolve(aResponse.get_SyncGetTagsResponse().mTags());
115
      p->MaybeResolve(aResponse.get_SyncGetTagsResponse().mTags());
116
      return true;
116
      return IPC_OK();
117
    case SyncOpResponse::TSyncOpError:
117
    case SyncOpResponse::TSyncOpError:
118
      p->MaybeReject(
118
      p->MaybeReject(
119
          static_cast<nsresult>(aResponse.get_SyncOpError().mCode()));
119
          static_cast<nsresult>(aResponse.get_SyncOpError().mCode()));
120
      return true;
120
      return IPC_OK();
121
    default:
121
    default:
122
      MOZ_CRASH("Unknown BackgroundSync response");
122
      MOZ_CRASH("Unknown BackgroundSync response");
123
      return false;
123
      return IPC_FAIL(this, "Unknown BackgroundSync response");
124
  }
124
  }
125
}
125
}
126
126
127
} // namespace backgroundsync
127
} // namespace backgroundsync
128
} // namespace dom
128
} // namespace dom
129
} // namespace mozilla
129
} // namespace mozilla
(-)a/dom/backgroundsync/BackgroundSyncChild.h (-2 / +3 lines)
Line     Link Here 
 Lines 34-51   public: Link Here 
34
34
35
  bool IsActorDestroyed() const
35
  bool IsActorDestroyed() const
36
  {
36
  {
37
    return mActorDestroyed;
37
    return mActorDestroyed;
38
  }
38
  }
39
39
40
  nsresult ExecuteOp(Promise* aPromise, SyncOp* aOp);
40
  nsresult ExecuteOp(Promise* aPromise, SyncOp* aOp);
41
41
42
  virtual bool RecvResponse(const nsID& aRequestId,
42
  virtual mozilla::ipc::IPCResult
43
                            const SyncOpResponse& aResponse) override;
43
  RecvResponse(const nsID& aRequestId,
44
               const SyncOpResponse& aResponse) override;
44
45
45
private:
46
private:
46
  BackgroundSyncChild();
47
  BackgroundSyncChild();
47
  ~BackgroundSyncChild();
48
  ~BackgroundSyncChild();
48
49
49
  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
50
  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
50
51
51
  nsresult StorePendingRequest(Promise* aPromise, nsID& aID);
52
  nsresult StorePendingRequest(Promise* aPromise, nsID& aID);
(-)a/dom/backgroundsync/BackgroundSyncParent.cpp (-5 / +7 lines)
Line     Link Here 
 Lines 26-43   BackgroundSyncParent::~BackgroundSyncPar Link Here 
26
  AssertIsOnBackgroundThread();
26
  AssertIsOnBackgroundThread();
27
}
27
}
28
28
29
void BackgroundSyncParent::ActorDestroy(ActorDestroyReason aWhy)
29
void BackgroundSyncParent::ActorDestroy(ActorDestroyReason aWhy)
30
{
30
{
31
  AssertIsOnBackgroundThread();
31
  AssertIsOnBackgroundThread();
32
}
32
}
33
33
34
bool BackgroundSyncParent::RecvRequest(const nsID& aRequestId,
34
mozilla::ipc::IPCResult
35
                                       const SyncOp& aOp)
35
BackgroundSyncParent::RecvRequest(const nsID& aRequestId,
36
                                  const SyncOp& aOp)
36
{
37
{
37
  AssertIsOnBackgroundThread();
38
  AssertIsOnBackgroundThread();
38
39
39
  switch(aOp.mArgs().type()) {
40
  switch(aOp.mArgs().type()) {
40
    case SyncOpArgs::TSyncRegisterArgs:
41
    case SyncOpArgs::TSyncRegisterArgs:
41
    {
42
    {
42
      // XXX Do registration.
43
      // XXX Do registration.
43
      const SyncRegisterResponse response(true);
44
      const SyncRegisterResponse response(true);
 Lines 53-78   bool BackgroundSyncParent::RecvRequest(c Link Here 
53
      Unused << SendResponse(aRequestId, response);
54
      Unused << SendResponse(aRequestId, response);
54
      break;
55
      break;
55
    }
56
    }
56
    default:
57
    default:
57
    {
58
    {
58
      MOZ_CRASH("Unknown BackgroundSync request");
59
      MOZ_CRASH("Unknown BackgroundSync request");
59
    }
60
    }
60
  }
61
  }
61
  return true;
62
  return IPC_OK();
62
}
63
}
63
64
64
bool BackgroundSyncParent::RecvShutdown()
65
mozilla::ipc::IPCResult
66
BackgroundSyncParent::RecvShutdown()
65
{
67
{
66
  AssertIsOnBackgroundThread();
68
  AssertIsOnBackgroundThread();
67
69
68
  Unused << Send__delete__(this);
70
  Unused << Send__delete__(this);
69
71
70
  return true;
72
  return IPC_OK();
71
}
73
}
72
74
73
void
75
void
74
BackgroundSyncParent::NotifyResponse(const nsID& aRequestId,
76
BackgroundSyncParent::NotifyResponse(const nsID& aRequestId,
75
                                     const SyncOpResponse& aResponse)
77
                                     const SyncOpResponse& aResponse)
76
{
78
{
77
  AssertIsOnBackgroundThread();
79
  AssertIsOnBackgroundThread();
78
80
(-)a/dom/backgroundsync/BackgroundSyncParent.h (-3 / +4 lines)
Line     Link Here 
 Lines 21-40   namespace ipc { Link Here 
21
namespace dom {
21
namespace dom {
22
namespace backgroundsync {
22
namespace backgroundsync {
23
23
24
class BackgroundSyncParent final : public PBackgroundSyncParent
24
class BackgroundSyncParent final : public PBackgroundSyncParent
25
{
25
{
26
  friend class mozilla::ipc::BackgroundParentImpl;
26
  friend class mozilla::ipc::BackgroundParentImpl;
27
27
28
public:
28
public:
29
  virtual bool RecvRequest(const nsID& aRequestId,
29
  virtual mozilla::ipc::IPCResult
30
                           const SyncOp& aOp) override;
30
  RecvRequest(const nsID& aRequestId, const SyncOp& aOp) override;
31
31
32
  virtual bool RecvShutdown() override;
32
  virtual mozilla::ipc::IPCResult
33
  RecvShutdown() override;
33
34
34
  void NotifyResponse(const nsID& aRequestId,
35
  void NotifyResponse(const nsID& aRequestId,
35
                      const SyncOpResponse& aResponse);
36
                      const SyncOpResponse& aResponse);
36
37
37
private:
38
private:
38
  BackgroundSyncParent();
39
  BackgroundSyncParent();
39
  ~BackgroundSyncParent();
40
  ~BackgroundSyncParent();
40
41

Return to bug 1217544