metadata_database_index_interface.h revision 6d86b77056ed63eb6871182f42a9fd5f07550f90
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 FileMetadata identified by |file_id| if exists, otherwise returns
38  // NULL.
39  virtual const FileMetadata* GetFileMetadata(
40      const std::string& file_id) const = 0;
41
42  // Returns FileTracker identified by |tracker_id| if exists, otherwise returns
43  // NULL.
44  virtual const FileTracker* GetFileTracker(int64 tracker_id) const = 0;
45
46  // Stores |metadata| and updates indexes.
47  // This overwrites existing FileMetadata for the same |file_id|.
48  virtual void StoreFileMetadata(scoped_ptr<FileMetadata> metadata) = 0;
49
50  // Stores |tracker| and updates indexes.
51  // This overwrites existing FileTracker for the same |tracker_id|.
52  virtual void StoreFileTracker(scoped_ptr<FileTracker> tracker) = 0;
53
54  // Removes FileMetadata identified by |file_id| from indexes.
55  virtual void RemoveFileMetadata(const std::string& file_id) = 0;
56
57  // Removes FileTracker identified by |tracker_id| from indexes.
58  virtual void RemoveFileTracker(int64 tracker_id) = 0;
59
60  // Returns a set of FileTracker that have |file_id| as its own.
61  virtual TrackerIDSet GetFileTrackerIDsByFileID(
62      const std::string& file_id) const = 0;
63
64  // Returns an app-root tracker identified by |app_id|.  Returns 0 if not
65  // found.
66  virtual int64 GetAppRootTracker(const std::string& app_id) const = 0;
67
68  // Returns a set of FileTracker that have |parent_tracker_id| and |title|.
69  virtual TrackerIDSet GetFileTrackerIDsByParentAndTitle(
70      int64 parent_tracker_id,
71      const std::string& title) const = 0;
72
73  virtual std::vector<int64> GetFileTrackerIDsByParent(
74      int64 parent_tracker_id) const = 0;
75
76  // Returns the |file_id| of a file that has multiple trackers.
77  virtual std::string PickMultiTrackerFileID() const = 0;
78
79  // Returns a pair of |parent_tracker_id| and |title| that has multiple file
80  // at the path.
81  virtual ParentIDAndTitle PickMultiBackingFilePath() const = 0;
82
83  // Returns a FileTracker whose |dirty| is set and which isn't demoted.
84  // Returns 0 if not found.
85  virtual int64 PickDirtyTracker() const = 0;
86
87  // Demotes a dirty tracker.
88  virtual void DemoteDirtyTracker(int64 tracker_id) = 0;
89
90  virtual bool HasDemotedDirtyTracker() const = 0;
91
92  // Promotes all demoted dirty trackers to normal dirty trackers.
93  virtual void PromoteDemotedDirtyTrackers() = 0;
94
95  virtual size_t CountDirtyTracker() const = 0;
96  virtual size_t CountFileMetadata() const = 0;
97  virtual size_t CountFileTracker() const = 0;
98
99  virtual std::vector<std::string> GetRegisteredAppIDs() const = 0;
100  virtual std::vector<int64> GetAllTrackerIDs() const = 0;
101  virtual std::vector<std::string> GetAllMetadataIDs() const = 0;
102
103 private:
104  DISALLOW_COPY_AND_ASSIGN(MetadataDatabaseIndexInterface);
105};
106
107}  // namespace drive_backend
108}  // namespace sync_file_system
109
110#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_INDEX_INTERFACE_H_
111