/* 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 COMM_MAILNEWS_DB_PANORAMA_SRC_FOLDERDATABASE_H_ #define COMM_MAILNEWS_DB_PANORAMA_SRC_FOLDERDATABASE_H_ #include "FolderComparator.h" #include "mozilla/HashTable.h" #include "mozilla/MozPromise.h" #include "mozilla/RefPtr.h" #include "mozilla/Result.h" #include "nsIFolderDatabase.h" #include "nsTHashMap.h" using mozilla::MozPromise; namespace mozilla::mailnews { class FolderDatabase : public nsIFolderDatabase { public: NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIFOLDERDATABASE Result GetFolderName(uint64_t folderId); Result GetFolderPath(uint64_t folderId); Result GetFolderFlags(uint64_t folderId); Result GetFolderParent(uint64_t folderId); // Returns children sorted. Can pass folderId=0 to get root folders. Result, nsresult> GetFolderChildren(uint64_t folderId); Result GetFolderChildNamed(uint64_t folderId, nsACString const& childName); Result GetFolderRoot(uint64_t folderId); Result, nsresult> GetFolderDescendants(uint64_t folderId); Result, nsresult> GetFolderAncestors(uint64_t folderId); Result, nsresult> GetFolderOrdinal(uint64_t folderId); protected: virtual ~FolderDatabase() {}; private: friend class DatabaseCore; FolderDatabase() : mComparator(*this) {}; private: friend class DatabaseCore; friend class FolderInfo; friend class VirtualFolderFilter; friend class VirtualFolderWrapper; nsresult GetFolderProperty(uint64_t id, const nsACString& name, nsACString& value); nsresult GetFolderProperty(uint64_t id, const nsACString& name, int64_t* value); nsresult SetFolderProperty(uint64_t id, const nsACString& name, const nsACString& value); nsresult SetFolderProperty(uint64_t id, const nsACString& name, int64_t value); nsresult GetVirtualFolderFolders(uint64_t virtualFolderId, nsTArray& searchFolderIds); nsresult SetVirtualFolderFolders(uint64_t virtualFolderId, nsTArray& searchFolderIds); Result, nsresult> GetFolderChildrenUnsorted( uint64_t folderId); private: FolderComparator mComparator; nsresult InternalLoadFolders(); nsresult InternalInsertFolder(uint64_t aParent, const nsACString& aName, uint64_t* aChild); nsresult InternalDeleteFolder(uint64_t aFolder); nsresult SaveOrdinals(nsTArray const& aFolders); nsresult InternalAppendDescendants(uint64_t folderId, nsTArray& descendants); // Folder data we want cached. struct CachedFolder { uint64_t id{0}; uint64_t parent{0}; Maybe ordinal; nsAutoCString name; uint32_t flags{0}; }; // The cache, indexed by folderId. mozilla::HashMap mFolderCache; // Guarantee folder data is in cache. Result EnsureFolderCached(uint64_t folderId); // Fetch folder data from DB into our cache struct. nsresult FetchFolderData(uint64_t folderId, CachedFolder& cached); // Check the cache and slim it down if needed. void TrimCache(); }; } // namespace mozilla::mailnews #endif // COMM_MAILNEWS_DB_PANORAMA_SRC_FOLDERDATABASE_H_