| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ | 
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" | 
| 12 #include "base/callback_forward.h" |  | 
| 13 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" | 
| 14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" | 
|  | 14 #include "chrome/browser/chromeos/drive/drive.pb.h" | 
| 15 | 15 | 
| 16 namespace leveldb { | 16 namespace leveldb { | 
| 17 class DB; | 17 class DB; | 
|  | 18 class Iterator; | 
| 18 } | 19 } | 
| 19 | 20 | 
| 20 namespace drive { | 21 namespace drive { | 
| 21 | 22 | 
| 22 class ResourceEntry; | 23 class ResourceEntry; | 
| 23 class ResourceMetadataHeader; | 24 class ResourceMetadataHeader; | 
| 24 | 25 | 
| 25 typedef base::Callback<void(const ResourceEntry& entry)> IterateCallback; |  | 
| 26 |  | 
| 27 // Storage for ResourceMetadata which is responsible to manage entry info | 26 // Storage for ResourceMetadata which is responsible to manage entry info | 
| 28 // and child-parent relationships between entries. | 27 // and child-parent relationships between entries. | 
| 29 class ResourceMetadataStorage { | 28 class ResourceMetadataStorage { | 
| 30  public: | 29  public: | 
| 31   // This should be incremented when incompatibility change is made to DB | 30   // This should be incremented when incompatibility change is made to DB | 
| 32   // format. | 31   // format. | 
| 33   static const int kDBVersion = 5; | 32   static const int kDBVersion = 5; | 
| 34 | 33 | 
|  | 34   class Iterator { | 
|  | 35    public: | 
|  | 36     explicit Iterator(scoped_ptr<leveldb::Iterator> it); | 
|  | 37     ~Iterator(); | 
|  | 38 | 
|  | 39     // Returns true if this iterator cannot advance any more. | 
|  | 40     bool IsAtEnd() const; | 
|  | 41 | 
|  | 42     // Returns the entry currently pointed by this object. | 
|  | 43     const ResourceEntry& Get() const; | 
|  | 44 | 
|  | 45     // Advances to the next entry. | 
|  | 46     void Advance(); | 
|  | 47 | 
|  | 48     // Returns true if this object has encountered any error. | 
|  | 49     bool HasError() const; | 
|  | 50 | 
|  | 51    private: | 
|  | 52     ResourceEntry entry_; | 
|  | 53     scoped_ptr<leveldb::Iterator> it_; | 
|  | 54 | 
|  | 55     DISALLOW_COPY_AND_ASSIGN(Iterator); | 
|  | 56   }; | 
|  | 57 | 
| 35   explicit ResourceMetadataStorage(const base::FilePath& directory_path); | 58   explicit ResourceMetadataStorage(const base::FilePath& directory_path); | 
| 36   virtual ~ResourceMetadataStorage(); | 59   virtual ~ResourceMetadataStorage(); | 
| 37 | 60 | 
| 38   // Initializes this object. | 61   // Initializes this object. | 
| 39   bool Initialize(); | 62   bool Initialize(); | 
| 40 | 63 | 
| 41   // Sets the largest changestamp. | 64   // Sets the largest changestamp. | 
| 42   bool SetLargestChangestamp(int64 largest_changestamp); | 65   bool SetLargestChangestamp(int64 largest_changestamp); | 
| 43 | 66 | 
| 44   // Gets the largest changestamp. | 67   // Gets the largest changestamp. | 
| 45   int64 GetLargestChangestamp(); | 68   int64 GetLargestChangestamp(); | 
| 46 | 69 | 
| 47   // Puts the entry to this storage. | 70   // Puts the entry to this storage. | 
| 48   bool PutEntry(const ResourceEntry& entry); | 71   bool PutEntry(const ResourceEntry& entry); | 
| 49 | 72 | 
| 50   // Returns an entry stored in this storage. | 73   // Returns an entry stored in this storage. | 
| 51   scoped_ptr<ResourceEntry> GetEntry(const std::string& resource_id); | 74   scoped_ptr<ResourceEntry> GetEntry(const std::string& resource_id); | 
| 52 | 75 | 
| 53   // Removes an entry from this storage. | 76   // Removes an entry from this storage. | 
| 54   bool RemoveEntry(const std::string& resource_id); | 77   bool RemoveEntry(const std::string& resource_id); | 
| 55 | 78 | 
| 56   // Iterates over entries stored in this storage. | 79   // Returns an object to iterate over entries stored in this storage. | 
| 57   void Iterate(const IterateCallback& callback); | 80   scoped_ptr<Iterator> GetIterator(); | 
| 58 | 81 | 
| 59   // Returns resource ID of the parent's child. | 82   // Returns resource ID of the parent's child. | 
| 60   std::string GetChild(const std::string& parent_resource_id, | 83   std::string GetChild(const std::string& parent_resource_id, | 
| 61                        const std::string& child_name); | 84                        const std::string& child_name); | 
| 62 | 85 | 
| 63   // Returns resource IDs of the parent's children. | 86   // Returns resource IDs of the parent's children. | 
| 64   void GetChildren(const std::string& parent_resource_id, | 87   void GetChildren(const std::string& parent_resource_id, | 
| 65                    std::vector<std::string>* children); | 88                    std::vector<std::string>* children); | 
| 66 | 89 | 
| 67  private: | 90  private: | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 85 | 108 | 
| 86   // Entries stored in this storage. | 109   // Entries stored in this storage. | 
| 87   scoped_ptr<leveldb::DB> resource_map_; | 110   scoped_ptr<leveldb::DB> resource_map_; | 
| 88 | 111 | 
| 89   DISALLOW_COPY_AND_ASSIGN(ResourceMetadataStorage); | 112   DISALLOW_COPY_AND_ASSIGN(ResourceMetadataStorage); | 
| 90 }; | 113 }; | 
| 91 | 114 | 
| 92 }  // namespace drive | 115 }  // namespace drive | 
| 93 | 116 | 
| 94 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ | 117 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ | 
| OLD | NEW | 
|---|