| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LEVELDB_WRAPPER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LEVELDB_WRAPPER_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LEVELDB_WRAPPER_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LEVELDB_WRAPPER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
| 11 #include <string> | 12 #include <string> |
| 12 | 13 |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "third_party/leveldatabase/src/include/leveldb/slice.h" | 15 #include "third_party/leveldatabase/src/include/leveldb/slice.h" |
| 16 | 16 |
| 17 namespace leveldb { | 17 namespace leveldb { |
| 18 class DB; | 18 class DB; |
| 19 class Iterator; | 19 class Iterator; |
| 20 class Slice; | 20 class Slice; |
| 21 class Status; | 21 class Status; |
| 22 class WriteBatch; | 22 class WriteBatch; |
| 23 } | 23 } |
| 24 | 24 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 void Next(); | 60 void Next(); |
| 61 void Delete(); | 61 void Delete(); |
| 62 leveldb::Slice key(); | 62 leveldb::Slice key(); |
| 63 leveldb::Slice value(); | 63 leveldb::Slice value(); |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 // Advances internal iterators to be valid. | 66 // Advances internal iterators to be valid. |
| 67 void AdvanceIterators(); | 67 void AdvanceIterators(); |
| 68 | 68 |
| 69 LevelDBWrapper* db_; // do not own | 69 LevelDBWrapper* db_; // do not own |
| 70 scoped_ptr<leveldb::Iterator> db_iterator_; | 70 std::unique_ptr<leveldb::Iterator> db_iterator_; |
| 71 PendingOperationMap::iterator map_iterator_; | 71 PendingOperationMap::iterator map_iterator_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(Iterator); | 73 DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 explicit LevelDBWrapper(scoped_ptr<leveldb::DB> db); | 76 explicit LevelDBWrapper(std::unique_ptr<leveldb::DB> db); |
| 77 ~LevelDBWrapper(); | 77 ~LevelDBWrapper(); |
| 78 | 78 |
| 79 // Wrapping methods of leveldb::WriteBatch | 79 // Wrapping methods of leveldb::WriteBatch |
| 80 void Put(const std::string& key, const std::string& value); | 80 void Put(const std::string& key, const std::string& value); |
| 81 void Delete(const std::string& key); | 81 void Delete(const std::string& key); |
| 82 | 82 |
| 83 // Wrapping methods of leveldb::DB | 83 // Wrapping methods of leveldb::DB |
| 84 leveldb::Status Get(const std::string& key, std::string* value); | 84 leveldb::Status Get(const std::string& key, std::string* value); |
| 85 scoped_ptr<Iterator> NewIterator(); | 85 std::unique_ptr<Iterator> NewIterator(); |
| 86 | 86 |
| 87 // Commits pending transactions to |db_| and clears cached transactions. | 87 // Commits pending transactions to |db_| and clears cached transactions. |
| 88 // Returns true if the commitment succeeds. | 88 // Returns true if the commitment succeeds. |
| 89 leveldb::Status Commit(); | 89 leveldb::Status Commit(); |
| 90 | 90 |
| 91 // Clears pending transactions. | 91 // Clears pending transactions. |
| 92 void Clear(); | 92 void Clear(); |
| 93 | 93 |
| 94 // Returns the number of pending PUT/DELETE operations. | 94 // Returns the number of pending PUT/DELETE operations. |
| 95 // Each counter counts operations independently, so operations on a key | 95 // Each counter counts operations independently, so operations on a key |
| 96 // may be counted more than once. | 96 // may be counted more than once. |
| 97 int64_t num_puts() { return num_puts_; } | 97 int64_t num_puts() { return num_puts_; } |
| 98 int64_t num_deletes() { return num_deletes_; } | 98 int64_t num_deletes() { return num_deletes_; } |
| 99 | 99 |
| 100 // TODO(peria): Rename this method to GetLevelDBForTesting, after removing | 100 // TODO(peria): Rename this method to GetLevelDBForTesting, after removing |
| 101 // usages of drive_backend::MigrateDatabaseFromVxToVy() under | 101 // usages of drive_backend::MigrateDatabaseFromVxToVy() under |
| 102 // drive_backend_v1/. | 102 // drive_backend_v1/. |
| 103 leveldb::DB* GetLevelDB(); | 103 leveldb::DB* GetLevelDB(); |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 scoped_ptr<leveldb::DB> db_; | 106 std::unique_ptr<leveldb::DB> db_; |
| 107 | 107 |
| 108 PendingOperationMap pending_; | 108 PendingOperationMap pending_; |
| 109 int64_t num_puts_; | 109 int64_t num_puts_; |
| 110 int64_t num_deletes_; | 110 int64_t num_deletes_; |
| 111 | 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(LevelDBWrapper); | 112 DISALLOW_COPY_AND_ASSIGN(LevelDBWrapper); |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 } // namespace drive_backend | 115 } // namespace drive_backend |
| 116 } // namespace sync_file_system | 116 } // namespace sync_file_system |
| 117 | 117 |
| 118 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LEVELDB_WRAPPER_H_ | 118 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_LEVELDB_WRAPPER_H_ |
| OLD | NEW |