2012-05-25 08:03:07 +04: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 mozilla_system_volume_h__
|
|
|
|
#define mozilla_system_volume_h__
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
#include "VolumeCommand.h"
|
2012-07-16 20:38:18 +04:00
|
|
|
#include "nsIVolume.h"
|
2012-07-16 20:38:18 +04:00
|
|
|
#include "nsString.h"
|
2012-07-16 20:38:18 +04:00
|
|
|
#include "mozilla/Observer.h"
|
2012-05-25 08:03:07 +04:00
|
|
|
#include "mozilla/RefPtr.h"
|
2012-07-16 20:38:18 +04:00
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2012-05-25 08:03:07 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace system {
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* There is an instance of the Volume class for each volume reported
|
|
|
|
* from vold.
|
|
|
|
*
|
|
|
|
* Each volume originates from the /system/etv/vold.fstab file.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
class Volume : public RefCounted<Volume>
|
|
|
|
{
|
|
|
|
public:
|
2014-02-21 18:11:33 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(Volume)
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume(const nsCSubstring& aVolumeName);
|
2012-05-25 08:03:07 +04:00
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
typedef long STATE; // States are now defined in nsIVolume.idl
|
|
|
|
|
2013-01-07 20:43:02 +04:00
|
|
|
static const char* StateStr(STATE aState) { return NS_VolumeStateStr(aState); }
|
|
|
|
const char* StateStr() const { return StateStr(mState); }
|
2012-05-25 08:03:07 +04:00
|
|
|
STATE State() const { return mState; }
|
|
|
|
|
2013-01-07 20:43:02 +04:00
|
|
|
const nsCString& Name() const { return mName; }
|
|
|
|
const char* NameStr() const { return mName.get(); }
|
2012-05-25 08:03:07 +04:00
|
|
|
|
|
|
|
// The mount point is the name of the directory where the volume is mounted.
|
|
|
|
// (i.e. path that leads to the files stored on the volume).
|
2013-01-07 20:43:02 +04:00
|
|
|
const nsCString& MountPoint() const { return mMountPoint; }
|
2012-05-25 08:03:07 +04:00
|
|
|
|
2012-12-15 04:01:34 +04:00
|
|
|
int32_t MountGeneration() const { return mMountGeneration; }
|
|
|
|
bool IsMountLocked() const { return mMountLocked; }
|
|
|
|
bool MediaPresent() const { return mMediaPresent; }
|
2013-05-14 04:53:23 +04:00
|
|
|
bool CanBeShared() const { return mCanBeShared; }
|
2013-09-06 10:11:58 +04:00
|
|
|
bool CanBeFormatted() const { return CanBeShared(); }
|
2013-05-14 04:53:23 +04:00
|
|
|
bool IsSharingEnabled() const { return mCanBeShared && mSharingEnabled; }
|
2013-09-06 10:11:58 +04:00
|
|
|
bool IsFormatRequested() const { return CanBeFormatted() && mFormatRequested; }
|
2013-08-23 03:12:25 +04:00
|
|
|
bool IsSharing() const { return mIsSharing; }
|
2013-09-06 10:11:58 +04:00
|
|
|
bool IsFormatting() const { return mIsFormatting; }
|
2013-05-14 04:53:23 +04:00
|
|
|
|
|
|
|
void SetSharingEnabled(bool aSharingEnabled);
|
2013-09-06 10:11:58 +04:00
|
|
|
void SetFormatRequested(bool aFormatRequested);
|
2012-07-16 20:38:18 +04:00
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
typedef mozilla::Observer<Volume *> EventObserver;
|
|
|
|
typedef mozilla::ObserverList<Volume *> EventObserverList;
|
|
|
|
|
|
|
|
// NOTE: that observers must live in the IOThread.
|
2013-01-07 20:43:02 +04:00
|
|
|
static void RegisterObserver(EventObserver* aObserver);
|
|
|
|
static void UnregisterObserver(EventObserver* aObserver);
|
2012-07-16 20:38:18 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class AutoMounter; // Calls StartXxx
|
2012-12-15 04:01:34 +04:00
|
|
|
friend class nsVolume; // Calls UpdateMountLock
|
2012-07-16 20:38:18 +04:00
|
|
|
friend class VolumeManager; // Calls HandleVoldResponse
|
2012-07-16 20:38:18 +04:00
|
|
|
friend class VolumeListCallback; // Calls SetMountPoint, SetState
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
// 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.
|
2013-01-07 20:43:02 +04:00
|
|
|
void StartMount(VolumeResponseCallback* aCallback);
|
|
|
|
void StartUnmount(VolumeResponseCallback* aCallback);
|
2013-09-06 10:11:58 +04:00
|
|
|
void StartFormat(VolumeResponseCallback* aCallback);
|
2013-01-07 20:43:02 +04:00
|
|
|
void StartShare(VolumeResponseCallback* aCallback);
|
|
|
|
void StartUnshare(VolumeResponseCallback* aCallback);
|
2012-05-25 08:03:07 +04:00
|
|
|
|
2013-08-23 03:12:25 +04:00
|
|
|
void SetIsSharing(bool aIsSharing);
|
2013-09-06 10:11:58 +04:00
|
|
|
void SetIsFormatting(bool aIsFormatting);
|
2012-05-25 08:03:07 +04:00
|
|
|
void SetState(STATE aNewState);
|
2012-07-16 20:38:18 +04:00
|
|
|
void SetMediaPresent(bool aMediaPresent);
|
2013-01-07 20:43:02 +04:00
|
|
|
void SetMountPoint(const nsCSubstring& aMountPoint);
|
|
|
|
void StartCommand(VolumeCommand* aCommand);
|
2012-05-25 08:03:07 +04:00
|
|
|
|
2013-01-07 20:43:02 +04:00
|
|
|
void HandleVoldResponse(int aResponseCode, nsCWhitespaceTokenizer& aTokenizer);
|
2012-12-15 04:01:34 +04:00
|
|
|
|
2013-01-07 20:43:02 +04:00
|
|
|
static void UpdateMountLock(const nsACString& aVolumeName,
|
|
|
|
const int32_t& aMountGeneration,
|
|
|
|
const bool& aMountLocked);
|
2012-12-15 04:01:34 +04:00
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
bool mMediaPresent;
|
2012-05-25 08:03:07 +04:00
|
|
|
STATE mState;
|
|
|
|
const nsCString mName;
|
|
|
|
nsCString mMountPoint;
|
2012-12-15 04:01:34 +04:00
|
|
|
int32_t mMountGeneration;
|
|
|
|
bool mMountLocked;
|
2013-05-14 04:53:23 +04:00
|
|
|
bool mSharingEnabled;
|
2013-09-06 10:11:58 +04:00
|
|
|
bool mFormatRequested;
|
2013-05-14 04:53:23 +04:00
|
|
|
bool mCanBeShared;
|
2013-08-23 03:12:25 +04:00
|
|
|
bool mIsSharing;
|
2013-09-06 10:11:58 +04:00
|
|
|
bool mIsFormatting;
|
2012-07-16 20:38:18 +04:00
|
|
|
|
|
|
|
static EventObserverList mEventObserverList;
|
2012-05-25 08:03:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // system
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_system_volumemanager_h__
|