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 #ifndef _mozilla_dom_ServiceWorkerRegistrationDescriptor_h
7 #define _mozilla_dom_ServiceWorkerRegistrationDescriptor_h
8 
9 #include "mozilla/Maybe.h"
10 #include "mozilla/dom/ServiceWorkerDescriptor.h"
11 #include "mozilla/UniquePtr.h"
12 
13 namespace mozilla {
14 
15 namespace ipc {
16 class PrincipalInfo;
17 }  // namespace ipc
18 
19 namespace dom {
20 
21 class IPCServiceWorkerRegistrationDescriptor;
22 class OptionalIPCServiceWorkerDescriptor;
23 class ServiceWorkerInfo;
24 enum class ServiceWorkerUpdateViaCache : uint8_t;
25 
26 // This class represents a snapshot of a particular
27 // ServiceWorkerRegistrationInfo object. It is threadsafe and can be
28 // transferred across processes.
29 class ServiceWorkerRegistrationDescriptor final {
30   // This class is largely a wrapper wround an IPDL generated struct.  We
31   // need the wrapper class since IPDL generated code includes windows.h
32   // which is in turn incompatible with bindings code.
33   UniquePtr<IPCServiceWorkerRegistrationDescriptor> mData;
34 
35   Maybe<IPCServiceWorkerDescriptor> NewestInternal() const;
36 
37  public:
38   ServiceWorkerRegistrationDescriptor(
39       uint64_t aId, nsIPrincipal* aPrincipal, const nsACString& aScope,
40       ServiceWorkerUpdateViaCache aUpdateViaCache);
41 
42   ServiceWorkerRegistrationDescriptor(
43       uint64_t aId, const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
44       const nsACString& aScope, ServiceWorkerUpdateViaCache aUpdateViaCache);
45 
46   explicit ServiceWorkerRegistrationDescriptor(
47       const IPCServiceWorkerRegistrationDescriptor& aDescriptor);
48 
49   ServiceWorkerRegistrationDescriptor(
50       const ServiceWorkerRegistrationDescriptor& aRight);
51 
52   ServiceWorkerRegistrationDescriptor& operator=(
53       const ServiceWorkerRegistrationDescriptor& aRight);
54 
55   ServiceWorkerRegistrationDescriptor(
56       ServiceWorkerRegistrationDescriptor&& aRight);
57 
58   ServiceWorkerRegistrationDescriptor& operator=(
59       ServiceWorkerRegistrationDescriptor&& aRight);
60 
61   ~ServiceWorkerRegistrationDescriptor();
62 
63   bool operator==(const ServiceWorkerRegistrationDescriptor& aRight) const;
64 
65   uint64_t Id() const;
66 
67   ServiceWorkerUpdateViaCache UpdateViaCache() const;
68 
69   const mozilla::ipc::PrincipalInfo& PrincipalInfo() const;
70 
71   const nsCString& Scope() const;
72 
73   Maybe<ServiceWorkerDescriptor> GetInstalling() const;
74 
75   Maybe<ServiceWorkerDescriptor> GetWaiting() const;
76 
77   Maybe<ServiceWorkerDescriptor> GetActive() const;
78 
79   Maybe<ServiceWorkerDescriptor> Newest() const;
80 
81   bool IsValid() const;
82 
83   void SetUpdateViaCache(ServiceWorkerUpdateViaCache aUpdateViaCache);
84 
85   void SetWorkers(ServiceWorkerInfo* aInstalling, ServiceWorkerInfo* aWaiting,
86                   ServiceWorkerInfo* aActive);
87 
88   void SetWorkers(const OptionalIPCServiceWorkerDescriptor& aInstalling,
89                   const OptionalIPCServiceWorkerDescriptor& aWaiting,
90                   const OptionalIPCServiceWorkerDescriptor& aActive);
91 
92   // Expose the underlying IPC type so that it can be passed via IPC.
93   const IPCServiceWorkerRegistrationDescriptor& ToIPC() const;
94 };
95 
96 }  // namespace dom
97 }  // namespace mozilla
98 
99 #endif  // _mozilla_dom_ServiceWorkerRegistrationDescriptor_h
100