2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 18:39:55 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
Bug 1463587: Part 3 - Add bindings for SharedMap, and expose it via process message managers. r=erahm,baku,bz
This is the first basic implementation of a shared-memory key-value store for
JS message managers. It has one read-write endpoint in the parent process, and
separate read-only endpoints for each child-process message manager.
Changes to the parent endpoint are broadcast to the children as snapshots.
Each snapshot triggers a "change" event with a list of changed keys.
It currently has the following limitations:
- It only supports basic structured clone data. There's no support for blobs,
input streams, message ports... Blob support will be added in a follow-up
patch.
- Changes are currently only broadcast to child endpoints when flush() is
explicitly called in the parent, or when new child processes are launched.
In a follow-up, this will be changed to automatically flush after changes
when the event loop is idle.
- All set operations clone their inputs synchronously, which means that
there's no trivial way for callers to batch multiple changes to a single key
without some additional effort. It might be useful to add a
delayed-serialization option to the .set() call in a follow-up, for callers
who are sure they know what they're doing.
MozReview-Commit-ID: IM8a3UgejXU
--HG--
extra : rebase_source : 66c92d538a5485349bc789028fdc3a6806bc5d5a
extra : source : 2ebaf5f8c6055b11b11d7ec334d54ee941115d48
2018-06-30 00:55:27 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef dom_ipc_SharedMapChangeEvent_h
|
|
|
|
#define dom_ipc_SharedMapChangeEvent_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/MozSharedMapBinding.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/Event.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
class SharedMapChangeEvent final : public Event {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(SharedMapChangeEvent, Event)
|
|
|
|
|
|
|
|
JSObject* WrapObjectInternal(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override {
|
|
|
|
return MozSharedMapChangeEvent_Binding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<SharedMapChangeEvent> Constructor(
|
|
|
|
EventTarget* aEventTarget, const nsAString& aType,
|
|
|
|
const MozSharedMapChangeEventInit& aInit);
|
|
|
|
|
|
|
|
void GetChangedKeys(nsTArray<nsString>& aChangedKeys) const {
|
|
|
|
aChangedKeys.AppendElements(mChangedKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~SharedMapChangeEvent() override = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit SharedMapChangeEvent(EventTarget* aEventTarget)
|
|
|
|
: Event(aEventTarget, nullptr, nullptr) {}
|
|
|
|
|
|
|
|
nsTArray<nsString> mChangedKeys;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // dom_ipc_SharedMapChangeEvent_h
|