| 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/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "chrome/browser/chromeos/drive/drive.pb.h" | 15 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 16 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 16 #include "chrome/browser/drive/drive_service_interface.h" | 17 #include "chrome/browser/drive/drive_service_interface.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace leveldb { | 23 namespace leveldb { |
| 23 class DB; | 24 class DB; |
| 24 class Iterator; | 25 class Iterator; |
| 25 } | 26 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // Destroys this object. | 133 // Destroys this object. |
| 133 void Destroy(); | 134 void Destroy(); |
| 134 | 135 |
| 135 // Initializes this object. | 136 // Initializes this object. |
| 136 bool Initialize(); | 137 bool Initialize(); |
| 137 | 138 |
| 138 // Collects cache info from trashed resource map DB. | 139 // Collects cache info from trashed resource map DB. |
| 139 void RecoverCacheInfoFromTrashedResourceMap(RecoveredCacheInfoMap* out_info); | 140 void RecoverCacheInfoFromTrashedResourceMap(RecoveredCacheInfoMap* out_info); |
| 140 | 141 |
| 141 // Sets the largest changestamp. | 142 // Sets the largest changestamp. |
| 142 bool SetLargestChangestamp(int64 largest_changestamp); | 143 FileError SetLargestChangestamp(int64 largest_changestamp); |
| 143 | 144 |
| 144 // Gets the largest changestamp. | 145 // Gets the largest changestamp. |
| 145 int64 GetLargestChangestamp(); | 146 FileError GetLargestChangestamp(int64* largest_changestamp); |
| 146 | 147 |
| 147 // Puts the entry to this storage. | 148 // Puts the entry to this storage. |
| 148 bool PutEntry(const ResourceEntry& entry); | 149 FileError PutEntry(const ResourceEntry& entry); |
| 149 | 150 |
| 150 // Gets an entry stored in this storage. | 151 // Gets an entry stored in this storage. |
| 151 bool GetEntry(const std::string& id, ResourceEntry* out_entry); | 152 FileError GetEntry(const std::string& id, ResourceEntry* out_entry); |
| 152 | 153 |
| 153 // Removes an entry from this storage. | 154 // Removes an entry from this storage. |
| 154 bool RemoveEntry(const std::string& id); | 155 FileError RemoveEntry(const std::string& id); |
| 155 | 156 |
| 156 // Returns an object to iterate over entries stored in this storage. | 157 // Returns an object to iterate over entries stored in this storage. |
| 157 scoped_ptr<Iterator> GetIterator(); | 158 scoped_ptr<Iterator> GetIterator(); |
| 158 | 159 |
| 159 // Returns the ID of the parent's child. | 160 // Returns the ID of the parent's child. |
| 160 std::string GetChild(const std::string& parent_id, | 161 FileError GetChild(const std::string& parent_id, |
| 161 const std::string& child_name); | 162 const std::string& child_name, |
| 163 std::string* child_id); |
| 162 | 164 |
| 163 // Returns the IDs of the parent's children. | 165 // Returns the IDs of the parent's children. |
| 164 void GetChildren(const std::string& parent_id, | 166 FileError GetChildren(const std::string& parent_id, |
| 165 std::vector<std::string>* children); | 167 std::vector<std::string>* children); |
| 166 | 168 |
| 167 // Puts the cache entry to this storage. | 169 // Puts the cache entry to this storage. |
| 168 bool PutCacheEntry(const std::string& id, const FileCacheEntry& entry); | 170 FileError PutCacheEntry(const std::string& id, const FileCacheEntry& entry); |
| 169 | 171 |
| 170 // Gets a cache entry stored in this storage. | 172 // Gets a cache entry stored in this storage. |
| 171 bool GetCacheEntry(const std::string& id, FileCacheEntry* out_entry); | 173 FileError GetCacheEntry(const std::string& id, FileCacheEntry* out_entry); |
| 172 | 174 |
| 173 // Removes a cache entry from this storage. | 175 // Removes a cache entry from this storage. |
| 174 bool RemoveCacheEntry(const std::string& id); | 176 FileError RemoveCacheEntry(const std::string& id); |
| 175 | 177 |
| 176 // Returns an object to iterate over cache entries stored in this storage. | 178 // Returns an object to iterate over cache entries stored in this storage. |
| 177 scoped_ptr<CacheEntryIterator> GetCacheEntryIterator(); | 179 scoped_ptr<CacheEntryIterator> GetCacheEntryIterator(); |
| 178 | 180 |
| 179 // Returns the local ID associated with the given resource ID. | 181 // Returns the local ID associated with the given resource ID. |
| 180 bool GetIdByResourceId(const std::string& resource_id, std::string* out_id); | 182 FileError GetIdByResourceId(const std::string& resource_id, |
| 183 std::string* out_id); |
| 181 | 184 |
| 182 private: | 185 private: |
| 183 friend class ResourceMetadataStorageTest; | 186 friend class ResourceMetadataStorageTest; |
| 184 | 187 |
| 185 // To destruct this object, use Destroy(). | 188 // To destruct this object, use Destroy(). |
| 186 ~ResourceMetadataStorage(); | 189 ~ResourceMetadataStorage(); |
| 187 | 190 |
| 188 // Used to implement Destroy(). | 191 // Used to implement Destroy(). |
| 189 void DestroyOnBlockingPool(); | 192 void DestroyOnBlockingPool(); |
| 190 | 193 |
| 191 // Returns a string to be used as a key for child entry. | 194 // Returns a string to be used as a key for child entry. |
| 192 static std::string GetChildEntryKey(const std::string& parent_id, | 195 static std::string GetChildEntryKey(const std::string& parent_id, |
| 193 const std::string& child_name); | 196 const std::string& child_name); |
| 194 | 197 |
| 195 // Puts header. | 198 // Puts header. |
| 196 bool PutHeader(const ResourceMetadataHeader& header); | 199 FileError PutHeader(const ResourceMetadataHeader& header); |
| 197 | 200 |
| 198 // Gets header. | 201 // Gets header. |
| 199 bool GetHeader(ResourceMetadataHeader* out_header); | 202 FileError GetHeader(ResourceMetadataHeader* out_header); |
| 200 | 203 |
| 201 // Checks validity of the data. | 204 // Checks validity of the data. |
| 202 bool CheckValidity(); | 205 bool CheckValidity(); |
| 203 | 206 |
| 204 // Path to the directory where the data is stored. | 207 // Path to the directory where the data is stored. |
| 205 base::FilePath directory_path_; | 208 base::FilePath directory_path_; |
| 206 | 209 |
| 207 bool cache_file_scan_is_needed_; | 210 bool cache_file_scan_is_needed_; |
| 208 | 211 |
| 209 // Entries stored in this storage. | 212 // Entries stored in this storage. |
| 210 scoped_ptr<leveldb::DB> resource_map_; | 213 scoped_ptr<leveldb::DB> resource_map_; |
| 211 | 214 |
| 212 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 215 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 213 | 216 |
| 214 DISALLOW_COPY_AND_ASSIGN(ResourceMetadataStorage); | 217 DISALLOW_COPY_AND_ASSIGN(ResourceMetadataStorage); |
| 215 }; | 218 }; |
| 216 | 219 |
| 217 } // namespace internal | 220 } // namespace internal |
| 218 } // namespace drive | 221 } // namespace drive |
| 219 | 222 |
| 220 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ | 223 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ |
| OLD | NEW |