Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: third_party/leveldatabase/env_chromium.h

Issue 2855953002: leveldb: Add DBTracker for exposing databases to Chrome's memory-infra. (Closed)
Patch Set: Address comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/leveldatabase/env_chromium.cc » ('j') | third_party/leveldatabase/env_chromium.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
pwnall 2017/06/22 02:50:22 I'd prefer that Open() and VisitOpenDatabases() be
DmitrySkiba 2017/06/26 20:45:18 Renaming: done. I'm not sure about free-standing
pwnall 2017/06/26 23:37:13 This comment (that I agree with) suggests that lev
DmitrySkiba 2017/06/28 20:35:28 Done.
+ public:
+ // Opens a database. Internally calls leveldb::DB::Open(options, name)
pwnall 2017/06/22 02:50:22 Can you please write the docs from the perspective
DmitrySkiba 2017/06/26 20:45:19 Done.
+ // and wraps the result in |DBWrapper| instance (see below).
+ static leveldb::Status Open(const leveldb::Options& options,
+ 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;
pwnall 2017/06/22 02:50:22 Do you envision adding more functionality here, su
DmitrySkiba 2017/06/26 20:45:19 Yes, more stuff is planned: visiting iterators, ex
pwnall 2017/06/26 23:37:13 How about TrackedDB instead of DB for the name, th
DmitrySkiba 2017/06/28 20:35:28 Done.
+ };
+
+ using DatabaseVisitor = std::function<void(DBWrapper*)>;
pwnall 2017/06/22 02:50:22 Visitor?
DmitrySkiba 2017/06/26 20:45:18 I think that if method is called VisitDatabases(),
pwnall 2017/06/26 23:37:13 I thought Visitor is acceptable if this is the onl
DmitrySkiba 2017/06/28 20:35:28 Acknowledged.
+
+ // 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);
pwnall 2017/06/22 02:50:22 VisitOpenDatabases?
DmitrySkiba 2017/06/26 20:45:19 I feel that 'Open' is redundant, since it's the on
pwnall 2017/06/26 23:37:13 It is, once you've thought things through. However
DmitrySkiba 2017/06/28 20:35:28 I think this is job for comments, so I updated the
+
+ private:
+ class DBWrapperImpl;
+ class MDP;
pwnall 2017/06/22 02:50:22 Can you please use the full name MemoryDumpProvide
DmitrySkiba 2017/06/26 20:45:19 Done.
+
+ 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_
« no previous file with comments | « no previous file | third_party/leveldatabase/env_chromium.cc » ('j') | third_party/leveldatabase/env_chromium.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698