dom/system/gonk/Volume.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef mozilla_system_volume_h__
     6 #define mozilla_system_volume_h__
     8 #include "VolumeCommand.h"
     9 #include "nsIVolume.h"
    10 #include "nsString.h"
    11 #include "mozilla/Observer.h"
    12 #include "nsISupportsImpl.h"
    13 #include "nsWhitespaceTokenizer.h"
    15 namespace mozilla {
    16 namespace system {
    18 /***************************************************************************
    19 *
    20 *   There is an instance of the Volume class for each volume reported
    21 *   from vold.
    22 *
    23 *   Each volume originates from the /system/etv/vold.fstab file.
    24 *
    25 ***************************************************************************/
    27 class Volume MOZ_FINAL
    28 {
    29 public:
    30   NS_INLINE_DECL_REFCOUNTING(Volume)
    32   Volume(const nsCSubstring& aVolumeName);
    34   typedef long STATE; // States are now defined in nsIVolume.idl
    36   static const char* StateStr(STATE aState) { return NS_VolumeStateStr(aState); }
    37   const char* StateStr() const  { return StateStr(mState); }
    38   STATE State() const           { return mState; }
    40   const nsCString& Name() const { return mName; }
    41   const char* NameStr() const   { return mName.get(); }
    43   // The mount point is the name of the directory where the volume is mounted.
    44   // (i.e. path that leads to the files stored on the volume).
    45   const nsCString& MountPoint() const { return mMountPoint; }
    47   int32_t MountGeneration() const     { return mMountGeneration; }
    48   bool IsMountLocked() const          { return mMountLocked; }
    49   bool MediaPresent() const           { return mMediaPresent; }
    50   bool CanBeShared() const            { return mCanBeShared; }
    51   bool CanBeFormatted() const         { return CanBeShared(); }
    52   bool CanBeMounted() const           { return CanBeShared(); }
    53   bool IsSharingEnabled() const       { return mCanBeShared && mSharingEnabled; }
    54   bool IsFormatRequested() const      { return CanBeFormatted() && mFormatRequested; }
    55   bool IsMountRequested() const       { return CanBeMounted() && mMountRequested; }
    56   bool IsUnmountRequested() const     { return CanBeMounted() && mUnmountRequested; }
    57   bool IsSharing() const              { return mIsSharing; }
    58   bool IsFormatting() const           { return mIsFormatting; }
    60   void SetSharingEnabled(bool aSharingEnabled);
    61   void SetFormatRequested(bool aFormatRequested);
    62   void SetMountRequested(bool aMountRequested);
    63   void SetUnmountRequested(bool aUnmountRequested);
    65   typedef mozilla::Observer<Volume *>     EventObserver;
    66   typedef mozilla::ObserverList<Volume *> EventObserverList;
    68   // NOTE: that observers must live in the IOThread.
    69   static void RegisterObserver(EventObserver* aObserver);
    70   static void UnregisterObserver(EventObserver* aObserver);
    72 private:
    73   friend class AutoMounter;         // Calls StartXxx
    74   friend class nsVolume;            // Calls UpdateMountLock
    75   friend class VolumeManager;       // Calls HandleVoldResponse
    76   friend class VolumeListCallback;  // Calls SetMountPoint, SetState
    78   // The StartXxx functions will queue up a command to the VolumeManager.
    79   // You can queue up as many commands as you like, and aCallback will
    80   // be called as each one completes.
    81   void StartMount(VolumeResponseCallback* aCallback);
    82   void StartUnmount(VolumeResponseCallback* aCallback);
    83   void StartFormat(VolumeResponseCallback* aCallback);
    84   void StartShare(VolumeResponseCallback* aCallback);
    85   void StartUnshare(VolumeResponseCallback* aCallback);
    87   void SetIsSharing(bool aIsSharing);
    88   void SetIsFormatting(bool aIsFormatting);
    89   void SetState(STATE aNewState);
    90   void SetMediaPresent(bool aMediaPresent);
    91   void SetMountPoint(const nsCSubstring& aMountPoint);
    92   void StartCommand(VolumeCommand* aCommand);
    94   void HandleVoldResponse(int aResponseCode, nsCWhitespaceTokenizer& aTokenizer);
    96   static void UpdateMountLock(const nsACString& aVolumeName,
    97                               const int32_t& aMountGeneration,
    98                               const bool& aMountLocked);
   100   bool              mMediaPresent;
   101   STATE             mState;
   102   const nsCString   mName;
   103   nsCString         mMountPoint;
   104   int32_t           mMountGeneration;
   105   bool              mMountLocked;
   106   bool              mSharingEnabled;
   107   bool              mFormatRequested;
   108   bool              mMountRequested;
   109   bool              mUnmountRequested;
   110   bool              mCanBeShared;
   111   bool              mIsSharing;
   112   bool              mIsFormatting;
   114   static EventObserverList mEventObserverList;
   115 };
   117 } // system
   118 } // mozilla
   120 #endif  // mozilla_system_volumemanager_h__

mercurial