| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "components/leveldb/leveldb_database_impl.h" | 5 #include "components/leveldb/leveldb_database_impl.h" |
| 6 | 6 |
| 7 #include <map> |
| 8 #include <string> |
| 9 |
| 7 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 8 #include "components/leveldb/env_mojo.h" | 11 #include "components/leveldb/env_mojo.h" |
| 9 #include "components/leveldb/util.h" | 12 #include "components/leveldb/util.h" |
| 10 #include "mojo/common/common_type_converters.h" | 13 #include "mojo/common/common_type_converters.h" |
| 11 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 14 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 12 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 15 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
| 13 | 16 |
| 14 namespace leveldb { | 17 namespace leveldb { |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 db_->ReleaseSnapshot(it->second); | 103 db_->ReleaseSnapshot(it->second); |
| 101 snapshot_map_.erase(it); | 104 snapshot_map_.erase(it); |
| 102 } | 105 } |
| 103 } | 106 } |
| 104 | 107 |
| 105 void LevelDBDatabaseImpl::GetFromSnapshot(uint64_t snapshot_id, | 108 void LevelDBDatabaseImpl::GetFromSnapshot(uint64_t snapshot_id, |
| 106 mojo::Array<uint8_t> key, | 109 mojo::Array<uint8_t> key, |
| 107 const GetCallback& callback) { | 110 const GetCallback& callback) { |
| 108 // If the snapshot id is invalid, send back invalid argument | 111 // If the snapshot id is invalid, send back invalid argument |
| 109 auto it = snapshot_map_.find(snapshot_id); | 112 auto it = snapshot_map_.find(snapshot_id); |
| 110 if (it == snapshot_map_.end()) | 113 if (it == snapshot_map_.end()) { |
| 111 callback.Run(DatabaseError::INVALID_ARGUMENT, mojo::Array<uint8_t>()); | 114 callback.Run(DatabaseError::INVALID_ARGUMENT, mojo::Array<uint8_t>()); |
| 115 return; |
| 116 } |
| 112 | 117 |
| 113 std::string value; | 118 std::string value; |
| 114 leveldb::ReadOptions options; | 119 leveldb::ReadOptions options; |
| 115 options.snapshot = it->second; | 120 options.snapshot = it->second; |
| 116 leveldb::Status status = db_->Get(options, GetSliceFor(key), &value); | 121 leveldb::Status status = db_->Get(options, GetSliceFor(key), &value); |
| 117 callback.Run(LeveldbStatusToError(status), mojo::Array<uint8_t>::From(value)); | 122 callback.Run(LeveldbStatusToError(status), mojo::Array<uint8_t>::From(value)); |
| 118 } | 123 } |
| 119 | 124 |
| 120 } // namespace leveldb | 125 } // namespace leveldb |
| OLD | NEW |