Chromium Code Reviews| 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_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/containers/scoped_ptr_hash_map.h" | 14 #include "base/containers/scoped_ptr_hash_map.h" |
| 15 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" | 15 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
|
tzik
2014/06/20 03:57:47
Not sure but can we remove metadata_database.h #in
peria
2014/06/20 04:44:22
Done.
| |
| 16 #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index_ interface.h" | |
| 16 | 17 |
| 17 namespace sync_file_system { | 18 namespace sync_file_system { |
| 18 namespace drive_backend { | 19 namespace drive_backend { |
| 19 | |
| 20 struct ParentIDAndTitle { | |
| 21 int64 parent_id; | |
| 22 std::string title; | |
| 23 | |
| 24 ParentIDAndTitle(); | |
| 25 ParentIDAndTitle(int64 parent_id, const std::string& title); | |
| 26 }; | |
| 27 | |
| 28 bool operator==(const ParentIDAndTitle& left, const ParentIDAndTitle& right); | |
| 29 bool operator<(const ParentIDAndTitle& left, const ParentIDAndTitle& right); | |
| 30 | |
| 31 } // namespace drive_backend | |
| 32 } // namespace sync_file_system | |
| 33 | |
| 34 namespace BASE_HASH_NAMESPACE { | |
| 35 | |
| 36 #if defined(COMPILER_GCC) | |
| 37 template<> struct hash<sync_file_system::drive_backend::ParentIDAndTitle> { | |
| 38 std::size_t operator()( | |
| 39 const sync_file_system::drive_backend::ParentIDAndTitle& v) const { | |
| 40 return base::HashInts64(v.parent_id, hash<std::string>()(v.title)); | |
| 41 } | |
| 42 }; | |
| 43 #elif defined(COMPILER_MSVC) | |
| 44 inline size_t hash_value( | |
| 45 const sync_file_system::drive_backend::ParentIDAndTitle& v) { | |
| 46 return base::HashInts64(v.parent_id, hash_value(v.title)); | |
| 47 } | |
| 48 #endif // COMPILER | |
| 49 | |
| 50 } // namespace BASE_HASH_NAMESPACE | |
| 51 | |
| 52 namespace sync_file_system { | |
| 53 namespace drive_backend { | |
| 54 | 20 |
| 55 class FileMetadata; | 21 class FileMetadata; |
| 56 class FileTracker; | 22 class FileTracker; |
| 57 struct DatabaseContents; | 23 struct DatabaseContents; |
| 58 | 24 |
| 59 // Maintains indexes of MetadataDatabase. This class doesn't modify database | 25 // Maintains indexes of MetadataDatabase on memory |
|
tzik
2014/06/20 03:57:47
please add '.' to the EOL here.
peria
2014/06/20 04:44:22
Done.
| |
| 60 // entries on memory nor on disk. | 26 class MetadataDatabaseIndex : public MetadataDatabaseIndexInterface { |
| 61 class MetadataDatabaseIndex { | |
| 62 public: | 27 public: |
| 63 explicit MetadataDatabaseIndex(DatabaseContents* content); | 28 explicit MetadataDatabaseIndex(DatabaseContents* content); |
| 64 ~MetadataDatabaseIndex(); | 29 virtual ~MetadataDatabaseIndex(); |
| 65 | 30 |
| 66 // Returns FileMetadata identified by |file_id| if exists, otherwise returns | 31 // Returns FileMetadata identified by |file_id| if exists, otherwise returns |
| 67 // NULL. | 32 // NULL. |
|
tzik
2014/06/20 03:57:47
Could you remove these comments for overridden fun
peria
2014/06/20 04:44:22
Done.
| |
| 68 const FileMetadata* GetFileMetadata(const std::string& file_id) const; | 33 virtual const FileMetadata* GetFileMetadata( |
| 34 const std::string& file_id) const OVERRIDE; | |
| 69 | 35 |
| 70 // Returns FileTracker identified by |tracker_id| if exists, otherwise returns | 36 // Returns FileTracker identified by |tracker_id| if exists, otherwise returns |
| 71 // NULL. | 37 // NULL. |
| 72 const FileTracker* GetFileTracker(int64 tracker_id) const; | 38 virtual const FileTracker* GetFileTracker(int64 tracker_id) const OVERRIDE; |
| 73 | 39 |
| 74 // Stores |metadata| and updates indexes. | 40 // Stores |metadata| and updates indexes. |
| 75 // This overwrites existing FileMetadata for the same |file_id|. | 41 // This overwrites existing FileMetadata for the same |file_id|. |
| 76 void StoreFileMetadata(scoped_ptr<FileMetadata> metadata); | 42 virtual void StoreFileMetadata(scoped_ptr<FileMetadata> metadata) OVERRIDE; |
| 77 | 43 |
| 78 // Stores |tracker| and updates indexes. | 44 // Stores |tracker| and updates indexes. |
| 79 // This overwrites existing FileTracker for the same |tracker_id|. | 45 // This overwrites existing FileTracker for the same |tracker_id|. |
| 80 void StoreFileTracker(scoped_ptr<FileTracker> tracker); | 46 virtual void StoreFileTracker(scoped_ptr<FileTracker> tracker) OVERRIDE; |
| 81 | 47 |
| 82 // Removes FileMetadata identified by |file_id| from indexes. | 48 // Removes FileMetadata identified by |file_id| from indexes. |
| 83 void RemoveFileMetadata(const std::string& file_id); | 49 virtual void RemoveFileMetadata(const std::string& file_id) OVERRIDE; |
| 84 | 50 |
| 85 // Removes FileTracker identified by |tracker_id| from indexes. | 51 // Removes FileTracker identified by |tracker_id| from indexes. |
| 86 void RemoveFileTracker(int64 tracker_id); | 52 virtual void RemoveFileTracker(int64 tracker_id) OVERRIDE; |
| 87 | 53 |
| 88 // Returns a set of FileTracker that have |file_id| as its own. | 54 // Returns a set of FileTracker that have |file_id| as its own. |
| 89 TrackerIDSet GetFileTrackerIDsByFileID(const std::string& file_id) const; | 55 virtual TrackerIDSet GetFileTrackerIDsByFileID( |
| 56 const std::string& file_id) const OVERRIDE; | |
| 90 | 57 |
| 91 // Returns an app-root tracker identified by |app_id|. Returns 0 if not | 58 // Returns an app-root tracker identified by |app_id|. Returns 0 if not |
| 92 // found. | 59 // found. |
| 93 int64 GetAppRootTracker(const std::string& app_id) const; | 60 virtual int64 GetAppRootTracker(const std::string& app_id) const OVERRIDE; |
| 94 | 61 |
| 95 // Returns a set of FileTracker that have |parent_tracker_id| and |title|. | 62 // Returns a set of FileTracker that have |parent_tracker_id| and |title|. |
| 96 TrackerIDSet GetFileTrackerIDsByParentAndTitle( | 63 virtual TrackerIDSet GetFileTrackerIDsByParentAndTitle( |
| 97 int64 parent_tracker_id, | 64 int64 parent_tracker_id, |
| 98 const std::string& title) const; | 65 const std::string& title) const OVERRIDE; |
| 99 | 66 |
| 100 std::vector<int64> GetFileTrackerIDsByParent(int64 parent_tracker_id) const; | 67 virtual std::vector<int64> GetFileTrackerIDsByParent( |
| 68 int64 parent_tracker_id) const OVERRIDE; | |
| 101 | 69 |
| 102 // Returns the |file_id| of a file that has multiple trackers. | 70 // Returns the |file_id| of a file that has multiple trackers. |
| 103 std::string PickMultiTrackerFileID() const; | 71 virtual std::string PickMultiTrackerFileID() const OVERRIDE; |
| 104 | 72 |
| 105 // Returns a pair of |parent_tracker_id| and |title| that has multiple file | 73 // Returns a pair of |parent_tracker_id| and |title| that has multiple file |
| 106 // at the path. | 74 // at the path. |
| 107 ParentIDAndTitle PickMultiBackingFilePath() const; | 75 virtual ParentIDAndTitle PickMultiBackingFilePath() const OVERRIDE; |
| 108 | 76 |
| 109 // Returns a FileTracker whose |dirty| is set and which isn't demoted. | 77 // Returns a FileTracker whose |dirty| is set and which isn't demoted. |
| 110 // Returns 0 if not found. | 78 // Returns 0 if not found. |
| 111 int64 PickDirtyTracker() const; | 79 virtual int64 PickDirtyTracker() const OVERRIDE; |
| 112 | 80 |
| 113 // Demotes a dirty tracker. | 81 // Demotes a dirty tracker. |
| 114 void DemoteDirtyTracker(int64 tracker_id); | 82 virtual void DemoteDirtyTracker(int64 tracker_id) OVERRIDE; |
| 115 | 83 |
| 116 bool HasDemotedDirtyTracker() const; | 84 virtual bool HasDemotedDirtyTracker() const OVERRIDE; |
| 117 | 85 |
| 118 // Promotes all demoted dirty trackers to normal dirty trackers. | 86 // Promotes all demoted dirty trackers to normal dirty trackers. |
| 119 void PromoteDemotedDirtyTrackers(); | 87 virtual void PromoteDemotedDirtyTrackers() OVERRIDE; |
| 120 | 88 |
| 121 size_t CountDirtyTracker() const; | 89 virtual size_t CountDirtyTracker() const OVERRIDE; |
| 122 size_t CountFileMetadata() const; | 90 virtual size_t CountFileMetadata() const OVERRIDE; |
| 123 size_t CountFileTracker() const; | 91 virtual size_t CountFileTracker() const OVERRIDE; |
| 124 std::vector<std::string> GetRegisteredAppIDs() const; | 92 |
| 125 std::vector<int64> GetAllTrackerIDs() const; | 93 virtual std::vector<std::string> GetRegisteredAppIDs() const OVERRIDE; |
| 126 std::vector<std::string> GetAllMetadataIDs() const; | 94 virtual std::vector<int64> GetAllTrackerIDs() const OVERRIDE; |
| 95 virtual std::vector<std::string> GetAllMetadataIDs() const OVERRIDE; | |
| 127 | 96 |
| 128 private: | 97 private: |
| 129 typedef base::ScopedPtrHashMap<std::string, FileMetadata> MetadataByID; | 98 typedef base::ScopedPtrHashMap<std::string, FileMetadata> MetadataByID; |
| 130 typedef base::ScopedPtrHashMap<int64, FileTracker> TrackerByID; | 99 typedef base::ScopedPtrHashMap<int64, FileTracker> TrackerByID; |
| 131 typedef base::hash_map<std::string, TrackerIDSet> TrackerIDsByFileID; | 100 typedef base::hash_map<std::string, TrackerIDSet> TrackerIDsByFileID; |
| 132 typedef base::hash_map<std::string, TrackerIDSet> TrackerIDsByTitle; | 101 typedef base::hash_map<std::string, TrackerIDSet> TrackerIDsByTitle; |
| 133 typedef std::map<int64, TrackerIDsByTitle> TrackerIDsByParentAndTitle; | 102 typedef std::map<int64, TrackerIDsByTitle> TrackerIDsByParentAndTitle; |
| 134 typedef base::hash_map<std::string, int64> TrackerIDByAppID; | 103 typedef base::hash_map<std::string, int64> TrackerIDByAppID; |
| 135 typedef base::hash_set<std::string> FileIDSet; | 104 typedef base::hash_set<std::string> FileIDSet; |
| 136 typedef base::hash_set<ParentIDAndTitle> PathSet; | 105 typedef base::hash_set<ParentIDAndTitle> PathSet; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 DirtyTrackers dirty_trackers_; | 145 DirtyTrackers dirty_trackers_; |
| 177 DirtyTrackers demoted_dirty_trackers_; | 146 DirtyTrackers demoted_dirty_trackers_; |
| 178 | 147 |
| 179 DISALLOW_COPY_AND_ASSIGN(MetadataDatabaseIndex); | 148 DISALLOW_COPY_AND_ASSIGN(MetadataDatabaseIndex); |
| 180 }; | 149 }; |
| 181 | 150 |
| 182 } // namespace drive_backend | 151 } // namespace drive_backend |
| 183 } // namespace sync_file_system | 152 } // namespace sync_file_system |
| 184 | 153 |
| 185 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX _H_ | 154 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX _H_ |
| OLD | NEW |