[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / sync / syncable / parent_child_index.h
blobfd0f2e89c831c87be0a8834aedd6101bfc2a4edd
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SYNC_SYNCABLE_PARENT_CHILD_INDEX
6 #define SYNC_SYNCABLE_PARENT_CHILD_INDEX
8 #include <map>
9 #include <set>
11 #include "base/basictypes.h"
12 #include "sync/base/sync_export.h"
14 namespace syncer {
15 namespace syncable {
17 struct EntryKernel;
18 class Id;
19 class ParentChildIndex;
21 // A node ordering function.
22 struct SYNC_EXPORT_PRIVATE ChildComparator {
23 bool operator() (const EntryKernel* a, const EntryKernel* b) const;
26 // An ordered set of nodes.
27 typedef std::set<EntryKernel*, ChildComparator> OrderedChildSet;
29 // Container that tracks parent-child relationships.
30 // Provides fast lookup of all items under a given parent.
31 class SYNC_EXPORT_PRIVATE ParentChildIndex {
32 public:
33 ParentChildIndex();
34 ~ParentChildIndex();
36 // Returns whether or not this entry belongs in the index.
37 // True for all non-deleted, non-root entries.
38 static bool ShouldInclude(const EntryKernel* e);
40 // Inserts a given child into the index.
41 bool Insert(EntryKernel* e);
43 // Removes a given child from the index.
44 void Remove(EntryKernel* e);
46 // Returns true if this item is in the index as a child.
47 bool Contains(EntryKernel* e) const;
49 // Returns all children of the entry with the given Id. Returns NULL if the
50 // node has no children or the Id does not identify a valid directory node.
51 const OrderedChildSet* GetChildren(const Id& id);
53 private:
54 typedef std::map<syncable::Id, OrderedChildSet*> ParentChildrenMap;
56 // A map of parent IDs to children.
57 // Parents with no children are not included in this map.
58 ParentChildrenMap parent_children_map_;
60 DISALLOW_COPY_AND_ASSIGN(ParentChildIndex);
63 } // namespace syncable
64 } // namespace syncer
66 #endif // SYNC_SYNCABLE_PARENT_CHILD_INDEX