#include "components/favicon/core/favicon_database.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <bit>
#include <string>
#include <tuple>
#include <utility>
#include "base/debug/alias.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h"
#include "base/rand_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/database_utils/upper_bound_string.h"
#include "components/database_utils/url_converter.h"
#include "sql/recovery.h"
#include "sql/statement.h"
#include "sql/transaction.h"
#include "url/origin.h"
#if BUILDFLAG(IS_APPLE)
#include "base/apple/backup_util.h"
#endif
namespace favicon {
namespace {
const int kCurrentVersionNumber = …;
const int kCompatibleVersionNumber = …;
const int kDeprecatedVersionNumber = …;
void FillIconMapping(const GURL& page_url,
sql::Statement& statement,
IconMapping* icon_mapping) { … }
bool InitTables(sql::Database* db) { … }
bool InitIndices(sql::Database* db) { … }
void DatabaseErrorCallback(sql::Database* db,
int extended_error,
sql::Statement* stmt) { … }
}
FaviconDatabase::IconMappingEnumerator::IconMappingEnumerator() { … }
FaviconDatabase::IconMappingEnumerator::~IconMappingEnumerator() { … }
bool FaviconDatabase::IconMappingEnumerator::GetNextIconMapping(
IconMapping* icon_mapping) { … }
FaviconDatabase::FaviconDatabase()
: … { … }
FaviconDatabase::~FaviconDatabase() { … }
sql::InitStatus FaviconDatabase::Init(const base::FilePath& db_name) { … }
void FaviconDatabase::ComputeDatabaseMetrics() { … }
void FaviconDatabase::BeginTransaction() { … }
void FaviconDatabase::CommitTransaction() { … }
void FaviconDatabase::RollbackTransaction() { … }
void FaviconDatabase::Vacuum() { … }
void FaviconDatabase::TrimMemory() { … }
std::map<favicon_base::FaviconID, IconMappingsForExpiry>
FaviconDatabase::GetOldOnDemandFavicons(base::Time threshold) { … }
bool FaviconDatabase::GetFaviconBitmapIDSizes(
favicon_base::FaviconID icon_id,
std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { … }
bool FaviconDatabase::GetFaviconBitmaps(
favicon_base::FaviconID icon_id,
std::vector<FaviconBitmap>* favicon_bitmaps) { … }
bool FaviconDatabase::GetFaviconBitmap(
FaviconBitmapID bitmap_id,
base::Time* last_updated,
base::Time* last_requested,
scoped_refptr<base::RefCountedMemory>* png_icon_data,
gfx::Size* pixel_size) { … }
FaviconBitmapID FaviconDatabase::AddFaviconBitmap(
favicon_base::FaviconID icon_id,
const scoped_refptr<base::RefCountedMemory>& icon_data,
FaviconBitmapType type,
base::Time time,
const gfx::Size& pixel_size) { … }
bool FaviconDatabase::SetFaviconBitmap(
FaviconBitmapID bitmap_id,
scoped_refptr<base::RefCountedMemory> bitmap_data,
base::Time time) { … }
bool FaviconDatabase::SetFaviconBitmapLastUpdateTime(FaviconBitmapID bitmap_id,
base::Time time) { … }
bool FaviconDatabase::SetFaviconsOutOfDateBetween(base::Time begin,
base::Time end) { … }
bool FaviconDatabase::TouchOnDemandFavicon(const GURL& icon_url,
base::Time time) { … }
bool FaviconDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) { … }
bool FaviconDatabase::SetFaviconOutOfDate(favicon_base::FaviconID icon_id) { … }
bool FaviconDatabase::GetFaviconLastUpdatedTime(favicon_base::FaviconID icon_id,
base::Time* last_updated) { … }
favicon_base::FaviconID FaviconDatabase::GetFaviconIDForFaviconURL(
const GURL& icon_url,
favicon_base::IconType icon_type,
const url::Origin& page_origin) { … }
favicon_base::FaviconID FaviconDatabase::GetFaviconIDForFaviconURL(
const GURL& icon_url,
favicon_base::IconType icon_type) { … }
bool FaviconDatabase::GetFaviconHeader(favicon_base::FaviconID icon_id,
GURL* icon_url,
favicon_base::IconType* icon_type) { … }
favicon_base::FaviconID FaviconDatabase::AddFavicon(
const GURL& icon_url,
favicon_base::IconType icon_type) { … }
favicon_base::FaviconID FaviconDatabase::AddFavicon(
const GURL& icon_url,
favicon_base::IconType icon_type,
const scoped_refptr<base::RefCountedMemory>& icon_data,
FaviconBitmapType type,
base::Time time,
const gfx::Size& pixel_size) { … }
bool FaviconDatabase::DeleteFavicon(favicon_base::FaviconID id) { … }
bool FaviconDatabase::GetIconMappingsForPageURL(
const GURL& page_url,
const favicon_base::IconTypeSet& required_icon_types,
std::vector<IconMapping>* filtered_mapping_data) { … }
bool FaviconDatabase::GetIconMappingsForPageURL(
const GURL& page_url,
std::vector<IconMapping>* mapping_data) { … }
std::optional<GURL> FaviconDatabase::FindFirstPageURLForHost(
const GURL& url,
const favicon_base::IconTypeSet& required_icon_types) { … }
IconMappingID FaviconDatabase::AddIconMapping(const GURL& page_url,
favicon_base::FaviconID icon_id) { … }
bool FaviconDatabase::DeleteIconMappings(const GURL& page_url) { … }
bool FaviconDatabase::DeleteIconMappingsForFaviconId(
favicon_base::FaviconID id) { … }
bool FaviconDatabase::DeleteIconMapping(IconMappingID mapping_id) { … }
bool FaviconDatabase::HasMappingFor(favicon_base::FaviconID id) { … }
std::vector<favicon_base::FaviconID>
FaviconDatabase::GetFaviconsLastUpdatedBefore(base::Time time, int max_count) { … }
bool FaviconDatabase::InitIconMappingEnumerator(
favicon_base::IconType type,
IconMappingEnumerator* enumerator) { … }
bool FaviconDatabase::RetainDataForPageUrls(
const std::vector<GURL>& urls_to_keep) { … }
int FaviconDatabase::ToPersistedIconType(favicon_base::IconType icon_type) { … }
favicon_base::IconType FaviconDatabase::FromPersistedIconType(int icon_type) { … }
sql::InitStatus FaviconDatabase::OpenDatabase(sql::Database* db,
const base::FilePath& db_name) { … }
sql::InitStatus FaviconDatabase::InitImpl(const base::FilePath& db_name) { … }
sql::InitStatus FaviconDatabase::CantUpgradeToVersion(int cur_version) { … }
bool FaviconDatabase::UpgradeToVersion7() { … }
bool FaviconDatabase::UpgradeToVersion8() { … }
bool FaviconDatabase::IsFaviconDBStructureIncorrect() { … }
}