| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_ON
_DISK_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_ON
_DISK_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_ON
_DISK_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_ON
_DISK_H_ |
| 7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 8 #include <map> | 11 #include <map> |
| 9 #include <set> | 12 #include <set> |
| 10 #include <string> | 13 #include <string> |
| 11 #include <vector> | 14 #include <vector> |
| 12 | 15 |
| 16 #include "base/macros.h" |
| 13 #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index_
interface.h" | 17 #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index_
interface.h" |
| 14 #include "chrome/browser/sync_file_system/drive_backend/tracker_id_set.h" | 18 #include "chrome/browser/sync_file_system/drive_backend/tracker_id_set.h" |
| 15 | 19 |
| 16 namespace sync_file_system { | 20 namespace sync_file_system { |
| 17 namespace drive_backend { | 21 namespace drive_backend { |
| 18 | 22 |
| 19 class FileMetadata; | 23 class FileMetadata; |
| 20 class FileTracker; | 24 class FileTracker; |
| 21 class LevelDBWrapper; | 25 class LevelDBWrapper; |
| 22 class ServiceMetadata; | 26 class ServiceMetadata; |
| 23 struct DatabaseContents; | 27 struct DatabaseContents; |
| 24 // TODO(peria): Migrate implementation of ParentIDAndTitle structure from | 28 // TODO(peria): Migrate implementation of ParentIDAndTitle structure from |
| 25 // metadata_database_index.{cc,h} to here, on removing the files. | 29 // metadata_database_index.{cc,h} to here, on removing the files. |
| 26 struct ParentIDAndTitle; | 30 struct ParentIDAndTitle; |
| 27 | 31 |
| 28 // Maintains indexes of MetadataDatabase on disk. | 32 // Maintains indexes of MetadataDatabase on disk. |
| 29 class MetadataDatabaseIndexOnDisk : public MetadataDatabaseIndexInterface { | 33 class MetadataDatabaseIndexOnDisk : public MetadataDatabaseIndexInterface { |
| 30 public: | 34 public: |
| 31 static scoped_ptr<MetadataDatabaseIndexOnDisk> Create(LevelDBWrapper* db); | 35 static scoped_ptr<MetadataDatabaseIndexOnDisk> Create(LevelDBWrapper* db); |
| 32 | 36 |
| 33 ~MetadataDatabaseIndexOnDisk() override; | 37 ~MetadataDatabaseIndexOnDisk() override; |
| 34 | 38 |
| 35 // MetadataDatabaseIndexInterface overrides. | 39 // MetadataDatabaseIndexInterface overrides. |
| 36 void RemoveUnreachableItems() override; | 40 void RemoveUnreachableItems() override; |
| 37 bool GetFileMetadata(const std::string& file_id, | 41 bool GetFileMetadata(const std::string& file_id, |
| 38 FileMetadata* metadata) const override; | 42 FileMetadata* metadata) const override; |
| 39 bool GetFileTracker(int64 tracker_id, FileTracker* tracker) const override; | 43 bool GetFileTracker(int64_t tracker_id, FileTracker* tracker) const override; |
| 40 void StoreFileMetadata(scoped_ptr<FileMetadata> metadata) override; | 44 void StoreFileMetadata(scoped_ptr<FileMetadata> metadata) override; |
| 41 void StoreFileTracker(scoped_ptr<FileTracker> tracker) override; | 45 void StoreFileTracker(scoped_ptr<FileTracker> tracker) override; |
| 42 void RemoveFileMetadata(const std::string& file_id) override; | 46 void RemoveFileMetadata(const std::string& file_id) override; |
| 43 void RemoveFileTracker(int64 tracker_id) override; | 47 void RemoveFileTracker(int64_t tracker_id) override; |
| 44 TrackerIDSet GetFileTrackerIDsByFileID( | 48 TrackerIDSet GetFileTrackerIDsByFileID( |
| 45 const std::string& file_id) const override; | 49 const std::string& file_id) const override; |
| 46 int64 GetAppRootTracker(const std::string& app_id) const override; | 50 int64_t GetAppRootTracker(const std::string& app_id) const override; |
| 47 TrackerIDSet GetFileTrackerIDsByParentAndTitle( | 51 TrackerIDSet GetFileTrackerIDsByParentAndTitle( |
| 48 int64 parent_tracker_id, | 52 int64_t parent_tracker_id, |
| 49 const std::string& title) const override; | 53 const std::string& title) const override; |
| 50 std::vector<int64> GetFileTrackerIDsByParent( | 54 std::vector<int64_t> GetFileTrackerIDsByParent( |
| 51 int64 parent_tracker_id) const override; | 55 int64_t parent_tracker_id) const override; |
| 52 std::string PickMultiTrackerFileID() const override; | 56 std::string PickMultiTrackerFileID() const override; |
| 53 ParentIDAndTitle PickMultiBackingFilePath() const override; | 57 ParentIDAndTitle PickMultiBackingFilePath() const override; |
| 54 int64 PickDirtyTracker() const override; | 58 int64_t PickDirtyTracker() const override; |
| 55 void DemoteDirtyTracker(int64 tracker_id) override; | 59 void DemoteDirtyTracker(int64_t tracker_id) override; |
| 56 bool HasDemotedDirtyTracker() const override; | 60 bool HasDemotedDirtyTracker() const override; |
| 57 bool IsDemotedDirtyTracker(int64 tracker_id) const override; | 61 bool IsDemotedDirtyTracker(int64_t tracker_id) const override; |
| 58 void PromoteDemotedDirtyTracker(int64 tracker_id) override; | 62 void PromoteDemotedDirtyTracker(int64_t tracker_id) override; |
| 59 bool PromoteDemotedDirtyTrackers() override; | 63 bool PromoteDemotedDirtyTrackers() override; |
| 60 size_t CountDirtyTracker() const override; | 64 size_t CountDirtyTracker() const override; |
| 61 size_t CountFileMetadata() const override; | 65 size_t CountFileMetadata() const override; |
| 62 size_t CountFileTracker() const override; | 66 size_t CountFileTracker() const override; |
| 63 void SetSyncRootRevalidated() const override; | 67 void SetSyncRootRevalidated() const override; |
| 64 void SetSyncRootTrackerID(int64 sync_root_id) const override; | 68 void SetSyncRootTrackerID(int64_t sync_root_id) const override; |
| 65 void SetLargestChangeID(int64 largest_change_id) const override; | 69 void SetLargestChangeID(int64_t largest_change_id) const override; |
| 66 void SetNextTrackerID(int64 next_tracker_id) const override; | 70 void SetNextTrackerID(int64_t next_tracker_id) const override; |
| 67 bool IsSyncRootRevalidated() const override; | 71 bool IsSyncRootRevalidated() const override; |
| 68 int64 GetSyncRootTrackerID() const override; | 72 int64_t GetSyncRootTrackerID() const override; |
| 69 int64 GetLargestChangeID() const override; | 73 int64_t GetLargestChangeID() const override; |
| 70 int64 GetNextTrackerID() const override; | 74 int64_t GetNextTrackerID() const override; |
| 71 std::vector<std::string> GetRegisteredAppIDs() const override; | 75 std::vector<std::string> GetRegisteredAppIDs() const override; |
| 72 std::vector<int64> GetAllTrackerIDs() const override; | 76 std::vector<int64_t> GetAllTrackerIDs() const override; |
| 73 std::vector<std::string> GetAllMetadataIDs() const override; | 77 std::vector<std::string> GetAllMetadataIDs() const override; |
| 74 | 78 |
| 75 // Builds on-disk indexes from FileTracker entries on disk. | 79 // Builds on-disk indexes from FileTracker entries on disk. |
| 76 // Returns the number of newly added entries for indexing. | 80 // Returns the number of newly added entries for indexing. |
| 77 int64 BuildTrackerIndexes(); | 81 int64_t BuildTrackerIndexes(); |
| 78 | 82 |
| 79 // Deletes entries used for indexes on on-disk database. | 83 // Deletes entries used for indexes on on-disk database. |
| 80 // Returns the number of the deleted entries. | 84 // Returns the number of the deleted entries. |
| 81 int64 DeleteTrackerIndexes(); | 85 int64_t DeleteTrackerIndexes(); |
| 82 | 86 |
| 83 LevelDBWrapper* GetDBForTesting(); | 87 LevelDBWrapper* GetDBForTesting(); |
| 84 | 88 |
| 85 private: | 89 private: |
| 86 enum NumEntries { | 90 enum NumEntries { |
| 87 NONE, // No entries are found. | 91 NONE, // No entries are found. |
| 88 SINGLE, // One entry is found. | 92 SINGLE, // One entry is found. |
| 89 MULTIPLE, // Two or more entires are found. | 93 MULTIPLE, // Two or more entires are found. |
| 90 }; | 94 }; |
| 91 | 95 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 130 |
| 127 // Adds an entry with |key_prefix| and tracker ID of |tracker|. If |tracker| | 131 // Adds an entry with |key_prefix| and tracker ID of |tracker|. If |tracker| |
| 128 // is active, an entry for |active_key| is added. | 132 // is active, an entry for |active_key| is added. |
| 129 void AddToTrackerIDSetWithPrefix( | 133 void AddToTrackerIDSetWithPrefix( |
| 130 const std::string& active_tracker_key, | 134 const std::string& active_tracker_key, |
| 131 const std::string& key_prefix, | 135 const std::string& key_prefix, |
| 132 const FileTracker& tracker); | 136 const FileTracker& tracker); |
| 133 | 137 |
| 134 // Returns true if |tracker_id| is removed successfully. If no other entries | 138 // Returns true if |tracker_id| is removed successfully. If no other entries |
| 135 // are stored with |key_prefix|, the entry for |active_key| is also removed. | 139 // are stored with |key_prefix|, the entry for |active_key| is also removed. |
| 136 bool EraseInTrackerIDSetWithPrefix( | 140 bool EraseInTrackerIDSetWithPrefix(const std::string& active_tracker_key, |
| 137 const std::string& active_tracker_key, | 141 const std::string& key_prefix, |
| 138 const std::string& key_prefix, | 142 int64_t tracker_id); |
| 139 int64 tracker_id); | |
| 140 | 143 |
| 141 // Adds an entry for |active_key| on DB, if |tracker_id| has an entry with | 144 // Adds an entry for |active_key| on DB, if |tracker_id| has an entry with |
| 142 // |key_prefix|. | 145 // |key_prefix|. |
| 143 void ActivateInTrackerIDSetWithPrefix( | 146 void ActivateInTrackerIDSetWithPrefix(const std::string& active_tracker_key, |
| 144 const std::string& active_tracker_key, | 147 const std::string& key_prefix, |
| 145 const std::string& key_prefix, | 148 int64_t tracker_id); |
| 146 int64 tracker_id); | |
| 147 | 149 |
| 148 // Removes an entry for |active_key| on DB, if the value of |active_key| key | 150 // Removes an entry for |active_key| on DB, if the value of |active_key| key |
| 149 // is |tracker_id|. | 151 // is |tracker_id|. |
| 150 void DeactivateInTrackerIDSetWithPrefix( | 152 void DeactivateInTrackerIDSetWithPrefix(const std::string& active_tracker_key, |
| 151 const std::string& active_tracker_key, | 153 const std::string& key_prefix, |
| 152 const std::string& key_prefix, | 154 int64_t tracker_id); |
| 153 int64 tracker_id); | |
| 154 | 155 |
| 155 // Checks if |db_| has an entry whose key is |key|. | 156 // Checks if |db_| has an entry whose key is |key|. |
| 156 bool DBHasKey(const std::string& key) const; | 157 bool DBHasKey(const std::string& key) const; |
| 157 | 158 |
| 158 // Returns the number of dirty trackers, actually counting them. | 159 // Returns the number of dirty trackers, actually counting them. |
| 159 size_t CountDirtyTrackerInternal() const; | 160 size_t CountDirtyTrackerInternal() const; |
| 160 | 161 |
| 161 // Returns the number of entries starting with |prefix| in NumEntries format. | 162 // Returns the number of entries starting with |prefix| in NumEntries format. |
| 162 // Entries for |ignored_id| are not counted in. | 163 // Entries for |ignored_id| are not counted in. |
| 163 NumEntries CountWithPrefix(const std::string& prefix, int64 ignored_id); | 164 NumEntries CountWithPrefix(const std::string& prefix, int64_t ignored_id); |
| 164 | 165 |
| 165 // Deletes entries whose keys start from |prefix|. | 166 // Deletes entries whose keys start from |prefix|. |
| 166 void DeleteKeyStartsWith(const std::string& prefix); | 167 void DeleteKeyStartsWith(const std::string& prefix); |
| 167 | 168 |
| 168 LevelDBWrapper* db_; // Not owned. | 169 LevelDBWrapper* db_; // Not owned. |
| 169 scoped_ptr<ServiceMetadata> service_metadata_; | 170 scoped_ptr<ServiceMetadata> service_metadata_; |
| 170 | 171 |
| 171 size_t num_dirty_trackers_; | 172 size_t num_dirty_trackers_; |
| 172 | 173 |
| 173 DISALLOW_COPY_AND_ASSIGN(MetadataDatabaseIndexOnDisk); | 174 DISALLOW_COPY_AND_ASSIGN(MetadataDatabaseIndexOnDisk); |
| 174 }; | 175 }; |
| 175 | 176 |
| 176 } // namespace drive_backend | 177 } // namespace drive_backend |
| 177 } // namespace sync_file_system | 178 } // namespace sync_file_system |
| 178 | 179 |
| 179 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX
_ON_DISK_H_ | 180 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX
_ON_DISK_H_ |
| OLD | NEW |