/src/mozilla-central/dom/serviceworkers/ServiceWorkerRegistrationParent.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 |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "ServiceWorkerRegistrationParent.h" |
8 | | |
9 | | #include "ServiceWorkerRegistrationProxy.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | using mozilla::ipc::IPCResult; |
15 | | |
16 | | void |
17 | | ServiceWorkerRegistrationParent::ActorDestroy(ActorDestroyReason aReason) |
18 | 0 | { |
19 | 0 | if (mProxy) { |
20 | 0 | mProxy->RevokeActor(this); |
21 | 0 | mProxy = nullptr; |
22 | 0 | } |
23 | 0 | } |
24 | | |
25 | | IPCResult |
26 | | ServiceWorkerRegistrationParent::RecvTeardown() |
27 | 0 | { |
28 | 0 | MaybeSendDelete(); |
29 | 0 | return IPC_OK(); |
30 | 0 | } |
31 | | |
32 | | namespace { |
33 | | |
34 | | void |
35 | | ResolveUnregister(PServiceWorkerRegistrationParent::UnregisterResolver&& aResolver, |
36 | | bool aSuccess, nsresult aRv) |
37 | 0 | { |
38 | 0 | aResolver(Tuple<const bool&, const CopyableErrorResult&>( |
39 | 0 | aSuccess, CopyableErrorResult(aRv))); |
40 | 0 | } |
41 | | |
42 | | } // anonymous namespace |
43 | | |
44 | | IPCResult |
45 | | ServiceWorkerRegistrationParent::RecvUnregister(UnregisterResolver&& aResolver) |
46 | 0 | { |
47 | 0 | if (!mProxy) { |
48 | 0 | ResolveUnregister(std::move(aResolver), false, NS_ERROR_DOM_INVALID_STATE_ERR); |
49 | 0 | return IPC_OK(); |
50 | 0 | } |
51 | 0 |
|
52 | 0 | mProxy->Unregister()->Then(GetCurrentThreadSerialEventTarget(), __func__, |
53 | 0 | [aResolver] (bool aSuccess) mutable { |
54 | 0 | ResolveUnregister(std::move(aResolver), aSuccess, NS_OK); |
55 | 0 | }, [aResolver] (nsresult aRv) mutable { |
56 | 0 | ResolveUnregister(std::move(aResolver), false, aRv); |
57 | 0 | }); |
58 | 0 |
|
59 | 0 | return IPC_OK(); |
60 | 0 | } |
61 | | |
62 | | IPCResult |
63 | | ServiceWorkerRegistrationParent::RecvUpdate(UpdateResolver&& aResolver) |
64 | 0 | { |
65 | 0 | if (!mProxy) { |
66 | 0 | aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR)); |
67 | 0 | return IPC_OK(); |
68 | 0 | } |
69 | 0 |
|
70 | 0 | mProxy->Update()->Then(GetCurrentThreadSerialEventTarget(), __func__, |
71 | 0 | [aResolver] (const ServiceWorkerRegistrationDescriptor& aDescriptor) { |
72 | 0 | aResolver(aDescriptor.ToIPC()); |
73 | 0 | }, [aResolver] (const CopyableErrorResult& aResult) { |
74 | 0 | aResolver(aResult); |
75 | 0 | }); |
76 | 0 |
|
77 | 0 | return IPC_OK(); |
78 | 0 | } |
79 | | |
80 | | ServiceWorkerRegistrationParent::ServiceWorkerRegistrationParent() |
81 | | : mDeleteSent(false) |
82 | 0 | { |
83 | 0 | } |
84 | | |
85 | | ServiceWorkerRegistrationParent::~ServiceWorkerRegistrationParent() |
86 | 0 | { |
87 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mProxy); |
88 | 0 | } |
89 | | |
90 | | void |
91 | | ServiceWorkerRegistrationParent::Init(const IPCServiceWorkerRegistrationDescriptor& aDescriptor) |
92 | 0 | { |
93 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mProxy); |
94 | 0 | mProxy = new ServiceWorkerRegistrationProxy(ServiceWorkerRegistrationDescriptor(aDescriptor)); |
95 | 0 | mProxy->Init(this); |
96 | 0 | } |
97 | | |
98 | | void |
99 | | ServiceWorkerRegistrationParent::MaybeSendDelete() |
100 | 0 | { |
101 | 0 | if (mDeleteSent) { |
102 | 0 | return; |
103 | 0 | } |
104 | 0 | mDeleteSent = true; |
105 | 0 | Unused << Send__delete__(this); |
106 | 0 | } |
107 | | |
108 | | } // namespace dom |
109 | | } // namespace mozilla |