[tracing] Add separate dump provider for sql connection
The sql connection memory dump is not thread safe since the connections
can get deleted while a dump is happening. To make this thread safe,
this CL introduces a dump provider class owned by the connection. This
class holds a lock when dumping and deleting the database. Also, to
workaround thread safe dump provider registration, it uses the
UnregisterAndDeleteDumpProviderAsync api added in crrev.com/1430073002.
BUG=466141
Review URL: https://codereview.chromium.org/1434993002
Cr-Commit-Position: refs/heads/master@{#369161}
diff --git a/sql/connection.h b/sql/connection.h
index e121b9fe..b35e2fa 100644
--- a/sql/connection.h
+++ b/sql/connection.h
@@ -20,7 +20,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
-#include "base/trace_event/memory_dump_provider.h"
#include "sql/sql_export.h"
struct sqlite3;
@@ -33,6 +32,7 @@
namespace sql {
+class ConnectionMemoryDumpProvider;
class Recovery;
class Statement;
@@ -105,7 +105,7 @@
DISALLOW_COPY_AND_ASSIGN(TimeSource);
};
-class SQL_EXPORT Connection : public base::trace_event::MemoryDumpProvider {
+class SQL_EXPORT Connection {
private:
class StatementRef; // Forward declaration, see real one below.
@@ -113,7 +113,7 @@
// The database is opened by calling Open[InMemory](). Any uncommitted
// transactions will be rolled back when this object is deleted.
Connection();
- ~Connection() override;
+ ~Connection();
// Pre-init configuration ----------------------------------------------------
@@ -484,11 +484,6 @@
// with the syntax of a SQL statement, or problems with the database schema.
static bool ShouldIgnoreSqliteCompileError(int error);
- // base::trace_event::MemoryDumpProvider implementation.
- bool OnMemoryDump(
- const base::trace_event::MemoryDumpArgs& args,
- base::trace_event::ProcessMemoryDump* process_memory_dump) override;
-
// Collect various diagnostic information and post a crash dump to aid
// debugging. Dump rate per database is limited to prevent overwhelming the
// crash server.
@@ -511,6 +506,7 @@
FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, CollectDiagnosticInfo);
FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, GetAppropriateMmapSize);
+ FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, OnMemoryDump);
FRIEND_TEST_ALL_PREFIXES(SQLConnectionTest, RegisterIntentToUpload);
// Internal initialize function used by both Init and InitInMemory. The file
@@ -795,6 +791,9 @@
// changes.
scoped_ptr<TimeSource> clock_;
+ // Stores the dump provider object when db is open.
+ scoped_ptr<ConnectionMemoryDumpProvider> memory_dump_provider_;
+
DISALLOW_COPY_AND_ASSIGN(Connection);
};