DirectoryMetadata.h (3638B)
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 DOM_QUOTA_DIRECTORYMETADATA_H_ 8 #define DOM_QUOTA_DIRECTORYMETADATA_H_ 9 10 #include <cstdint> 11 12 enum class nsresult : uint32_t; 13 14 class nsIBinaryInputStream; 15 class nsIBinaryOutputStream; 16 class nsIFile; 17 18 namespace mozilla { 19 20 template <typename V, typename E> 21 class Result; 22 23 } 24 25 namespace mozilla::dom::quota { 26 27 struct OriginStateMetadata; 28 29 /** 30 * Directory Metadata File Format (.metadata-v2) 31 * 32 * The metadata file is a binary file containing metadata information for an 33 * origin directory. It consists of a header and several additional fields, 34 * some of which are maintained only for backward compatibility. 35 * 36 * Header (OriginStateMetadata): 37 * - int64_t mLastAccessTime 38 * The last access time of the origin in microseconds since the epoch. 39 * - bool mPersisted 40 * True if the origin is marked as persisted and should survive origin 41 * eviction. 42 * - uint32_t flags 43 * A bitfield of DirectoryMetadataFlags used to store boolean state flags. 44 * This field currently maps only to mAccessed. The defined flags are: 45 * - Initialized: Always set when writing metadata; indicates that this 46 * field contains valid flag bits. Older files written before this 47 * flag was introduced will have this field set to zero. 48 * - Accessed: Indicates whether the origin has been accessed by a quota 49 * client. This maps directly to the mAccessed field in memory. 50 * 51 * If the Initialized flag is not set, the flags field is considered 52 * invalid and mAccessed is conservatively set to true to ensure a full 53 * initialization scan. 54 * - int32_t mLastMaintenanceDate 55 * The last maintenance date of the origin in days since the epoch. 56 * 57 * Legacy fields (still written and read for backward compatibility, but no 58 * longer used): 59 * - nsCString mSuffix 60 * Originally used for origin attributes. Still written to preserve 61 * compatibility. 62 * - nsCString mGroup 63 * Originally used for quota group. Still written to preserve 64 * compatibility. 65 * 66 * Storage fields: 67 * - nsCString mStorageOrigin 68 * Storage origin string (actively used for reconstructing the principal). 69 * 70 * Legacy fields (continued): 71 * - bool mIsPrivate 72 * Flag originally used for private browsing contexts or apps. Still 73 * written. 74 * 75 * Validation check: 76 * - After reading all expected fields, any additional data (even a single 77 * 32-bit value) is treated as an error. 78 * 79 * Notes: 80 * - OriginStateMetadata is loaded first and interpreted independently. This 81 * allows fast and safe updates to the metadata header on disk without 82 * rewriting the full file. 83 * - The header is intentionally designed to contain only fixed-size fields. 84 * This allows updating the header in-place without creating a temporary 85 * file. 86 */ 87 88 Result<OriginStateMetadata, nsresult> ReadDirectoryMetadataHeader( 89 nsIBinaryInputStream& aStream); 90 91 nsresult WriteDirectoryMetadataHeader( 92 nsIBinaryOutputStream& aStream, 93 const OriginStateMetadata& aOriginStateMetadata); 94 95 Result<OriginStateMetadata, nsresult> LoadDirectoryMetadataHeader( 96 nsIFile& aDirectory); 97 98 nsresult SaveDirectoryMetadataHeader( 99 nsIFile& aDirectory, const OriginStateMetadata& aOriginStateMetadata); 100 101 } // namespace mozilla::dom::quota 102 103 #endif // DOM_QUOTA_NOTIFYUTILS_H_