1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_BaseHistory_h
6 #define mozilla_BaseHistory_h
9 #include "mozilla/dom/ContentParent.h"
10 #include "nsTHashSet.h"
12 /* A base class for history implementations that implement link coloring. */
16 class BaseHistory
: public IHistory
{
18 void RegisterVisitedCallback(nsIURI
*, dom::Link
*) final
;
19 void ScheduleVisitedQuery(nsIURI
*, dom::ContentParent
*) final
;
20 void UnregisterVisitedCallback(nsIURI
*, dom::Link
*) final
;
21 void NotifyVisited(nsIURI
*, VisitedStatus
,
22 const ContentParentSet
* = nullptr) final
;
24 // Some URIs like data-uris are never going to be stored in history, so we can
25 // avoid doing IPC roundtrips for them or what not.
26 static bool CanStore(nsIURI
*);
29 void NotifyVisitedInThisProcess(nsIURI
*, VisitedStatus
);
30 void NotifyVisitedFromParent(nsIURI
*, VisitedStatus
, const ContentParentSet
*);
31 static constexpr const size_t kTrackedUrisInitialSize
= 64;
36 using ObserverArray
= nsTObserverArray
<dom::Link
*>;
37 struct ObservingLinks
{
39 VisitedStatus mStatus
= VisitedStatus::Unknown
;
41 size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
) const {
42 return mLinks
.ShallowSizeOfExcludingThis(aMallocSizeOf
);
46 using PendingVisitedQueries
= nsTHashMap
<nsURIHashKey
, ContentParentSet
>;
47 struct PendingVisitedResult
{
48 dom::VisitedQueryResult mResult
;
49 ContentParentSet mProcessesToNotify
;
51 using PendingVisitedResults
= nsTArray
<PendingVisitedResult
>;
53 // Starts all the queries in the pending queries list, potentially at the same
55 virtual void StartPendingVisitedQueries(PendingVisitedQueries
&&) = 0;
58 // Cancels a visited query, if it is at all possible, because we know we won't
59 // use the results anymore.
60 void CancelVisitedQueryIfPossible(nsIURI
*);
62 void SendPendingVisitedResultsToChildProcesses();
65 // A map from URI to links that depend on that URI, and whether that URI is
66 // known-to-be-visited-or-unvisited already.
67 nsTHashMap
<nsURIHashKey
, ObservingLinks
> mTrackedURIs
;
70 // The set of pending URIs that we haven't queried yet but need to.
71 PendingVisitedQueries mPendingQueries
;
72 // The set of pending query results that we still haven't dispatched to child
74 PendingVisitedResults mPendingResults
;
75 // Whether we've successfully scheduled a runnable to call
76 // StartPendingVisitedQueries already.
77 bool mStartPendingVisitedQueriesScheduled
= false;
78 // Whether we've successfully scheduled a runnable to call
79 // SendPendingVisitedResultsToChildProcesses already.
80 bool mStartPendingResultsScheduled
= false;
83 } // namespace mozilla