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> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/optional.h" | 10 #include "base/optional.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 for (; it->Valid(); it->Next()) { | 27 for (; it->Valid(); it->Next()) { |
28 if (!it->key().starts_with(key_prefix)) | 28 if (!it->key().starts_with(key_prefix)) |
29 break; | 29 break; |
30 function(it->key(), it->value()); | 30 function(it->key(), it->value()); |
31 } | 31 } |
32 return it->status(); | 32 return it->status(); |
33 } | 33 } |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 LevelDBDatabaseImpl::LevelDBDatabaseImpl( | 37 LevelDBDatabaseImpl::LevelDBDatabaseImpl(std::unique_ptr<Env> owned_environment, |
38 std::unique_ptr<leveldb::Env> environment, | 38 std::unique_ptr<DB> db) |
39 std::unique_ptr<leveldb::DB> db) | 39 : owned_environment_(std::move(owned_environment)), db_(std::move(db)) {} |
40 : environment_(std::move(environment)), db_(std::move(db)) {} | 40 |
41 LevelDBDatabaseImpl::LevelDBDatabaseImpl(MojoEnv* environment, | |
42 std::string directory_prefix, | |
43 std::unique_ptr<leveldb::DB> db) | |
44 : environment_(environment), | |
45 directory_prefix_(std::move(directory_prefix)), | |
46 db_(std::move(db)) {} | |
41 | 47 |
42 LevelDBDatabaseImpl::~LevelDBDatabaseImpl() { | 48 LevelDBDatabaseImpl::~LevelDBDatabaseImpl() { |
43 for (auto& p : iterator_map_) | 49 for (auto& p : iterator_map_) |
44 delete p.second; | 50 delete p.second; |
45 for (auto& p : snapshot_map_) | 51 for (auto& p : snapshot_map_) |
46 db_->ReleaseSnapshot(p.second); | 52 db_->ReleaseSnapshot(p.second); |
53 if (environment_) { | |
54 environment_->UnregisterDirectory(directory_prefix_); | |
michaeln
2017/03/27 20:24:10
oh, the unreg call is far removed from the reg cal
Marijn Kruisselbrink
2017/03/31 23:26:24
Yeah, before unreg happened in ~MojoEnv, but now t
| |
55 } | |
47 } | 56 } |
48 | 57 |
49 void LevelDBDatabaseImpl::Put(const std::vector<uint8_t>& key, | 58 void LevelDBDatabaseImpl::Put(const std::vector<uint8_t>& key, |
50 const std::vector<uint8_t>& value, | 59 const std::vector<uint8_t>& value, |
51 const PutCallback& callback) { | 60 const PutCallback& callback) { |
52 leveldb::Status status = | 61 leveldb::Status status = |
53 db_->Put(leveldb::WriteOptions(), GetSliceFor(key), GetSliceFor(value)); | 62 db_->Put(leveldb::WriteOptions(), GetSliceFor(key), GetSliceFor(value)); |
54 callback.Run(LeveldbStatusToError(status)); | 63 callback.Run(LeveldbStatusToError(status)); |
55 } | 64 } |
56 | 65 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 const leveldb::Slice& key_prefix, | 295 const leveldb::Slice& key_prefix, |
287 leveldb::WriteBatch* batch) { | 296 leveldb::WriteBatch* batch) { |
288 leveldb::Status status = ForEachWithPrefix(db_.get(), key_prefix, | 297 leveldb::Status status = ForEachWithPrefix(db_.get(), key_prefix, |
289 [batch](const leveldb::Slice& key, const leveldb::Slice& value) { | 298 [batch](const leveldb::Slice& key, const leveldb::Slice& value) { |
290 batch->Delete(key); | 299 batch->Delete(key); |
291 }); | 300 }); |
292 return status; | 301 return status; |
293 } | 302 } |
294 | 303 |
295 } // namespace leveldb | 304 } // namespace leveldb |
OLD | NEW |