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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_INTERFACE_H_
6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_INTERFACE_H_
7
8#include <string>
9#include <vector>
10
11#include "base/memory/scoped_ptr.h"
12
13namespace sync_file_system {
14namespace drive_backend {
15
16class FileMetadata;
17class FileTracker;
18class TrackerIDSet;
19
20struct ParentIDAndTitle {
21  int64 parent_id;
22  std::string title;
23
24  ParentIDAndTitle();
25  ParentIDAndTitle(int64 parent_id, const std::string& title);
26};
27
28bool operator==(const ParentIDAndTitle& left, const ParentIDAndTitle& right);
29bool operator<(const ParentIDAndTitle& left, const ParentIDAndTitle& right);
30
31// Interface class to maintain indexes of MetadataDatabase.
32class MetadataDatabaseIndexInterface {
33 public:
34  MetadataDatabaseIndexInterface() {}
35  virtual ~MetadataDatabaseIndexInterface() {}
36
37  // Returns true if FileMetadata identified by |file_id| exists.
38  // If |metadata| is not NULL, the FileMetadata is copied to it.
39  virtual bool GetFileMetadata(
40      const std::string& file_id, FileMetadata* metadata) const = 0;
41
42  // Returns true if FileTracker identified by |tracker_id| exists.
43  // If |tracker| is not NULL, the FileTracker is copied to it.
44  virtual bool GetFileTracker(
45      int64 tracker_id, FileTracker* tracker) const = 0;
46
47  // Stores |metadata| and updates indexes.
48  // This overwrites existing FileMetadata for the same |file_id|.
49  virtual void StoreFileMetadata(scoped_ptr<FileMetadata> metadata) = 0;
50
51  // Stores |tracker| and updates indexes.
52  // This overwrites existing FileTracker for the same |tracker_id|.
53  virtual void StoreFileTracker(scoped_ptr<FileTracker> tracker) = 0;
54
55  // Removes FileMetadata identified by |file_id| from indexes.
56  virtual void RemoveFileMetadata(const std::string& file_id) = 0;
57
58  // Removes FileTracker identified by |tracker_id| from indexes.
59  virtual void RemoveFileTracker(int64 tracker_id) = 0;
60
61  // Returns a set of FileTracker that have |file_id| as its own.
62  virtual TrackerIDSet GetFileTrackerIDsByFileID(
63      const std::string& file_id) const = 0;
64
65  // Returns an app-root tracker identified by |app_id|.  Returns 0 if not
66  // found.
67  virtual int64 GetAppRootTracker(const std::string& app_id) const = 0;
68
69  // Returns a set of FileTracker that have |parent_tracker_id| and |title|.
70  virtual TrackerIDSet GetFileTrackerIDsByParentAndTitle(
71      int64 parent_tracker_id,
72      const std::string& title) const = 0;
73
74  virtual std::vector<int64> GetFileTrackerIDsByParent(
75      int64 parent_tracker_id) const = 0;
76
77  // Returns the |file_id| of a file that has multiple trackers.
78  virtual std::string PickMultiTrackerFileID() const = 0;
79
80  // Returns a pair of |parent_tracker_id| and |title| that has multiple file
81  // at the path.
82  virtual ParentIDAndTitle PickMultiBackingFilePath() const = 0;
83
84  // Returns a FileTracker whose |dirty| is set and which isn't demoted.
85  // Returns 0 if not found.
86  virtual int64 PickDirtyTracker() const = 0;
87
88  // Demotes a dirty tracker.
89  virtual void DemoteDirtyTracker(int64 tracker_id) = 0;
90
91  virtual bool HasDemotedDirtyTracker() const = 0;
92
93  // Promotes single demoted dirty tracker to a normal dirty tracker.
94  virtual void PromoteDemotedDirtyTracker(int64 tracker_id) = 0;
95
96  // Promotes all demoted dirty trackers to normal dirty trackers.
97  // Returns true if any tracker was promoted.
98  virtual bool PromoteDemotedDirtyTrackers() = 0;
99
100  virtual size_t CountDirtyTracker() const = 0;
101  virtual size_t CountFileMetadata() const = 0;
102  virtual size_t CountFileTracker() const = 0;
103
104  virtual void SetSyncRootTrackerID(int64 sync_root_id) const = 0;
105  virtual void SetLargestChangeID(int64 largest_change_id) const = 0;
106  virtual void SetNextTrackerID(int64 next_tracker_id) const = 0;
107  virtual int64 GetSyncRootTrackerID() const = 0;
108  virtual int64 GetLargestChangeID() const = 0;
109  virtual int64 GetNextTrackerID() const = 0;
110  virtual std::vector<std::string> GetRegisteredAppIDs() const = 0;
111  virtual std::vector<int64> GetAllTrackerIDs() const = 0;
112  virtual std::vector<std::string> GetAllMetadataIDs() const = 0;
113
114 private:
115  DISALLOW_COPY_AND_ASSIGN(MetadataDatabaseIndexInterface);
116};
117
118}  // namespace drive_backend
119}  // namespace sync_file_system
120
121#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_INTERFACE_H_
122