// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_ #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_ #include <stddef.h> #include <stdint.h> #include <map> #include <memory> #include <set> #include <string> #include <vector> #include "base/files/file_path.h" #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" #include "base/values.h" #include "chrome/browser/sync_file_system/drive_backend/tracker_id_set.h" #include "chrome/browser/sync_file_system/sync_status_code.h" namespace leveldb { class Env; } namespace google_apis { class ChangeResource; class FileResource; } namespace base { class Location; } namespace sync_file_system { namespace drive_backend { class FileDetails; class FileMetadata; class FileTracker; class LevelDBWrapper; class MetadataDatabaseIndexInterface; class ServiceMetadata; // MetadataDatabase holds and maintains a LevelDB instance and its indexes, // which holds 1)ServiceMetadata, 2)FileMetadata and 3)FileTracker. // 1) ServiceMetadata is a singleton in the database which holds information for // the backend. // 2) FileMetadata represents a remote-side file and holds latest known // metadata of the remote file. // 3) FileTracker represents a synced or to-be-synced file and maintains // the local-side folder tree. // // The term "file" includes files, folders and other resources on Drive. // // FileTrackers form a tree structure on the database, which represents the // FileSystem trees of SyncFileSystem. The tree has a FileTracker named // sync-root as its root node, and a set of FileTracker named app-root. An // app-root represents a remote folder for an installed Chrome App and holds all // synced contents for the App. // // One FileMetadata is created for each tracked remote file, which is identified // by FileID. // One FileTracker is created for every different {parent tracker, FileID} pair, // excluding non-app-root inactive parent trackers. Multiple trackers may be // associated to one FileID when the file has multiple parents. Multiple // trackers may have the same {parent tracker, title} pair when the associated // remote files have the same title. // // Files have following state: // - Unknown file // - Has a dirty inactive tracker and empty synced_details. // - Is initial state of a tracker, only file_id and parent_tracker_id field // are known. // - Folder // - Is either one of sync-root folder, app-root folder or a regular folder. // - Sync-root folder holds app-root folders as its direct children, and // holds entire SyncFileSystem files as its descentants. Its tracker // should be stored in ServiceMetadata by its tracker_id. // - App-root folder holds all files for an application as its descendants. // - File // - Unsupported file // - Represents unsupported files such as hosted documents. Must be // inactive. // // Invariants: // - Any tracker in the database must either: // - be sync-root, // - have an app-root as its parent tracker, or // - have an active tracker as its parent. // That is, all trackers must be reachable from sync-root via app-root folders // and active trackers. // // - Any active tracker must either: // - have |needs_folder_listing| flag and dirty flag, or // - have all children at the stored largest change ID. // // - If multiple trackers have the same parent tracker and same title, they // must not have same |file_id|, and at most one of them may be active. // - If multiple trackers have the same |file_id|, at most one of them may be // active. // class MetadataDatabase { … }; } // namespace drive_backend } // namespace sync_file_system #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_