|
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/. */ |
|
4 |
|
5 #ifndef mozilla_system_nsvolume_h__ |
|
6 #define mozilla_system_nsvolume_h__ |
|
7 |
|
8 #include "nsCOMPtr.h" |
|
9 #include "nsIVolume.h" |
|
10 #include "nsString.h" |
|
11 #include "nsTArray.h" |
|
12 |
|
13 namespace mozilla { |
|
14 namespace system { |
|
15 |
|
16 class Volume; |
|
17 class VolumeMountLock; |
|
18 |
|
19 class nsVolume : public nsIVolume |
|
20 { |
|
21 public: |
|
22 NS_DECL_THREADSAFE_ISUPPORTS |
|
23 NS_DECL_NSIVOLUME |
|
24 |
|
25 // This constructor is used by the UpdateVolumeRunnable constructor |
|
26 nsVolume(const Volume* aVolume); |
|
27 |
|
28 // This constructor is used by ContentChild::RecvFileSystemUpdate which is |
|
29 // used to update the volume cache maintained in the child process. |
|
30 nsVolume(const nsAString& aName, const nsAString& aMountPoint, |
|
31 const int32_t& aState, const int32_t& aMountGeneration, |
|
32 const bool& aIsMediaPresent, const bool& aIsSharing, |
|
33 const bool& aIsFormatting) |
|
34 : mName(aName), |
|
35 mMountPoint(aMountPoint), |
|
36 mState(aState), |
|
37 mMountGeneration(aMountGeneration), |
|
38 mMountLocked(false), |
|
39 mIsFake(false), |
|
40 mIsMediaPresent(aIsMediaPresent), |
|
41 mIsSharing(aIsSharing), |
|
42 mIsFormatting(aIsFormatting) |
|
43 { |
|
44 } |
|
45 |
|
46 // This constructor is used by nsVolumeService::FindAddVolumeByName, and |
|
47 // will be followed shortly by a Set call. |
|
48 nsVolume(const nsAString& aName) |
|
49 : mName(aName), |
|
50 mState(STATE_INIT), |
|
51 mMountGeneration(-1), |
|
52 mMountLocked(true), // Needs to agree with Volume::Volume |
|
53 mIsFake(false), |
|
54 mIsMediaPresent(false), |
|
55 mIsSharing(false), |
|
56 mIsFormatting(false) |
|
57 { |
|
58 } |
|
59 |
|
60 bool Equals(nsIVolume* aVolume); |
|
61 void Set(nsIVolume* aVolume); |
|
62 |
|
63 void LogState() const; |
|
64 |
|
65 const nsString& Name() const { return mName; } |
|
66 nsCString NameStr() const { return NS_LossyConvertUTF16toASCII(mName); } |
|
67 |
|
68 int32_t MountGeneration() const { return mMountGeneration; } |
|
69 bool IsMountLocked() const { return mMountLocked; } |
|
70 |
|
71 const nsString& MountPoint() const { return mMountPoint; } |
|
72 nsCString MountPointStr() const { return NS_LossyConvertUTF16toASCII(mMountPoint); } |
|
73 |
|
74 int32_t State() const { return mState; } |
|
75 const char* StateStr() const { return NS_VolumeStateStr(mState); } |
|
76 |
|
77 bool IsFake() const { return mIsFake; } |
|
78 bool IsMediaPresent() const { return mIsMediaPresent; } |
|
79 bool IsSharing() const { return mIsSharing; } |
|
80 bool IsFormatting() const { return mIsFormatting; } |
|
81 |
|
82 typedef nsTArray<nsRefPtr<nsVolume> > Array; |
|
83 |
|
84 private: |
|
85 ~nsVolume() {} |
|
86 |
|
87 friend class nsVolumeService; // Calls the following XxxMountLock functions |
|
88 void UpdateMountLock(const nsAString& aMountLockState); |
|
89 void UpdateMountLock(bool aMountLocked); |
|
90 |
|
91 void SetIsFake(bool aIsFake); |
|
92 void SetState(int32_t aState); |
|
93 static void FormatVolumeIOThread(const nsCString& aVolume); |
|
94 static void MountVolumeIOThread(const nsCString& aVolume); |
|
95 static void UnmountVolumeIOThread(const nsCString& aVolume); |
|
96 |
|
97 nsString mName; |
|
98 nsString mMountPoint; |
|
99 int32_t mState; |
|
100 int32_t mMountGeneration; |
|
101 bool mMountLocked; |
|
102 bool mIsFake; |
|
103 bool mIsMediaPresent; |
|
104 bool mIsSharing; |
|
105 bool mIsFormatting; |
|
106 }; |
|
107 |
|
108 } // system |
|
109 } // mozilla |
|
110 |
|
111 #endif // mozilla_system_nsvolume_h__ |