Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/metadata_database_index.h

Issue 349543003: [SyncFS] Use pointers to MetadataDatabaseIndexInterface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Work for nits Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_index_ interface.h"
16 #include "chrome/browser/sync_file_system/drive_backend/tracker_id_set.h"
16 17
17 namespace sync_file_system { 18 namespace sync_file_system {
18 namespace drive_backend { 19 namespace drive_backend {
19 20
20 struct ParentIDAndTitle { 21 class FileMetadata;
21 int64 parent_id; 22 class FileTracker;
22 std::string title; 23 struct DatabaseContents;
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 24
31 } // namespace drive_backend 25 } // namespace drive_backend
32 } // namespace sync_file_system 26 } // namespace sync_file_system
33 27
34 namespace BASE_HASH_NAMESPACE { 28 namespace BASE_HASH_NAMESPACE {
35 29
36 #if defined(COMPILER_GCC) 30 #if defined(COMPILER_GCC)
37 template<> struct hash<sync_file_system::drive_backend::ParentIDAndTitle> { 31 template<> struct hash<sync_file_system::drive_backend::ParentIDAndTitle> {
38 std::size_t operator()( 32 std::size_t operator()(
39 const sync_file_system::drive_backend::ParentIDAndTitle& v) const { 33 const sync_file_system::drive_backend::ParentIDAndTitle& v) const {
40 return base::HashInts64(v.parent_id, hash<std::string>()(v.title)); 34 return base::HashInts64(v.parent_id, hash<std::string>()(v.title));
41 } 35 }
42 }; 36 };
43 #elif defined(COMPILER_MSVC) 37 #elif defined(COMPILER_MSVC)
44 inline size_t hash_value( 38 inline size_t hash_value(
45 const sync_file_system::drive_backend::ParentIDAndTitle& v) { 39 const sync_file_system::drive_backend::ParentIDAndTitle& v) {
46 return base::HashInts64(v.parent_id, hash_value(v.title)); 40 return base::HashInts64(v.parent_id, hash_value(v.title));
47 } 41 }
48 #endif // COMPILER 42 #endif // COMPILER
49 43
50 } // namespace BASE_HASH_NAMESPACE 44 } // namespace BASE_HASH_NAMESPACE
51 45
52 namespace sync_file_system { 46 namespace sync_file_system {
53 namespace drive_backend { 47 namespace drive_backend {
54 48
55 class FileMetadata; 49 // Maintains indexes of MetadataDatabase on memory.
56 class FileTracker; 50 class MetadataDatabaseIndex : public MetadataDatabaseIndexInterface {
57 struct DatabaseContents;
58
59 // Maintains indexes of MetadataDatabase. This class doesn't modify database
60 // entries on memory nor on disk.
61 class MetadataDatabaseIndex {
62 public: 51 public:
63 explicit MetadataDatabaseIndex(DatabaseContents* content); 52 explicit MetadataDatabaseIndex(DatabaseContents* content);
64 ~MetadataDatabaseIndex(); 53 virtual ~MetadataDatabaseIndex();
65 54
66 // Returns FileMetadata identified by |file_id| if exists, otherwise returns 55 // MetadataDatabaseIndexInterface overrides.
67 // NULL. 56 virtual const FileMetadata* GetFileMetadata(
68 const FileMetadata* GetFileMetadata(const std::string& file_id) const; 57 const std::string& file_id) const OVERRIDE;
69 58 virtual const FileTracker* GetFileTracker(int64 tracker_id) const OVERRIDE;
70 // Returns FileTracker identified by |tracker_id| if exists, otherwise returns 59 virtual void StoreFileMetadata(scoped_ptr<FileMetadata> metadata) OVERRIDE;
71 // NULL. 60 virtual void StoreFileTracker(scoped_ptr<FileTracker> tracker) OVERRIDE;
72 const FileTracker* GetFileTracker(int64 tracker_id) const; 61 virtual void RemoveFileMetadata(const std::string& file_id) OVERRIDE;
73 62 virtual void RemoveFileTracker(int64 tracker_id) OVERRIDE;
74 // Stores |metadata| and updates indexes. 63 virtual TrackerIDSet GetFileTrackerIDsByFileID(
75 // This overwrites existing FileMetadata for the same |file_id|. 64 const std::string& file_id) const OVERRIDE;
76 void StoreFileMetadata(scoped_ptr<FileMetadata> metadata); 65 virtual int64 GetAppRootTracker(const std::string& app_id) const OVERRIDE;
77 66 virtual TrackerIDSet GetFileTrackerIDsByParentAndTitle(
78 // Stores |tracker| and updates indexes.
79 // This overwrites existing FileTracker for the same |tracker_id|.
80 void StoreFileTracker(scoped_ptr<FileTracker> tracker);
81
82 // Removes FileMetadata identified by |file_id| from indexes.
83 void RemoveFileMetadata(const std::string& file_id);
84
85 // Removes FileTracker identified by |tracker_id| from indexes.
86 void RemoveFileTracker(int64 tracker_id);
87
88 // Returns a set of FileTracker that have |file_id| as its own.
89 TrackerIDSet GetFileTrackerIDsByFileID(const std::string& file_id) const;
90
91 // Returns an app-root tracker identified by |app_id|. Returns 0 if not
92 // found.
93 int64 GetAppRootTracker(const std::string& app_id) const;
94
95 // Returns a set of FileTracker that have |parent_tracker_id| and |title|.
96 TrackerIDSet GetFileTrackerIDsByParentAndTitle(
97 int64 parent_tracker_id, 67 int64 parent_tracker_id,
98 const std::string& title) const; 68 const std::string& title) const OVERRIDE;
99 69 virtual std::vector<int64> GetFileTrackerIDsByParent(
100 std::vector<int64> GetFileTrackerIDsByParent(int64 parent_tracker_id) const; 70 int64 parent_tracker_id) const OVERRIDE;
101 71 virtual std::string PickMultiTrackerFileID() const OVERRIDE;
102 // Returns the |file_id| of a file that has multiple trackers. 72 virtual ParentIDAndTitle PickMultiBackingFilePath() const OVERRIDE;
103 std::string PickMultiTrackerFileID() const; 73 virtual int64 PickDirtyTracker() const OVERRIDE;
104 74 virtual void DemoteDirtyTracker(int64 tracker_id) OVERRIDE;
105 // Returns a pair of |parent_tracker_id| and |title| that has multiple file 75 virtual bool HasDemotedDirtyTracker() const OVERRIDE;
106 // at the path. 76 virtual void PromoteDemotedDirtyTrackers() OVERRIDE;
107 ParentIDAndTitle PickMultiBackingFilePath() const; 77 virtual size_t CountDirtyTracker() const OVERRIDE;
108 78 virtual size_t CountFileMetadata() const OVERRIDE;
109 // Returns a FileTracker whose |dirty| is set and which isn't demoted. 79 virtual size_t CountFileTracker() const OVERRIDE;
110 // Returns 0 if not found. 80 virtual std::vector<std::string> GetRegisteredAppIDs() const OVERRIDE;
111 int64 PickDirtyTracker() const; 81 virtual std::vector<int64> GetAllTrackerIDs() const OVERRIDE;
112 82 virtual std::vector<std::string> GetAllMetadataIDs() const OVERRIDE;
113 // Demotes a dirty tracker.
114 void DemoteDirtyTracker(int64 tracker_id);
115
116 bool HasDemotedDirtyTracker() const;
117
118 // Promotes all demoted dirty trackers to normal dirty trackers.
119 void PromoteDemotedDirtyTrackers();
120
121 size_t CountDirtyTracker() const;
122 size_t CountFileMetadata() const;
123 size_t CountFileTracker() const;
124 std::vector<std::string> GetRegisteredAppIDs() const;
125 std::vector<int64> GetAllTrackerIDs() const;
126 std::vector<std::string> GetAllMetadataIDs() const;
127 83
128 private: 84 private:
129 typedef base::ScopedPtrHashMap<std::string, FileMetadata> MetadataByID; 85 typedef base::ScopedPtrHashMap<std::string, FileMetadata> MetadataByID;
130 typedef base::ScopedPtrHashMap<int64, FileTracker> TrackerByID; 86 typedef base::ScopedPtrHashMap<int64, FileTracker> TrackerByID;
131 typedef base::hash_map<std::string, TrackerIDSet> TrackerIDsByFileID; 87 typedef base::hash_map<std::string, TrackerIDSet> TrackerIDsByFileID;
132 typedef base::hash_map<std::string, TrackerIDSet> TrackerIDsByTitle; 88 typedef base::hash_map<std::string, TrackerIDSet> TrackerIDsByTitle;
133 typedef std::map<int64, TrackerIDsByTitle> TrackerIDsByParentAndTitle; 89 typedef std::map<int64, TrackerIDsByTitle> TrackerIDsByParentAndTitle;
134 typedef base::hash_map<std::string, int64> TrackerIDByAppID; 90 typedef base::hash_map<std::string, int64> TrackerIDByAppID;
135 typedef base::hash_set<std::string> FileIDSet; 91 typedef base::hash_set<std::string> FileIDSet;
136 typedef base::hash_set<ParentIDAndTitle> PathSet; 92 typedef base::hash_set<ParentIDAndTitle> PathSet;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 DirtyTrackers dirty_trackers_; 132 DirtyTrackers dirty_trackers_;
177 DirtyTrackers demoted_dirty_trackers_; 133 DirtyTrackers demoted_dirty_trackers_;
178 134
179 DISALLOW_COPY_AND_ASSIGN(MetadataDatabaseIndex); 135 DISALLOW_COPY_AND_ASSIGN(MetadataDatabaseIndex);
180 }; 136 };
181 137
182 } // namespace drive_backend 138 } // namespace drive_backend
183 } // namespace sync_file_system 139 } // namespace sync_file_system
184 140
185 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX _H_ 141 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698