[M108 Migration][HBBTV] Implement ewk_context_register_jsplugin_mime_types API
[platform/framework/web/chromium-efl.git] / sql / database_memory_dump_provider.h
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SQL_DATABASE_MEMORY_DUMP_PROVIDER_H_
6 #define SQL_DATABASE_MEMORY_DUMP_PROVIDER_H_
7
8 #include <string>
9
10 #include "base/memory/raw_ptr.h"
11 #include "base/synchronization/lock.h"
12 #include "base/thread_annotations.h"
13 #include "base/trace_event/memory_dump_provider.h"
14
15 struct sqlite3;
16
17 namespace base::trace_event {
18 struct MemoryDumpArgs;
19 class ProcessMemoryDump;
20 }  // namespace base::trace_event
21
22 namespace sql {
23
24 class DatabaseMemoryDumpProvider
25     : public base::trace_event::MemoryDumpProvider {
26  public:
27   DatabaseMemoryDumpProvider(sqlite3* db, const std::string& name);
28
29   DatabaseMemoryDumpProvider(const DatabaseMemoryDumpProvider&) = delete;
30   DatabaseMemoryDumpProvider& operator=(const DatabaseMemoryDumpProvider&) =
31       delete;
32
33   ~DatabaseMemoryDumpProvider() override;
34
35   void ResetDatabase();
36
37   // base::trace_event::MemoryDumpProvider implementation.
38   bool OnMemoryDump(
39       const base::trace_event::MemoryDumpArgs& args,
40       base::trace_event::ProcessMemoryDump* process_memory_dump) override;
41
42   // Reports memory usage into provided memory dump with the given |dump_name|.
43   // Called by sql::Database when its owner asks it to report memory usage.
44   bool ReportMemoryUsage(base::trace_event::ProcessMemoryDump* pmd,
45                          const std::string& dump_name);
46
47  private:
48   struct MemoryUsageResult {
49     bool is_valid = false;
50     int cache_size = 0;
51     int schema_size = 0;
52     int statement_size = 0;
53   };
54   MemoryUsageResult GetDbMemoryUsage();
55
56   std::string FormatDumpName() const;
57
58   base::Lock lock_;
59   raw_ptr<sqlite3> db_ GUARDED_BY_CONTEXT(lock_);  // not owned.
60   const std::string connection_name_;
61 };
62
63 }  // namespace sql
64
65 #endif  // SQL_DATABASE_MEMORY_DUMP_PROVIDER_H_