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

Unified Diff: chrome/browser/extensions/activity_log/activity_database.h

Issue 18660004: Extension activity log database refactoring (step 1) (Closed) Base URL: http://git.chromium.org/chromium/src.git@incognito-tests
Patch Set: Fix potential null pointer dereference Created 7 years, 5 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
Index: chrome/browser/extensions/activity_log/activity_database.h
diff --git a/chrome/browser/extensions/activity_log/activity_database.h b/chrome/browser/extensions/activity_log/activity_database.h
index 8c3c42fae1bd993390c0f22c5accb03dbc11afb3..609eeb0f7d5f9a709bec873250b973933d21ea92 100644
--- a/chrome/browser/extensions/activity_log/activity_database.h
+++ b/chrome/browser/extensions/activity_log/activity_database.h
@@ -27,6 +27,29 @@ class FilePath;
namespace extensions {
+// Interface defining callbacks that the ActivityDatabase can make into a
+// higher-level ActivityLogPolicy instance. Callbacks are always invoked on
+// the database thread. Classes other than ActivityDatabase should not call
+// these methods.
+class ActivityDatabaseCallbacks {
Matt Perry 2013/07/10 23:19:30 I would not refer to this class or its methods as
mvrable 2013/07/11 17:30:33 I've tried renaming this to be an inner class, Act
+ protected:
+ friend class ActivityDatabase;
+
+ // Initializes the database schema; this gives a policy a change to create or
Matt Perry 2013/07/10 23:19:30 chance*
mvrable 2013/07/11 17:30:33 Done.
+ // update database tables as needed. Should return true on success.
+ virtual bool DatabaseInitCallback(sql::Connection* db) = 0;
+
+ // Called by ActivityDatabase just before the ActivityDatabase object is
+ // deleted. The database will make no further callbacks after invoking this
+ // method, so it is an appropriate time for the policy to delete itself.
+ virtual void DatabaseCloseCallback() = 0;
+
+ // An ActivityDatabaseCallbacks instance should not be deleted directly; it
+ // is instead deleted by the ActivityDatabase which calls the Cleanup()
+ // method.
+ virtual ~ActivityDatabaseCallbacks() {}
+};
+
// Encapsulates the SQL connection for the activity log database.
// This class holds the database connection and has methods for writing.
// All of the methods except constructor need to be
@@ -35,9 +58,10 @@ namespace extensions {
class ActivityDatabase {
public:
// Need to call Init to actually use the ActivityDatabase.
- ActivityDatabase();
+ explicit ActivityDatabase(ActivityDatabaseCallbacks* callbacks);
- // Opens the DB and creates tables as necessary.
+ // Opens the DB. Calls DatabaseInitCallback in the policy callbacks, which
+ // is responsible for creating or updating the database schema if needed.
void Init(const base::FilePath& db_name);
// The ActivityLog should call this to kill the ActivityDatabase.
@@ -100,6 +124,7 @@ class ActivityDatabase {
// For unit testing only.
void RecordBatchedActionsWhileTesting();
+ ActivityDatabaseCallbacks* policy_callbacks_;
base::Clock* testing_clock_;
sql::Connection db_;
bool valid_db_;

Powered by Google App Engine
This is Rietveld 408576698