diff --git a/hal/Hal.cpp b/hal/Hal.cpp index f3646b3a9b3b..1528da069cb4 100644 --- a/hal/Hal.cpp +++ b/hal/Hal.cpp @@ -76,7 +76,7 @@ StaticAutoPtr gLastIDToVibrate; static void RecordLastIDToVibrate(const WindowIdentifier& aId) { if (!InSandbox()) { - *gLastIDToVibrate = aId.AsArray(); + *gLastIDToVibrate = aId.AsArray().Clone(); } } @@ -107,7 +107,7 @@ void Vibrate(const nsTArray& pattern, nsPIDOMWindowInner* window) { Vibrate(pattern, WindowIdentifier(window)); } -void Vibrate(const nsTArray& pattern, const WindowIdentifier& id) { +void Vibrate(const nsTArray& pattern, WindowIdentifier&& id) { AssertMainThread(); // Only active windows may start vibrations. If |id| hasn't gone @@ -126,21 +126,23 @@ void Vibrate(const nsTArray& 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())); } } diff --git a/hal/Hal.h b/hal/Hal.h index 560b1efc710d..d042658a0483 100644 --- a/hal/Hal.h +++ b/hal/Hal.h @@ -72,8 +72,7 @@ void Shutdown(); * The method with WindowIdentifier will be called automatically. */ void Vibrate(const nsTArray& pattern, nsPIDOMWindowInner* aWindow); -void Vibrate(const nsTArray& pattern, - const hal::WindowIdentifier& id); +void Vibrate(const nsTArray& pattern, hal::WindowIdentifier&& id); /** * Cancel a vibration started by the content window identified by @@ -88,7 +87,7 @@ void Vibrate(const nsTArray& pattern, * automatically. */ void CancelVibrate(nsPIDOMWindowInner* aWindow); -void CancelVibrate(const hal::WindowIdentifier& id); +void CancelVibrate(hal::WindowIdentifier&& id); #define MOZ_DEFINE_HAL_OBSERVER(name_) \ /** \ diff --git a/hal/HalWakeLock.cpp b/hal/HalWakeLock.cpp index efeb7fb8de7c..96c1cf364058 100644 --- a/hal/HalWakeLock.cpp +++ b/hal/HalWakeLock.cpp @@ -23,7 +23,7 @@ struct LockCount { LockCount() : numLocks(0), numHidden(0) {} uint32_t numLocks; uint32_t numHidden; - nsTArray processes; + CopyableTArray processes; }; typedef nsDataHashtable ProcessLockTable; diff --git a/hal/WindowIdentifier.cpp b/hal/WindowIdentifier.cpp index 19a938aaf8ed..dc108016910f 100644 --- a/hal/WindowIdentifier.cpp +++ b/hal/WindowIdentifier.cpp @@ -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& id, +WindowIdentifier::WindowIdentifier(nsTArray&& 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& WindowIdentifier::AsArray() const { MOZ_ASSERT(!mIsEmpty); return mID; diff --git a/hal/WindowIdentifier.h b/hal/WindowIdentifier.h index 34047b804936..11c5140f61b1 100644 --- a/hal/WindowIdentifier.h +++ b/hal/WindowIdentifier.h @@ -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& id, nsPIDOMWindowInner* window); + WindowIdentifier(nsTArray&& id, nsPIDOMWindowInner* window); /** * Get the list of window and process IDs we contain. @@ -100,7 +95,9 @@ class WindowIdentifier { AutoTArray mID; nsCOMPtr mWindow; - bool mIsEmpty; +#ifdef DEBUG + bool mIsEmpty = false; +#endif }; } // namespace hal diff --git a/hal/android/AndroidHal.cpp b/hal/android/AndroidHal.cpp index 16dd4dd57ede..098fc9db5035 100644 --- a/hal/android/AndroidHal.cpp +++ b/hal/android/AndroidHal.cpp @@ -20,7 +20,7 @@ namespace java = mozilla::java; namespace mozilla { namespace hal_impl { -void Vibrate(const nsTArray& pattern, const WindowIdentifier&) { +void Vibrate(const nsTArray& 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& pattern, const WindowIdentifier&) { b->Vibrate(pattern); } -void CancelVibrate(const WindowIdentifier&) { +void CancelVibrate(WindowIdentifier&&) { // Ignore WindowIdentifier parameter. java::GeckoAppShell::CancelVibrate(); diff --git a/hal/fallback/FallbackVibration.cpp b/hal/fallback/FallbackVibration.cpp index 13db8a0a8a5d..f3b0302d03d9 100644 --- a/hal/fallback/FallbackVibration.cpp +++ b/hal/fallback/FallbackVibration.cpp @@ -11,9 +11,9 @@ using mozilla::hal::WindowIdentifier; namespace mozilla { namespace hal_impl { -void Vibrate(const nsTArray& pattern, const hal::WindowIdentifier&) {} +void Vibrate(const nsTArray& pattern, hal::WindowIdentifier&&) {} -void CancelVibrate(const hal::WindowIdentifier&) {} +void CancelVibrate(hal::WindowIdentifier&&) {} } // namespace hal_impl } // namespace mozilla diff --git a/hal/sandbox/SandboxHal.cpp b/hal/sandbox/SandboxHal.cpp index d3b55c123a78..2c82c6cdef24 100644 --- a/hal/sandbox/SandboxHal.cpp +++ b/hal/sandbox/SandboxHal.cpp @@ -36,21 +36,19 @@ static PHalChild* Hal() { return sHal; } -void Vibrate(const nsTArray& pattern, const WindowIdentifier& id) { +void Vibrate(const nsTArray& pattern, WindowIdentifier&& id) { HAL_LOG("Vibrate: Sending to parent process."); - AutoTArray 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 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 window = browserParent->GetBrowserDOMWindow(); */ - WindowIdentifier newID(id, nullptr); - hal::CancelVibrate(newID); + hal::CancelVibrate(WindowIdentifier(std::move(id), nullptr)); return IPC_OK(); }