#include "components/power_bookmarks/storage/power_bookmark_database_impl.h"
#include "base/check.h"
#include "base/files/file_util.h"
#include "base/notreached.h"
#include "base/strings/pattern.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "components/power_bookmarks/common/power_bookmark_metrics.h"
#include "components/power_bookmarks/common/search_params.h"
#include "components/power_bookmarks/storage/power_bookmark_sync_metadata_database.h"
#include "components/sync/protocol/power_bookmark_specifics.pb.h"
#include "sql/error_delegate_util.h"
#include "sql/statement.h"
#include "sql/transaction.h"
#include "url/origin.h"
namespace power_bookmarks {
namespace {
const int kCurrentVersionNumber = …;
const int kCompatibleVersionNumber = …;
static constexpr char kSaveTableName[] = …;
static constexpr char kBlobTableName[] = …;
std::unique_ptr<Power> CreatePowerFromSpecifics(
const sync_pb::PowerBookmarkSpecifics& specifics) { … }
bool CheckIfPowerWithIdExists(sql::Database* db, const base::Uuid& guid) { … }
bool MatchPattern(std::string field, std::string pattern, bool case_sensitive) { … }
bool MatchesSearchQuery(const sync_pb::PowerBookmarkSpecifics& specifics,
const std::string& query,
bool case_sensitive) { … }
bool MatchesSearchParams(const sync_pb::PowerBookmarkSpecifics& specifics,
const SearchParams& search_params) { … }
class SqliteDatabaseTransaction : public Transaction { … };
SqliteDatabaseTransaction::SqliteDatabaseTransaction(sql::Database& db)
: … { … }
SqliteDatabaseTransaction::~SqliteDatabaseTransaction() { … }
bool SqliteDatabaseTransaction::Begin() { … }
bool SqliteDatabaseTransaction::Commit() { … }
}
PowerBookmarkDatabaseImpl::PowerBookmarkDatabaseImpl(
const base::FilePath& database_dir)
: … { … }
PowerBookmarkDatabaseImpl::~PowerBookmarkDatabaseImpl() { … }
bool PowerBookmarkDatabaseImpl::Init() { … }
bool PowerBookmarkDatabaseImpl::IsOpen() { … }
void PowerBookmarkDatabaseImpl::DatabaseErrorCallback(int error,
sql::Statement* stmt) { … }
bool PowerBookmarkDatabaseImpl::InitSchema() { … }
bool PowerBookmarkDatabaseImpl::CreateSchema() { … }
std::vector<std::unique_ptr<Power>> PowerBookmarkDatabaseImpl::GetPowersForURL(
const GURL& url,
const sync_pb::PowerBookmarkSpecifics::PowerType& power_type) { … }
std::vector<std::unique_ptr<PowerOverview>>
PowerBookmarkDatabaseImpl::GetPowerOverviewsForType(
const sync_pb::PowerBookmarkSpecifics::PowerType& power_type) { … }
std::vector<std::unique_ptr<Power>>
PowerBookmarkDatabaseImpl::GetPowersForSearchParams(
const SearchParams& search_params) { … }
std::vector<std::unique_ptr<PowerOverview>>
PowerBookmarkDatabaseImpl::GetPowerOverviewsForSearchParams(
const SearchParams& search_params) { … }
bool PowerBookmarkDatabaseImpl::CreatePower(std::unique_ptr<Power> power) { … }
std::unique_ptr<Power> PowerBookmarkDatabaseImpl::UpdatePower(
std::unique_ptr<Power> power) { … }
bool PowerBookmarkDatabaseImpl::DeletePower(const base::Uuid& guid) { … }
bool PowerBookmarkDatabaseImpl::DeletePowersForURL(
const GURL& url,
const sync_pb::PowerBookmarkSpecifics::PowerType& power_type,
std::vector<std::string>* deleted_guids) { … }
std::vector<std::unique_ptr<Power>>
PowerBookmarkDatabaseImpl::GetPowersForGUIDs(
const std::vector<std::string>& guids) { … }
std::vector<std::unique_ptr<Power>> PowerBookmarkDatabaseImpl::GetAllPowers() { … }
std::unique_ptr<Power> PowerBookmarkDatabaseImpl::GetPowerForGUID(
const std::string& guid) { … }
bool PowerBookmarkDatabaseImpl::CreateOrMergePowerFromSync(const Power& power) { … }
bool PowerBookmarkDatabaseImpl::DeletePowerFromSync(const std::string& guid) { … }
PowerBookmarkSyncMetadataDatabase*
PowerBookmarkDatabaseImpl::GetSyncMetadataDatabase() { … }
std::optional<sync_pb::PowerBookmarkSpecifics>
PowerBookmarkDatabaseImpl::DeserializeOrDelete(const std::string& data,
const base::Uuid& id) { … }
std::vector<std::string> PowerBookmarkDatabaseImpl::GetGUIDsForURL(
const GURL& url,
const sync_pb::PowerBookmarkSpecifics::PowerType& power_type) { … }
bool PowerBookmarkDatabaseImpl::CreatePowerInternal(const Power& power) { … }
bool PowerBookmarkDatabaseImpl::UpdatePowerInternal(const Power& power) { … }
bool PowerBookmarkDatabaseImpl::DeletePowerInternal(const base::Uuid& guid) { … }
std::unique_ptr<Transaction> PowerBookmarkDatabaseImpl::BeginTransaction() { … }
}