From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- toolkit/components/places/FaviconHelpers.cpp | 101 ++++++++++++--------------- 1 file changed, 45 insertions(+), 56 deletions(-) (limited to 'toolkit/components/places/FaviconHelpers.cpp') diff --git a/toolkit/components/places/FaviconHelpers.cpp b/toolkit/components/places/FaviconHelpers.cpp index 1c565a3de1..df06885e1f 100644 --- a/toolkit/components/places/FaviconHelpers.cpp +++ b/toolkit/components/places/FaviconHelpers.cpp @@ -959,6 +959,49 @@ AsyncAssociateIconToPage::Run() { return NS_OK; } +//////////////////////////////////////////////////////////////////////////////// +//// AsyncSetIconForPage + +AsyncSetIconForPage::AsyncSetIconForPage(const IconData& aIcon, + const PageData& aPage, + PlacesCompletionCallback* aCallback) + : Runnable("places::AsyncSetIconForPage"), + mCallback(new nsMainThreadPtrHolder( + "AsyncSetIconForPage::mCallback", aCallback, false)), + mIcon(aIcon), + mPage(aPage) {} + +NS_IMETHODIMP +AsyncSetIconForPage::Run() { + MOZ_ASSERT(!NS_IsMainThread()); + MOZ_ASSERT(mIcon.payloads.Length(), "The icon should have valid data"); + MOZ_ASSERT(mPage.spec.Length(), "The page should have spec"); + MOZ_ASSERT(mPage.guid.IsEmpty(), "The page should not have guid"); + + nsresult rv = NS_OK; + auto guard = MakeScopeExit([&]() { + if (mCallback) { + NS_DispatchToMainThread( + NS_NewRunnableFunction("AsyncSetIconForPage::Callback", + [rv, callback = std::move(mCallback)]() { + (void)callback->Complete(rv); + })); + } + }); + + // Fetch the page data. + RefPtr DB = Database::GetDatabase(); + if (MOZ_UNLIKELY(!DB)) { + return (rv = NS_ERROR_UNEXPECTED); + } + rv = FetchPageInfo(DB, mPage); + NS_ENSURE_SUCCESS(rv, rv); + + nsMainThreadPtrHandle nullCallback; + AsyncAssociateIconToPage event(mIcon, mPage, nullCallback); + return (rv = event.Run()); +} + //////////////////////////////////////////////////////////////////////////////// //// AsyncGetFaviconURLForPage @@ -1040,61 +1083,6 @@ AsyncGetFaviconDataForPage::Run() { return NS_OK; } -//////////////////////////////////////////////////////////////////////////////// -//// AsyncReplaceFaviconData - -AsyncReplaceFaviconData::AsyncReplaceFaviconData(const IconData& aIcon) - : Runnable("places::AsyncReplaceFaviconData"), mIcon(aIcon) { - MOZ_ASSERT(NS_IsMainThread()); -} - -NS_IMETHODIMP -AsyncReplaceFaviconData::Run() { - MOZ_ASSERT(!NS_IsMainThread()); - - RefPtr DB = Database::GetDatabase(); - NS_ENSURE_STATE(DB); - - mozStorageTransaction transaction( - DB->MainConn(), false, mozIStorageConnection::TRANSACTION_IMMEDIATE); - - // XXX Handle the error, bug 1696133. - Unused << NS_WARN_IF(NS_FAILED(transaction.Start())); - - nsresult rv = SetIconInfo(DB, mIcon, true); - if (rv == NS_ERROR_NOT_AVAILABLE) { - // There's no previous icon to replace, we don't need to do anything. - (void)transaction.Commit(); - return NS_OK; - } - NS_ENSURE_SUCCESS(rv, rv); - rv = transaction.Commit(); - NS_ENSURE_SUCCESS(rv, rv); - - // We can invalidate the cache version since we now persist the icon. - nsCOMPtr event = NewRunnableMethod( - "places::AsyncReplaceFaviconData::RemoveIconDataCacheEntry", this, - &AsyncReplaceFaviconData::RemoveIconDataCacheEntry); - rv = NS_DispatchToMainThread(event); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - -nsresult AsyncReplaceFaviconData::RemoveIconDataCacheEntry() { - MOZ_ASSERT(NS_IsMainThread()); - - nsCOMPtr iconURI; - nsresult rv = NS_NewURI(getter_AddRefs(iconURI), mIcon.spec); - NS_ENSURE_SUCCESS(rv, rv); - - nsFaviconService* favicons = nsFaviconService::GetFaviconService(); - NS_ENSURE_STATE(favicons); - favicons->mUnassociatedIcons.RemoveEntry(iconURI); - - return NS_OK; -} - //////////////////////////////////////////////////////////////////////////////// //// NotifyIconObservers @@ -1207,7 +1195,8 @@ AsyncCopyFavicons::Run() { } NS_ENSURE_SUCCESS(rv, rv); - // Get just one icon, to check whether the page has any, and to notify later. + // Get just one icon, to check whether the page has any, and to notify + // later. rv = FetchIconPerSpec(DB, mFromPage.spec, ""_ns, icon, UINT16_MAX); NS_ENSURE_SUCCESS(rv, rv); -- cgit v1.2.3