| 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/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/browser/chromeos/drive/drive.pb.h" | 15 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 15 | 16 |
| 17 namespace base { |
| 18 class SequencedTaskRunner; |
| 19 } |
| 20 |
| 16 namespace leveldb { | 21 namespace leveldb { |
| 17 class DB; | 22 class DB; |
| 18 class Iterator; | 23 class Iterator; |
| 19 } | 24 } |
| 20 | 25 |
| 21 namespace drive { | 26 namespace drive { |
| 22 | 27 |
| 23 class ResourceEntry; | 28 class ResourceEntry; |
| 24 class ResourceMetadataHeader; | 29 class ResourceMetadataHeader; |
| 25 | 30 |
| 31 namespace internal { |
| 32 |
| 26 // Storage for ResourceMetadata which is responsible to manage resource | 33 // Storage for ResourceMetadata which is responsible to manage resource |
| 27 // entries and child-parent relationships between entries. | 34 // entries and child-parent relationships between entries. |
| 28 class ResourceMetadataStorage { | 35 class ResourceMetadataStorage { |
| 29 public: | 36 public: |
| 30 // This should be incremented when incompatibility change is made to DB | 37 // This should be incremented when incompatibility change is made to DB |
| 31 // format. | 38 // format. |
| 32 static const int kDBVersion = 6; | 39 static const int kDBVersion = 6; |
| 33 | 40 |
| 34 // Object to iterate over entries stored in this storage. | 41 // Object to iterate over entries stored in this storage. |
| 35 class Iterator { | 42 class Iterator { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Used to implement Advance(). | 91 // Used to implement Advance(). |
| 85 void AdvanceInternal(); | 92 void AdvanceInternal(); |
| 86 | 93 |
| 87 scoped_ptr<leveldb::Iterator> it_; | 94 scoped_ptr<leveldb::Iterator> it_; |
| 88 std::string resource_id_; | 95 std::string resource_id_; |
| 89 FileCacheEntry entry_; | 96 FileCacheEntry entry_; |
| 90 | 97 |
| 91 DISALLOW_COPY_AND_ASSIGN(CacheEntryIterator); | 98 DISALLOW_COPY_AND_ASSIGN(CacheEntryIterator); |
| 92 }; | 99 }; |
| 93 | 100 |
| 94 explicit ResourceMetadataStorage(const base::FilePath& directory_path); | 101 ResourceMetadataStorage(const base::FilePath& directory_path, |
| 95 virtual ~ResourceMetadataStorage(); | 102 base::SequencedTaskRunner* blocking_task_runner); |
| 103 |
| 104 const base::FilePath& directory_path() const { return directory_path_; } |
| 105 |
| 106 // Destroys this object. |
| 107 void Destroy(); |
| 96 | 108 |
| 97 // Initializes this object. | 109 // Initializes this object. |
| 98 bool Initialize(); | 110 bool Initialize(); |
| 99 | 111 |
| 100 // Sets the largest changestamp. | 112 // Sets the largest changestamp. |
| 101 bool SetLargestChangestamp(int64 largest_changestamp); | 113 bool SetLargestChangestamp(int64 largest_changestamp); |
| 102 | 114 |
| 103 // Gets the largest changestamp. | 115 // Gets the largest changestamp. |
| 104 int64 GetLargestChangestamp(); | 116 int64 GetLargestChangestamp(); |
| 105 | 117 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 132 | 144 |
| 133 // Removes a cache entry from this storage. | 145 // Removes a cache entry from this storage. |
| 134 bool RemoveCacheEntry(const std::string& resource_id); | 146 bool RemoveCacheEntry(const std::string& resource_id); |
| 135 | 147 |
| 136 // Returns an object to iterate over cache entries stored in this storage. | 148 // Returns an object to iterate over cache entries stored in this storage. |
| 137 scoped_ptr<CacheEntryIterator> GetCacheEntryIterator(); | 149 scoped_ptr<CacheEntryIterator> GetCacheEntryIterator(); |
| 138 | 150 |
| 139 private: | 151 private: |
| 140 friend class ResourceMetadataStorageTest; | 152 friend class ResourceMetadataStorageTest; |
| 141 | 153 |
| 154 // To destruct this object, use Destroy(). |
| 155 ~ResourceMetadataStorage(); |
| 156 |
| 157 // Used to implement Destroy(). |
| 158 void DestroyOnBlockingPool(); |
| 159 |
| 142 // Returns a string to be used as a key for child entry. | 160 // Returns a string to be used as a key for child entry. |
| 143 static std::string GetChildEntryKey(const std::string& parent_resource_id, | 161 static std::string GetChildEntryKey(const std::string& parent_resource_id, |
| 144 const std::string& child_name); | 162 const std::string& child_name); |
| 145 | 163 |
| 146 // Puts header. | 164 // Puts header. |
| 147 bool PutHeader(const ResourceMetadataHeader& header); | 165 bool PutHeader(const ResourceMetadataHeader& header); |
| 148 | 166 |
| 149 // Gets header. | 167 // Gets header. |
| 150 bool GetHeader(ResourceMetadataHeader* out_header); | 168 bool GetHeader(ResourceMetadataHeader* out_header); |
| 151 | 169 |
| 152 // Checks validity of the data. | 170 // Checks validity of the data. |
| 153 bool CheckValidity(); | 171 bool CheckValidity(); |
| 154 | 172 |
| 155 // Path to the directory where the data is stored. | 173 // Path to the directory where the data is stored. |
| 156 base::FilePath directory_path_; | 174 base::FilePath directory_path_; |
| 157 | 175 |
| 158 // Entries stored in this storage. | 176 // Entries stored in this storage. |
| 159 scoped_ptr<leveldb::DB> resource_map_; | 177 scoped_ptr<leveldb::DB> resource_map_; |
| 160 | 178 |
| 179 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 180 |
| 161 DISALLOW_COPY_AND_ASSIGN(ResourceMetadataStorage); | 181 DISALLOW_COPY_AND_ASSIGN(ResourceMetadataStorage); |
| 162 }; | 182 }; |
| 163 | 183 |
| 184 } // namespace internal |
| 164 } // namespace drive | 185 } // namespace drive |
| 165 | 186 |
| 166 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ | 187 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_STORAGE_H_ |
| OLD | NEW |