FileSystemBase.h (2602B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_FileSystemBase_h 8 #define mozilla_dom_FileSystemBase_h 9 10 #include "Directory.h" 11 #include "nsString.h" 12 13 namespace mozilla::dom { 14 15 class BlobImpl; 16 17 class FileSystemBase { 18 public: 19 NS_INLINE_DECL_REFCOUNTING(FileSystemBase) 20 21 FileSystemBase(); 22 23 virtual void Shutdown(); 24 25 // SerializeDOMPath the FileSystem to string. 26 virtual void SerializeDOMPath(nsAString& aOutput) const = 0; 27 28 virtual already_AddRefed<FileSystemBase> Clone() = 0; 29 30 virtual bool ShouldCreateDirectory() = 0; 31 32 virtual nsIGlobalObject* GetParentObject() const; 33 34 virtual void GetDirectoryName(nsIFile* aFile, nsAString& aRetval, 35 ErrorResult& aRv) const; 36 37 void GetDOMPath(nsIFile* aFile, nsAString& aRetval, ErrorResult& aRv) const; 38 39 /* 40 * Return the local root path of the FileSystem implementation. 41 * For OSFileSystem, this is equal to the path of the root Directory; 42 * For DeviceStorageFileSystem, this is the path of the SDCard, parent 43 * directory of the exposed root Directory (per type). 44 */ 45 const nsAString& LocalRootPath() const { return mLocalRootPath; } 46 47 bool IsShutdown() const { return mShutdown; } 48 49 virtual bool IsSafeFile(nsIFile* aFile) const; 50 51 virtual bool IsSafeDirectory(Directory* aDir) const; 52 53 bool GetRealPath(BlobImpl* aFile, nsIFile** aPath) const; 54 55 // CC methods 56 virtual void Unlink() {} 57 virtual void Traverse(nsCycleCollectionTraversalCallback& cb) {} 58 59 void AssertIsOnOwningThread() const; 60 61 protected: 62 virtual ~FileSystemBase(); 63 64 // The local path of the root (i.e. the OS path, with OS path separators, of 65 // the OS directory that acts as the root of this OSFileSystem). 66 // This path must be set by the FileSystem implementation immediately 67 // because it will be used for the validation of any FileSystemTaskChildBase. 68 // The concept of this path is that, any task will never go out of it and this 69 // must be considered the OS 'root' of the current FileSystem. Different 70 // Directory object can have different OS 'root' path. 71 // To be more clear, any path managed by this FileSystem implementation must 72 // be discendant of this local root path. 73 nsString mLocalRootPath; 74 75 bool mShutdown; 76 }; 77 78 } // namespace mozilla::dom 79 80 #endif // mozilla_dom_FileSystemBase_h