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
9 #include "mozilla/Maybe.h"
10 #include "mozilla/dom/ServiceWorkerDescriptor.h"
11 #include "mozilla/UniquePtr.h"
21 class IPCServiceWorkerRegistrationDescriptor
;
22 class ServiceWorkerInfo
;
23 enum class ServiceWorkerUpdateViaCache
: uint8_t;
25 // This class represents a snapshot of a particular
26 // ServiceWorkerRegistrationInfo object. It is threadsafe and can be
27 // transferred across processes.
28 class ServiceWorkerRegistrationDescriptor final
{
29 // This class is largely a wrapper wround an IPDL generated struct. We
30 // need the wrapper class since IPDL generated code includes windows.h
31 // which is in turn incompatible with bindings code.
32 UniquePtr
<IPCServiceWorkerRegistrationDescriptor
> mData
;
34 Maybe
<IPCServiceWorkerDescriptor
> NewestInternal() const;
37 ServiceWorkerRegistrationDescriptor(
38 uint64_t aId
, uint64_t aVersion
, nsIPrincipal
* aPrincipal
,
39 const nsACString
& aScope
, ServiceWorkerUpdateViaCache aUpdateViaCache
);
41 ServiceWorkerRegistrationDescriptor(
42 uint64_t aId
, uint64_t aVersion
,
43 const mozilla::ipc::PrincipalInfo
& aPrincipalInfo
,
44 const nsACString
& aScope
, ServiceWorkerUpdateViaCache aUpdateViaCache
);
46 explicit ServiceWorkerRegistrationDescriptor(
47 const IPCServiceWorkerRegistrationDescriptor
& aDescriptor
);
49 ServiceWorkerRegistrationDescriptor(
50 const ServiceWorkerRegistrationDescriptor
& aRight
);
52 ServiceWorkerRegistrationDescriptor
& operator=(
53 const ServiceWorkerRegistrationDescriptor
& aRight
);
55 ServiceWorkerRegistrationDescriptor(
56 ServiceWorkerRegistrationDescriptor
&& aRight
);
58 ServiceWorkerRegistrationDescriptor
& operator=(
59 ServiceWorkerRegistrationDescriptor
&& aRight
);
61 ~ServiceWorkerRegistrationDescriptor();
63 bool operator==(const ServiceWorkerRegistrationDescriptor
& aRight
) const;
67 uint64_t Version() const;
69 ServiceWorkerUpdateViaCache
UpdateViaCache() const;
71 const mozilla::ipc::PrincipalInfo
& PrincipalInfo() const;
73 Result
<nsCOMPtr
<nsIPrincipal
>, nsresult
> GetPrincipal() const;
75 const nsCString
& Scope() const;
77 Maybe
<ServiceWorkerDescriptor
> GetInstalling() const;
79 Maybe
<ServiceWorkerDescriptor
> GetWaiting() const;
81 Maybe
<ServiceWorkerDescriptor
> GetActive() const;
83 Maybe
<ServiceWorkerDescriptor
> Newest() const;
85 bool HasWorker(const ServiceWorkerDescriptor
& aDescriptor
) const;
89 void SetUpdateViaCache(ServiceWorkerUpdateViaCache aUpdateViaCache
);
91 void SetWorkers(ServiceWorkerInfo
* aInstalling
, ServiceWorkerInfo
* aWaiting
,
92 ServiceWorkerInfo
* aActive
);
94 void SetVersion(uint64_t aVersion
);
96 // Expose the underlying IPC type so that it can be passed via IPC.
97 const IPCServiceWorkerRegistrationDescriptor
& ToIPC() const;
101 } // namespace mozilla
103 #endif // _mozilla_dom_ServiceWorkerRegistrationDescriptor_h