Bug 1626570 - Improve handling of copying arrays in hal/. r=gsvelto
Differential Revision: https://phabricator.services.mozilla.com/D73637
This commit is contained in:
12
hal/Hal.cpp
12
hal/Hal.cpp
@@ -76,7 +76,7 @@ StaticAutoPtr<WindowIdentifier::IDArrayType> gLastIDToVibrate;
|
||||
|
||||
static void RecordLastIDToVibrate(const WindowIdentifier& aId) {
|
||||
if (!InSandbox()) {
|
||||
*gLastIDToVibrate = aId.AsArray();
|
||||
*gLastIDToVibrate = aId.AsArray().Clone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ void Vibrate(const nsTArray<uint32_t>& pattern, nsPIDOMWindowInner* window) {
|
||||
Vibrate(pattern, WindowIdentifier(window));
|
||||
}
|
||||
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier& id) {
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, WindowIdentifier&& id) {
|
||||
AssertMainThread();
|
||||
|
||||
// Only active windows may start vibrations. If |id| hasn't gone
|
||||
@@ -126,21 +126,23 @@ void Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier& id) {
|
||||
// Don't forward our ID if we are not in the sandbox, because hal_impl
|
||||
// doesn't need it, and we don't want it to be tempted to read it. The
|
||||
// empty identifier will assert if it's used.
|
||||
PROXY_IF_SANDBOXED(Vibrate(pattern, InSandbox() ? id : WindowIdentifier()));
|
||||
PROXY_IF_SANDBOXED(
|
||||
Vibrate(pattern, InSandbox() ? std::move(id) : WindowIdentifier()));
|
||||
}
|
||||
|
||||
void CancelVibrate(nsPIDOMWindowInner* window) {
|
||||
CancelVibrate(WindowIdentifier(window));
|
||||
}
|
||||
|
||||
void CancelVibrate(const WindowIdentifier& id) {
|
||||
void CancelVibrate(WindowIdentifier&& id) {
|
||||
AssertMainThread();
|
||||
|
||||
if (MayCancelVibration(id)) {
|
||||
// Don't forward our ID if we are not in the sandbox, because hal_impl
|
||||
// doesn't need it, and we don't want it to be tempted to read it. The
|
||||
// empty identifier will assert if it's used.
|
||||
PROXY_IF_SANDBOXED(CancelVibrate(InSandbox() ? id : WindowIdentifier()));
|
||||
PROXY_IF_SANDBOXED(
|
||||
CancelVibrate(InSandbox() ? std::move(id) : WindowIdentifier()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,8 +72,7 @@ void Shutdown();
|
||||
* The method with WindowIdentifier will be called automatically.
|
||||
*/
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, nsPIDOMWindowInner* aWindow);
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern,
|
||||
const hal::WindowIdentifier& id);
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, hal::WindowIdentifier&& id);
|
||||
|
||||
/**
|
||||
* Cancel a vibration started by the content window identified by
|
||||
@@ -88,7 +87,7 @@ void Vibrate(const nsTArray<uint32_t>& pattern,
|
||||
* automatically.
|
||||
*/
|
||||
void CancelVibrate(nsPIDOMWindowInner* aWindow);
|
||||
void CancelVibrate(const hal::WindowIdentifier& id);
|
||||
void CancelVibrate(hal::WindowIdentifier&& id);
|
||||
|
||||
#define MOZ_DEFINE_HAL_OBSERVER(name_) \
|
||||
/** \
|
||||
|
||||
@@ -23,7 +23,7 @@ struct LockCount {
|
||||
LockCount() : numLocks(0), numHidden(0) {}
|
||||
uint32_t numLocks;
|
||||
uint32_t numHidden;
|
||||
nsTArray<uint64_t> processes;
|
||||
CopyableTArray<uint64_t> processes;
|
||||
};
|
||||
|
||||
typedef nsDataHashtable<nsUint64HashKey, LockCount> ProcessLockTable;
|
||||
|
||||
@@ -12,22 +12,26 @@
|
||||
namespace mozilla {
|
||||
namespace hal {
|
||||
|
||||
WindowIdentifier::WindowIdentifier() : mWindow(nullptr), mIsEmpty(true) {}
|
||||
WindowIdentifier::WindowIdentifier()
|
||||
: mWindow(nullptr)
|
||||
#ifdef DEBUG
|
||||
,
|
||||
mIsEmpty(true)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
WindowIdentifier::WindowIdentifier(nsPIDOMWindowInner* window)
|
||||
: mWindow(window), mIsEmpty(false) {
|
||||
: mWindow(window) {
|
||||
mID.AppendElement(GetWindowID());
|
||||
}
|
||||
|
||||
WindowIdentifier::WindowIdentifier(const nsTArray<uint64_t>& id,
|
||||
WindowIdentifier::WindowIdentifier(nsTArray<uint64_t>&& id,
|
||||
nsPIDOMWindowInner* window)
|
||||
: mID(id), mWindow(window), mIsEmpty(false) {
|
||||
: mID(std::move(id)), mWindow(window) {
|
||||
mID.AppendElement(GetWindowID());
|
||||
}
|
||||
|
||||
WindowIdentifier::WindowIdentifier(const WindowIdentifier& other)
|
||||
: mID(other.mID), mWindow(other.mWindow), mIsEmpty(other.mIsEmpty) {}
|
||||
|
||||
const nsTArray<uint64_t>& WindowIdentifier::AsArray() const {
|
||||
MOZ_ASSERT(!mIsEmpty);
|
||||
return mID;
|
||||
|
||||
@@ -46,11 +46,6 @@ class WindowIdentifier {
|
||||
*/
|
||||
WindowIdentifier();
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
WindowIdentifier(const WindowIdentifier& other);
|
||||
|
||||
/**
|
||||
* Wrap the given window in a WindowIdentifier. These two
|
||||
* constructors automatically grab the window's ID and append it to
|
||||
@@ -66,7 +61,7 @@ class WindowIdentifier {
|
||||
* This automatically grabs the window's ID and appends it to the
|
||||
* array.
|
||||
*/
|
||||
WindowIdentifier(const nsTArray<uint64_t>& id, nsPIDOMWindowInner* window);
|
||||
WindowIdentifier(nsTArray<uint64_t>&& id, nsPIDOMWindowInner* window);
|
||||
|
||||
/**
|
||||
* Get the list of window and process IDs we contain.
|
||||
@@ -100,7 +95,9 @@ class WindowIdentifier {
|
||||
|
||||
AutoTArray<uint64_t, 3> mID;
|
||||
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
||||
bool mIsEmpty;
|
||||
#ifdef DEBUG
|
||||
bool mIsEmpty = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace hal
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace java = mozilla::java;
|
||||
namespace mozilla {
|
||||
namespace hal_impl {
|
||||
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier&) {
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, WindowIdentifier&&) {
|
||||
// Ignore the WindowIdentifier parameter; it's here only because hal::Vibrate,
|
||||
// hal_sandbox::Vibrate, and hal_impl::Vibrate all must have the same
|
||||
// signature.
|
||||
@@ -49,7 +49,7 @@ void Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier&) {
|
||||
b->Vibrate(pattern);
|
||||
}
|
||||
|
||||
void CancelVibrate(const WindowIdentifier&) {
|
||||
void CancelVibrate(WindowIdentifier&&) {
|
||||
// Ignore WindowIdentifier parameter.
|
||||
|
||||
java::GeckoAppShell::CancelVibrate();
|
||||
|
||||
@@ -11,9 +11,9 @@ using mozilla::hal::WindowIdentifier;
|
||||
namespace mozilla {
|
||||
namespace hal_impl {
|
||||
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, const hal::WindowIdentifier&) {}
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, hal::WindowIdentifier&&) {}
|
||||
|
||||
void CancelVibrate(const hal::WindowIdentifier&) {}
|
||||
void CancelVibrate(hal::WindowIdentifier&&) {}
|
||||
|
||||
} // namespace hal_impl
|
||||
} // namespace mozilla
|
||||
|
||||
@@ -36,21 +36,19 @@ static PHalChild* Hal() {
|
||||
return sHal;
|
||||
}
|
||||
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier& id) {
|
||||
void Vibrate(const nsTArray<uint32_t>& pattern, WindowIdentifier&& id) {
|
||||
HAL_LOG("Vibrate: Sending to parent process.");
|
||||
|
||||
AutoTArray<uint32_t, 8> p(pattern);
|
||||
|
||||
WindowIdentifier newID(id);
|
||||
WindowIdentifier newID(std::move(id));
|
||||
newID.AppendProcessID();
|
||||
Hal()->SendVibrate(p, newID.AsArray(),
|
||||
Hal()->SendVibrate(pattern, newID.AsArray(),
|
||||
BrowserChild::GetFrom(newID.GetWindow()));
|
||||
}
|
||||
|
||||
void CancelVibrate(const WindowIdentifier& id) {
|
||||
void CancelVibrate(WindowIdentifier&& id) {
|
||||
HAL_LOG("CancelVibrate: Sending to parent process.");
|
||||
|
||||
WindowIdentifier newID(id);
|
||||
WindowIdentifier newID(std::move(id));
|
||||
newID.AppendProcessID();
|
||||
Hal()->SendCancelVibrate(newID.AsArray(),
|
||||
BrowserChild::GetFrom(newID.GetWindow()));
|
||||
@@ -166,8 +164,7 @@ class HalParent : public PHalParent,
|
||||
nsCOMPtr<nsIDOMWindow> window =
|
||||
do_QueryInterface(browserParent->GetBrowserDOMWindow());
|
||||
*/
|
||||
WindowIdentifier newID(id, nullptr);
|
||||
hal::Vibrate(pattern, newID);
|
||||
hal::Vibrate(pattern, WindowIdentifier(std::move(id), nullptr));
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
@@ -178,8 +175,7 @@ class HalParent : public PHalParent,
|
||||
nsCOMPtr<nsIDOMWindow> window =
|
||||
browserParent->GetBrowserDOMWindow();
|
||||
*/
|
||||
WindowIdentifier newID(id, nullptr);
|
||||
hal::CancelVibrate(newID);
|
||||
hal::CancelVibrate(WindowIdentifier(std::move(id), nullptr));
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user