// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_ #include "base/files/file_path.h" #include "base/gtest_prod_util.h" #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted_memory.h" #include "base/sequence_checker.h" #include "base/strings/cstring_view.h" #include "base/synchronization/lock.h" #include "base/time/time.h" #include "base/timer/timer.h" #include "chrome/browser/extensions/activity_log/activity_actions.h" #include "extensions/common/extension.h" #include "sql/database.h" namespace base { class FilePath; } namespace extensions { // 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 the constructor need to be called on the DB thread. // // Object ownership and lifetime is a bit complicated for ActivityLog, // ActivityLogPolicy, and ActivityDatabase: // // ActivityLog ----> ActivityLogPolicy ----> ActivityDatabase // ^ | // | | // \--(ActivityDatabase::Delegate)-/ // // The ActivityLogPolicy object contains a pointer to the ActivityDatabase, and // the ActivityDatabase contains a pointer back to the ActivityLogPolicy object // (as an instance of ActivityDatabase::Delegate). // // Since some cleanup must happen on the database thread, deletion should occur // as follows: // 1. ActivityLog calls ActivityLogPolicy::Close() // 2. ActivityLogPolicy should call ActivityDatabase::Close() on the database // thread. // 3. ActivityDatabase::Close() shuts down the database, then calls // ActivityDatabase::Delegate::OnDatabaseClose(). // 4. ActivityDatabase::Delegate::OnDatabaseClose() should delete the // ActivityLogPolicy object. // 5. ActivityDatabase::Close() finishes running by deleting the // ActivityDatabase object. // // (This assumes the common case that the ActivityLogPolicy uses an // ActivityDatabase and implements the ActivityDatabase::Delegate interface. // It is also possible for an ActivityLogPolicy to not use a database at all, // in which case ActivityLogPolicy::Close() should directly delete itself.) class ActivityDatabase { … }; } // namespace extensions #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_DATABASE_H_