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

Side by Side Diff: components/leveldb_proto/leveldb_database.h

Issue 2340983002: [tracing] Memory dump provider for leveldb_proto (Closed)
Patch Set: Fix test name and IOS build. Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/leveldb_proto/leveldb_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 COMPONENTS_LEVELDB_PROTO_LEVELDB_DATABASE_H_ 5 #ifndef COMPONENTS_LEVELDB_PROTO_LEVELDB_DATABASE_H_
6 #define COMPONENTS_LEVELDB_PROTO_LEVELDB_DATABASE_H_ 6 #define COMPONENTS_LEVELDB_PROTO_LEVELDB_DATABASE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
15 #include "base/threading/thread_collision_warner.h" 15 #include "base/threading/thread_collision_warner.h"
16 #include "base/trace_event/memory_dump_provider.h"
16 17
17 namespace base { 18 namespace base {
18 class HistogramBase; 19 class HistogramBase;
19 } // namespace base 20 } // namespace base
20 21
21 namespace leveldb { 22 namespace leveldb {
22 class DB; 23 class DB;
23 class Env; 24 class Env;
24 struct Options; 25 struct Options;
25 } // namespace leveldb 26 } // namespace leveldb
26 27
27 namespace leveldb_proto { 28 namespace leveldb_proto {
28 29
29 // Interacts with the LevelDB third party module. 30 // Interacts with the LevelDB third party module.
30 // Once constructed, function calls and destruction should all occur on the 31 // Once constructed, function calls and destruction should all occur on the
31 // same thread (not necessarily the same as the constructor). 32 // same thread (not necessarily the same as the constructor).
32 class LevelDB { 33 class LevelDB : base::trace_event::MemoryDumpProvider {
33 public: 34 public:
34 // Constructor. Does *not* open a leveldb - only initialize this class. 35 // Constructor. Does *not* open a leveldb - only initialize this class.
35 // |client_name| is the name of the "client" that owns this instance. Used 36 // |client_name| is the name of the "client" that owns this instance. Used
36 // for UMA statics as so: LevelDB.<value>.<client name>. It is best to not 37 // for UMA statics as so: LevelDB.<value>.<client name>. It is best to not
37 // change once shipped. 38 // change once shipped.
38 explicit LevelDB(const char* client_name); 39 explicit LevelDB(const char* client_name);
39 virtual ~LevelDB(); 40 ~LevelDB() override;
40 41
41 virtual bool InitWithOptions(const base::FilePath& database_dir, 42 virtual bool InitWithOptions(const base::FilePath& database_dir,
42 const leveldb::Options& options); 43 const leveldb::Options& options);
43 virtual bool Init(const base::FilePath& database_dir); 44 virtual bool Init(const base::FilePath& database_dir);
44 virtual bool Save(const base::StringPairs& pairs_to_save, 45 virtual bool Save(const base::StringPairs& pairs_to_save,
45 const std::vector<std::string>& keys_to_remove); 46 const std::vector<std::string>& keys_to_remove);
46 virtual bool Load(std::vector<std::string>* entries); 47 virtual bool Load(std::vector<std::string>* entries);
47 virtual bool Get(const std::string& key, bool* found, std::string* entry); 48 virtual bool Get(const std::string& key, bool* found, std::string* entry);
48 49
49 static bool Destroy(const base::FilePath& database_dir); 50 static bool Destroy(const base::FilePath& database_dir);
50 51
52 // base::trace_event::MemoryDumpProvider implementation.
53 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& dump_args,
54 base::trace_event::ProcessMemoryDump* pmd) override;
55
51 private: 56 private:
52 DFAKE_MUTEX(thread_checker_); 57 DFAKE_MUTEX(thread_checker_);
53 58
54 // The declaration order of these members matters: |db_| depends on |env_| and 59 // The declaration order of these members matters: |db_| depends on |env_| and
55 // therefore has to be destructed first. 60 // therefore has to be destructed first.
56 std::unique_ptr<leveldb::Env> env_; 61 std::unique_ptr<leveldb::Env> env_;
57 std::unique_ptr<leveldb::DB> db_; 62 std::unique_ptr<leveldb::DB> db_;
58 base::HistogramBase* open_histogram_; 63 base::HistogramBase* open_histogram_;
64 // Name of the client shown in chrome://tracing.
65 std::string client_name_;
59 66
60 DISALLOW_COPY_AND_ASSIGN(LevelDB); 67 DISALLOW_COPY_AND_ASSIGN(LevelDB);
61 }; 68 };
62 69
63 } // namespace leveldb_proto 70 } // namespace leveldb_proto
64 71
65 #endif // COMPONENTS_LEVELDB_PROTO_LEVELDB_DATABASE_H_ 72 #endif // COMPONENTS_LEVELDB_PROTO_LEVELDB_DATABASE_H_
OLDNEW
« no previous file with comments | « no previous file | components/leveldb_proto/leveldb_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698