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