Bug 1494333 - index crons just like artifacts r=Callek
[gecko.git] / dom / serviceworkers / ServiceWorkerDescriptor.h
blob1d4170e014d14d00ea3ae3888cd05b4c0b32205d
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_ServiceWorkerDescriptor_h
7 #define _mozilla_dom_ServiceWorkerDescriptor_h
9 #include "mozilla/UniquePtr.h"
10 #include "nsCOMPtr.h"
11 #include "nsString.h"
13 class nsIPrincipal;
15 namespace mozilla {
17 namespace ipc {
18 class PrincipalInfo;
19 } // namespace ipc
21 namespace dom {
23 class IPCServiceWorkerDescriptor;
24 enum class ServiceWorkerState : uint8_t;
26 // This class represents a snapshot of a particular ServiceWorkerInfo object.
27 // It is threadsafe and can be transferred across processes. This is useful
28 // because most of its values are immutable and can be relied upon to be
29 // accurate. Currently the only variable field is the ServiceWorkerState.
30 class ServiceWorkerDescriptor final
32 // This class is largely a wrapper around an IPDL generated struct. We
33 // need the wrapper class since IPDL generated code includes windows.h
34 // which is in turn incompatible with bindings code.
35 UniquePtr<IPCServiceWorkerDescriptor> mData;
37 public:
38 ServiceWorkerDescriptor(uint64_t aId,
39 uint64_t aRegistrationId,
40 uint64_t aRegistrationVersion,
41 nsIPrincipal* aPrincipal,
42 const nsACString& aScope,
43 const nsACString& aScriptURL,
44 ServiceWorkerState aState);
46 ServiceWorkerDescriptor(uint64_t aId,
47 uint64_t aRegistrationId,
48 uint64_t aRegistrationVersion,
49 const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
50 const nsACString& aScope,
51 const nsACString& aScriptURL,
52 ServiceWorkerState aState);
54 explicit ServiceWorkerDescriptor(const IPCServiceWorkerDescriptor& aDescriptor);
56 ServiceWorkerDescriptor(const ServiceWorkerDescriptor& aRight);
58 ServiceWorkerDescriptor&
59 operator=(const ServiceWorkerDescriptor& aRight);
61 ServiceWorkerDescriptor(ServiceWorkerDescriptor&& aRight);
63 ServiceWorkerDescriptor&
64 operator=(ServiceWorkerDescriptor&& aRight);
66 ~ServiceWorkerDescriptor();
68 bool
69 operator==(const ServiceWorkerDescriptor& aRight) const;
71 uint64_t
72 Id() const;
74 uint64_t
75 RegistrationId() const;
77 uint64_t
78 RegistrationVersion() const;
80 const mozilla::ipc::PrincipalInfo&
81 PrincipalInfo() const;
83 nsCOMPtr<nsIPrincipal>
84 GetPrincipal() const;
86 const nsCString&
87 Scope() const;
89 const nsCString&
90 ScriptURL() const;
92 ServiceWorkerState
93 State() const;
95 void
96 SetState(ServiceWorkerState aState);
98 void
99 SetRegistrationVersion(uint64_t aVersion);
101 // Try to determine if two workers match each other. This is less strict
102 // than an operator==() call since it ignores mutable values like State().
103 bool
104 Matches(const ServiceWorkerDescriptor& aDescriptor) const;
106 // Expose the underlying IPC type so that it can be passed via IPC.
107 const IPCServiceWorkerDescriptor&
108 ToIPC() const;
111 } // namespace dom
112 } // namespace mozilla
114 #endif // _mozilla_dom_ServiceWorkerDescriptor_h