Chromium Code Reviews| Index: third_party/leveldatabase/env_chromium.h |
| diff --git a/third_party/leveldatabase/env_chromium.h b/third_party/leveldatabase/env_chromium.h |
| index d4335810b24496abaf1835a01ada393d9bdbbc43..7f063d055dbc21aba95d1817f9409b8f2af26a89 100644 |
| --- a/third_party/leveldatabase/env_chromium.h |
| +++ b/third_party/leveldatabase/env_chromium.h |
| @@ -6,13 +6,18 @@ |
| #define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
| #include <deque> |
| +#include <functional> |
| +#include <memory> |
| #include <set> |
| #include <string> |
| #include <vector> |
| +#include "base/containers/linked_list.h" |
| #include "base/files/file.h" |
| #include "base/files/file_path.h" |
| +#include "base/macros.h" |
| #include "base/metrics/histogram.h" |
| +#include "leveldb/db.h" |
| #include "leveldb/env.h" |
| #include "port/port_chromium.h" |
| #include "util/mutexlock.h" |
| @@ -230,6 +235,50 @@ class ChromiumEnv : public leveldb::Env, |
| LockTable locks_; |
| }; |
| +// Database registry. Keeps track of all live databases and reports them to |
| +// memory-infra. This class is thread safe. |
| +class DBRegistry { |
| + public: |
| + // Opens a database. Internally calls leveldb::DB::Open(options, name) |
| + // and wraps the result in |DBWrapper| instance (see below). |
| + static leveldb::Status Open(const leveldb::Options& options, |
|
Marijn Kruisselbrink
2017/06/20 23:38:52
drive-by comment: presumably this is supposed to a
ssid
2017/06/20 23:52:13
I don't think we want to replace the existing prov
Marijn Kruisselbrink
2017/06/20 23:58:21
Ah, okay, makes sense. So there will be some magic
DmitrySkiba
2017/06/20 23:59:21
Yup, that's pretty much what we discussed with ssi
|
| + const std::string& name, |
| + leveldb::DB** dbptr); |
| + |
| + static DBRegistry* GetInstance(); |
| + |
| + // DB wrapper that provides extra information about the database. |
| + class DBWrapper : public leveldb::DB { |
| + public: |
| + // DB name that Open() was called with. |
| + virtual const std::string& name() const = 0; |
| + }; |
| + |
| + using DatabaseVisitor = std::function<void(DBWrapper*)>; |
| + |
| + // Calls |visitor| for each live database. Takes a lock, preventing |
| + // any database from being created or destroyed (but doesn't lock the |
| + // databases themselves). |
| + void VisitDatabases(const DatabaseVisitor& visitor); |
| + |
| + private: |
| + class DBWrapperImpl; |
| + class MDP; |
| + |
| + DBRegistry(); |
| + ~DBRegistry(); |
| + |
| + void RegisterDatabase(DBWrapperImpl* database); |
| + void UnregisterDatabase(DBWrapperImpl* database); |
| + |
| + std::unique_ptr<MDP> mdp_; |
| + |
| + base::Lock databases_lock_; |
| + base::LinkedList<DBWrapperImpl> databases_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DBRegistry); |
| +}; |
| + |
| } // namespace leveldb_env |
| #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |