From a7e4a46c0b0b164cd007b9d79602f48dd4f9eb21 Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Mon, 7 Jan 2013 17:43:02 +0100 Subject: [PATCH] Bug 785124 - Pt 5 - Add extra asserts. r=dougt --- dom/system/gonk/Volume.cpp | 32 ++++++++++++++++++++++ dom/system/gonk/nsVolume.cpp | 11 ++++++++ toolkit/mozapps/update/updater/updater.cpp | 3 +- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/dom/system/gonk/Volume.cpp b/dom/system/gonk/Volume.cpp index d5976c90680..cca366aabea 100644 --- a/dom/system/gonk/Volume.cpp +++ b/dom/system/gonk/Volume.cpp @@ -65,6 +65,9 @@ Volume::Volume(const nsCSubstring& aName) void Volume::SetMediaPresent(bool aMediaPresent) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + // mMediaPresent is slightly redunant to the state, however // when media is removed (while Idle), we get the following: // 631 Volume sdcard /mnt/sdcard disk removed (179:0) @@ -100,6 +103,9 @@ Volume::SetMediaPresent(bool aMediaPresent) void Volume::SetState(Volume::STATE aNewState) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + if (aNewState == mState) { return; } @@ -127,6 +133,9 @@ Volume::SetState(Volume::STATE aNewState) void Volume::SetMountPoint(const nsCSubstring& aMountPoint) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + if (mMountPoint.Equals(aMountPoint)) { return; } @@ -137,30 +146,45 @@ Volume::SetMountPoint(const nsCSubstring& aMountPoint) void Volume::StartMount(VolumeResponseCallback* aCallback) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + StartCommand(new VolumeActionCommand(this, "mount", "", aCallback)); } void Volume::StartUnmount(VolumeResponseCallback* aCallback) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + StartCommand(new VolumeActionCommand(this, "unmount", "force", aCallback)); } void Volume::StartShare(VolumeResponseCallback* aCallback) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + StartCommand(new VolumeActionCommand(this, "share", "ums", aCallback)); } void Volume::StartUnshare(VolumeResponseCallback* aCallback) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + StartCommand(new VolumeActionCommand(this, "unshare", "ums", aCallback)); } void Volume::StartCommand(VolumeCommand* aCommand) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + VolumeManager::PostCommand(aCommand); } @@ -168,6 +192,7 @@ Volume::StartCommand(VolumeCommand* aCommand) void Volume::RegisterObserver(Volume::EventObserver* aObserver) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); mEventObserverList.AddObserver(aObserver); @@ -183,6 +208,7 @@ Volume::RegisterObserver(Volume::EventObserver* aObserver) void Volume::UnregisterObserver(Volume::EventObserver* aObserver) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); mEventObserverList.RemoveObserver(aObserver); @@ -194,6 +220,9 @@ Volume::UpdateMountLock(const nsACString& aVolumeName, const int32_t& aMountGeneration, const bool& aMountLocked) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + RefPtr vol = VolumeManager::FindVolumeByName(aVolumeName); if (!vol || (vol->mMountGeneration != aMountGeneration)) { return; @@ -208,6 +237,9 @@ Volume::UpdateMountLock(const nsACString& aVolumeName, void Volume::HandleVoldResponse(int aResponseCode, nsCWhitespaceTokenizer& aTokenizer) { + MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); + MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); + // The volume name will have already been parsed, and the tokenizer will point // to the token after the volume name switch (aResponseCode) { diff --git a/dom/system/gonk/nsVolume.cpp b/dom/system/gonk/nsVolume.cpp index ec9938920f4..a0eeefda9ec 100644 --- a/dom/system/gonk/nsVolume.cpp +++ b/dom/system/gonk/nsVolume.cpp @@ -38,6 +38,11 @@ NS_VolumeStateStr(int32_t aState) return "???"; } +// While nsVolumes can only be used on the main thread, in the +// UpdateVolumeRunnable constructor (which is called from IOThread) we +// allocate an nsVolume which is then passed to MainThread. Since we +// have a situation where we allocate on one thread and free on another +// we use a thread safe AddRef implementation. NS_IMPL_THREADSAFE_ISUPPORTS1(nsVolume, nsIVolume) nsVolume::nsVolume(const Volume* aVolume) @@ -106,6 +111,8 @@ nsVolume::LogState() const void nsVolume::Set(const nsVolume* aVolume) { + MOZ_ASSERT(NS_IsMainThread()); + mName = aVolume->mName; mMountPoint = aVolume->mMountPoint; mState = aVolume->mState; @@ -139,6 +146,8 @@ void nsVolume::Set(const nsVolume* aVolume) void nsVolume::UpdateMountLock(const nsAString& aMountLockState) { + MOZ_ASSERT(NS_IsMainThread()); + // There are 3 states, unlocked, locked-background, and locked-foreground // I figured it was easier to use negtive logic and compare for unlocked. UpdateMountLock(!aMountLockState.EqualsLiteral("unlocked")); @@ -147,6 +156,8 @@ nsVolume::UpdateMountLock(const nsAString& aMountLockState) void nsVolume::UpdateMountLock(bool aMountLocked) { + MOZ_ASSERT(NS_IsMainThread()); + if (aMountLocked == mMountLocked) { return; } diff --git a/toolkit/mozapps/update/updater/updater.cpp b/toolkit/mozapps/update/updater/updater.cpp index 3c12874cf8a..b1b0630ca03 100644 --- a/toolkit/mozapps/update/updater/updater.cpp +++ b/toolkit/mozapps/update/updater/updater.cpp @@ -2088,8 +2088,7 @@ ReadMARChannelIDs(const NS_tchar *path, MARChannelStringTable *results) static int GetUpdateFileName(NS_tchar *fileName, int maxChars) { -#if defined(MOZ_WIDGET_GONK) - // If an update.link file exists, then it will contain the name +#if defined(MOZ_WIDGET_GONK) // If an update.link file exists, then it will contain the name // of the update file (terminated by a newline). NS_tchar linkFileName[MAXPATHLEN];