Bug 1807268 - Fix verifyOpenAllInNewTabsOptionTest UI test r=ohorvath
[gecko.git] / docshell / base / BaseHistory.h
blobf0fa36db99dd082e86a8404fba9a182bd80985de
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
8 #include "IHistory.h"
9 #include "mozilla/dom/ContentParent.h"
10 #include "nsTHashSet.h"
12 /* A base class for history implementations that implement link coloring. */
14 namespace mozilla {
16 class BaseHistory : public IHistory {
17 public:
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*);
28 protected:
29 void NotifyVisitedInThisProcess(nsIURI*, VisitedStatus);
30 void NotifyVisitedFromParent(nsIURI*, VisitedStatus, const ContentParentSet*);
31 static constexpr const size_t kTrackedUrisInitialSize = 64;
33 BaseHistory();
34 ~BaseHistory();
36 using ObserverArray = nsTObserverArray<dom::Link*>;
37 struct ObservingLinks {
38 ObserverArray mLinks;
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
54 // time.
55 virtual void StartPendingVisitedQueries(PendingVisitedQueries&&) = 0;
57 private:
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();
64 protected:
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;
69 private:
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
73 // processes.
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
85 #endif