summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/FaviconHelpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/places/FaviconHelpers.cpp')
-rw-r--r--toolkit/components/places/FaviconHelpers.cpp101
1 files changed, 45 insertions, 56 deletions
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
@@ -960,6 +960,49 @@ AsyncAssociateIconToPage::Run() {
}
////////////////////////////////////////////////////////////////////////////////
+//// AsyncSetIconForPage
+
+AsyncSetIconForPage::AsyncSetIconForPage(const IconData& aIcon,
+ const PageData& aPage,
+ PlacesCompletionCallback* aCallback)
+ : Runnable("places::AsyncSetIconForPage"),
+ mCallback(new nsMainThreadPtrHolder<PlacesCompletionCallback>(
+ "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<Database> DB = Database::GetDatabase();
+ if (MOZ_UNLIKELY(!DB)) {
+ return (rv = NS_ERROR_UNEXPECTED);
+ }
+ rv = FetchPageInfo(DB, mPage);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ nsMainThreadPtrHandle<nsIFaviconDataCallback> nullCallback;
+ AsyncAssociateIconToPage event(mIcon, mPage, nullCallback);
+ return (rv = event.Run());
+}
+
+////////////////////////////////////////////////////////////////////////////////
//// AsyncGetFaviconURLForPage
AsyncGetFaviconURLForPage::AsyncGetFaviconURLForPage(
@@ -1041,61 +1084,6 @@ AsyncGetFaviconDataForPage::Run() {
}
////////////////////////////////////////////////////////////////////////////////
-//// AsyncReplaceFaviconData
-
-AsyncReplaceFaviconData::AsyncReplaceFaviconData(const IconData& aIcon)
- : Runnable("places::AsyncReplaceFaviconData"), mIcon(aIcon) {
- MOZ_ASSERT(NS_IsMainThread());
-}
-
-NS_IMETHODIMP
-AsyncReplaceFaviconData::Run() {
- MOZ_ASSERT(!NS_IsMainThread());
-
- RefPtr<Database> 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<nsIRunnable> 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<nsIURI> 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
NotifyIconObservers::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);