Source code

Revision control

Other Tools

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
#ifndef mozilla_dom_ServiceWorkerCloneData_h__
8
#define mozilla_dom_ServiceWorkerCloneData_h__
9
10
#include "mozilla/dom/ipc/StructuredCloneData.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
// Helper class used to pack structured clone data so that it can be
16
// passed across thread and process boundaries. Currently the raw
17
// StructuredCloneData and StructureCloneHolder APIs both make it
18
// difficult to meet this needs directly. This helper class improves
19
// the situation by:
20
//
21
// 1. Provides a ref-counted version of StructuredCloneData. We need
22
// StructuredCloneData so we can serialize/deserialize across IPC.
23
// The move constructor problems in StructuredCloneData (bug 1462676),
24
// though, makes it hard to pass it around. Passing a ref-counted
25
// pointer addresses this problem.
26
// 2. Normally StructuredCloneData runs into problems if you try to move
27
// it across thread boundaries because it releases its SharedJSAllocatedData
28
// on the wrong thread. This helper will correctly proxy release the
29
// shared data on the correct thread.
30
//
31
// This helper class should really just be used to serialize on one thread
32
// and then move the reference across thread/process boundries to the
33
// target worker thread. This class is not intended to support simultaneous
34
// read/write operations from different threads at the same time.
35
class ServiceWorkerCloneData final : public ipc::StructuredCloneData {
36
nsCOMPtr<nsISerialEventTarget> mEventTarget;
37
38
~ServiceWorkerCloneData();
39
40
public:
41
ServiceWorkerCloneData();
42
43
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerCloneData)
44
};
45
46
} // namespace dom
47
} // namespace mozilla
48
49
#endif // mozilla_dom_ServiceWorkerCloneData_h__