Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / serviceworkers / ServiceWorkerCloneData.h
blobb29b43414bfc7033f7ed71e1bff68a64cd39ef96
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/. */
7 #ifndef mozilla_dom_ServiceWorkerCloneData_h__
8 #define mozilla_dom_ServiceWorkerCloneData_h__
10 #include "mozilla/Assertions.h"
11 #include "mozilla/dom/DOMTypes.h"
12 #include "mozilla/dom/ipc/StructuredCloneData.h"
13 #include "nsCOMPtr.h"
14 #include "nsISupports.h"
16 class nsISerialEventTarget;
18 namespace mozilla {
19 namespace ipc {
20 class PBackgroundChild;
21 class PBackgroundParent;
22 } // namespace ipc
24 namespace dom {
26 class ClonedOrErrorMessageData;
28 // Helper class used to pack structured clone data so that it can be
29 // passed across thread and process boundaries. Currently the raw
30 // StructuredCloneData and StructureCloneHolder APIs both make it
31 // difficult to meet this needs directly. This helper class improves
32 // the situation by:
34 // 1. Provides a ref-counted version of StructuredCloneData. We need
35 // StructuredCloneData so we can serialize/deserialize across IPC.
36 // The move constructor problems in StructuredCloneData (bug 1462676),
37 // though, makes it hard to pass it around. Passing a ref-counted
38 // pointer addresses this problem.
39 // 2. Normally StructuredCloneData runs into problems if you try to move
40 // it across thread boundaries because it releases its SharedJSAllocatedData
41 // on the wrong thread. This helper will correctly proxy release the
42 // shared data on the correct thread.
44 // This helper class should really just be used to serialize on one thread
45 // and then move the reference across thread/process boundries to the
46 // target worker thread. This class is not intended to support simultaneous
47 // read/write operations from different threads at the same time.
48 class ServiceWorkerCloneData final : public ipc::StructuredCloneData {
49 nsCOMPtr<nsISerialEventTarget> mEventTarget;
50 bool mIsErrorMessageData;
52 ~ServiceWorkerCloneData();
54 public:
55 ServiceWorkerCloneData();
57 bool BuildClonedMessageData(ClonedOrErrorMessageData& aClonedData);
59 void CopyFromClonedMessageData(const ClonedOrErrorMessageData& aClonedData);
61 void SetAsErrorMessageData();
63 bool IsErrorMessageData() const;
65 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerCloneData)
68 } // namespace dom
69 } // namespace mozilla
71 #endif // mozilla_dom_ServiceWorkerCloneData_h__