mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 764228: Add Volume event notifications r=qDot
This commit is contained in:
parent
c39841ecfc
commit
16ed5ee6d0
@ -6,6 +6,7 @@
|
||||
#include "VolumeCommand.h"
|
||||
#include "VolumeManager.h"
|
||||
#include "VolumeManagerLog.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace system {
|
||||
@ -20,21 +21,25 @@ Volume::Volume(const nsCSubstring &aName)
|
||||
void
|
||||
Volume::SetState(Volume::STATE aNewState)
|
||||
{
|
||||
if (aNewState != mState) {
|
||||
LOG("Volume %s: changing state from %s to %s",
|
||||
NameStr(), StateStr(mState), StateStr(aNewState));
|
||||
|
||||
mState = aNewState;
|
||||
if (aNewState == mState) {
|
||||
return;
|
||||
}
|
||||
LOG("Volume %s: changing state from %s to %s (%d observers)",
|
||||
NameStr(), StateStr(mState),
|
||||
StateStr(aNewState), mEventObserverList.Length());
|
||||
|
||||
mState = aNewState;
|
||||
mEventObserverList.Broadcast(this);
|
||||
}
|
||||
|
||||
void
|
||||
Volume::SetMountPoint(const nsCSubstring &aMountPoint)
|
||||
{
|
||||
if (!mMountPoint.Equals(aMountPoint)) {
|
||||
mMountPoint = aMountPoint;
|
||||
DBG("Volume %s: Setting mountpoint to '%s'", NameStr(), mMountPoint.get());
|
||||
if (mMountPoint.Equals(aMountPoint)) {
|
||||
return;
|
||||
}
|
||||
mMountPoint = aMountPoint;
|
||||
DBG("Volume %s: Setting mountpoint to '%s'", NameStr(), mMountPoint.get());
|
||||
}
|
||||
|
||||
void
|
||||
@ -67,5 +72,23 @@ Volume::StartCommand(VolumeCommand *aCommand)
|
||||
VolumeManager::PostCommand(aCommand);
|
||||
}
|
||||
|
||||
void
|
||||
Volume::RegisterObserver(Volume::EventObserver *aObserver)
|
||||
{
|
||||
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
||||
|
||||
mEventObserverList.AddObserver(aObserver);
|
||||
// Send an initial event to the observer
|
||||
aObserver->Notify(this);
|
||||
}
|
||||
|
||||
void
|
||||
Volume::UnregisterObserver(Volume::EventObserver *aObserver)
|
||||
{
|
||||
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
||||
|
||||
mEventObserverList.RemoveObserver(aObserver);
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
} // namespace mozilla
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef mozilla_system_volume_h__
|
||||
#define mozilla_system_volume_h__
|
||||
|
||||
#include "mozilla/Observer.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "VolumeCommand.h"
|
||||
@ -67,6 +68,18 @@ public:
|
||||
// (i.e. path that leads to the files stored on the volume).
|
||||
const nsCString &MountPoint() const { return mMountPoint; }
|
||||
|
||||
typedef mozilla::Observer<Volume *> EventObserver;
|
||||
typedef mozilla::ObserverList<Volume *> EventObserverList;
|
||||
|
||||
// NOTE: that observers must live in the IOThread.
|
||||
void RegisterObserver(EventObserver *aObserver);
|
||||
void UnregisterObserver(EventObserver *aObserver);
|
||||
|
||||
private:
|
||||
friend class AutoMounter; // Calls StartXxx
|
||||
friend class VolumeManager; // Calls SetState
|
||||
friend class VolumeListCallback; // Calls SetMountPoint, SetState
|
||||
|
||||
// The StartXxx functions will queue up a command to the VolumeManager.
|
||||
// You can queue up as many commands as you like, and aCallback will
|
||||
// be called as each one completes.
|
||||
@ -75,18 +88,14 @@ public:
|
||||
void StartShare(VolumeResponseCallback *aCallback);
|
||||
void StartUnshare(VolumeResponseCallback *aCallback);
|
||||
|
||||
private:
|
||||
friend class VolumeManager; // Calls SetState
|
||||
friend class VolumeListCallback; // Calls SetMountPoint, SetState
|
||||
|
||||
void SetState(STATE aNewState);
|
||||
void SetMountPoint(const nsCSubstring &aMountPoint);
|
||||
void StartCommand(VolumeCommand *aCommand);
|
||||
|
||||
STATE mState;
|
||||
const nsCString mName;
|
||||
|
||||
nsCString mMountPoint;
|
||||
EventObserverList mEventObserverList;
|
||||
};
|
||||
|
||||
} // system
|
||||
|
@ -445,4 +445,3 @@ ShutdownVolumeManager()
|
||||
|
||||
} // system
|
||||
} // mozilla
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user