/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
void BaseHistory::CancelVisitedQueryIfPossible(nsIURI* aURI) {
mPendingQueries.Remove(aURI); // TODO(bug 1591393): It could be worth to make this virtual and allow places // to stop the existing database query? Needs some measurement.
}
void BaseHistory::RegisterVisitedCallback(nsIURI* aURI, Link* aLink) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aURI, "Must pass a non-null URI!");
MOZ_ASSERT(aLink, "Must pass a non-null Link!");
if (!CanStore(aURI)) {
aLink->VisitedQueryFinished(/* visited = */ false); return;
}
// Obtain our array of observers for this URI. auto* const links =
mTrackedURIs.WithEntryHandle(aURI, [&](auto&& entry) -> ObservingLinks* {
MOZ_DIAGNOSTIC_ASSERT(!entry || !entry->mLinks.IsEmpty(), "An empty key was kept around in our hashtable!");
if (!entry) { // If the URI has userpass, skip the visit query scheduling, because // these URIs are not stored by history, and their status is only // updated at the time of a visit. bool hasUserPass; if (NS_FAILED(aURI->GetHasUserPass(&hasUserPass)) || !hasUserPass) {
ScheduleVisitedQuery(aURI, nullptr);
}
}
// Sanity check that Links are not registered more than once for a given URI. // This will not catch a case where it is registered for two different URIs.
MOZ_DIAGNOSTIC_ASSERT(!links->mLinks.Contains(aLink), "Already tracking this Link object!");
links->mLinks.AppendElement(aLink);
// If this link has already been queried and we should notify, do so now. switch (links->mStatus) { case VisitedStatus::Unknown: break; case VisitedStatus::Unvisited:
[[fallthrough]]; case VisitedStatus::Visited:
aLink->VisitedQueryFinished(links->mStatus == VisitedStatus::Visited); break;
}
}
void BaseHistory::UnregisterVisitedCallback(nsIURI* aURI, Link* aLink) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aURI, "Must pass a non-null URI!");
MOZ_ASSERT(aLink, "Must pass a non-null Link object!");
// Get the array, and remove the item from it. auto entry = mTrackedURIs.Lookup(aURI); if (!entry) {
MOZ_ASSERT(!CanStore(aURI), "Trying to unregister URI that wasn't registered, " "and that could be visited!"); return;
}
ObserverArray& observers = entry->mLinks; if (!observers.RemoveElement(aLink)) {
MOZ_ASSERT_UNREACHABLE("Trying to unregister node that wasn't registered!"); return;
}
// If the array is now empty, we should remove it from the hashtable. if (observers.IsEmpty()) {
entry.Remove();
CancelVisitedQueryIfPossible(aURI);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.