Source code

Revision control

Other Tools

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/. */
4
5
#ifndef mozilla_BaseHistory_h
6
#define mozilla_BaseHistory_h
7
8
#include "IHistory.h"
9
#include "mozilla/Result.h"
10
11
/* A base class for history implementations that implement link coloring. */
12
13
namespace mozilla {
14
15
class BaseHistory : public IHistory {
16
public:
17
nsresult RegisterVisitedCallback(nsIURI*, dom::Link*) final;
18
void UnregisterVisitedCallback(nsIURI*, dom::Link*) final;
19
void NotifyVisited(nsIURI*, VisitedStatus) final;
20
21
protected:
22
static constexpr const size_t kTrackedUrisInitialSize = 64;
23
24
BaseHistory() : mTrackedURIs(kTrackedUrisInitialSize) {}
25
26
using ObserverArray = nsTObserverArray<dom::Link*>;
27
struct ObservingLinks {
28
ObserverArray mLinks;
29
VisitedStatus mStatus = VisitedStatus::Unknown;
30
31
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
32
return mLinks.ShallowSizeOfExcludingThis(aMallocSizeOf);
33
}
34
};
35
36
using PendingVisitedQueries = nsTHashtable<nsURIHashKey>;
37
38
// Starts all the queries in the pending queries list, potentially at the same
39
// time.
40
virtual void StartPendingVisitedQueries(const PendingVisitedQueries&) = 0;
41
42
private:
43
/**
44
* Mark all links for the given URI in the given document as visited. Used
45
* within NotifyVisited.
46
*/
47
void NotifyVisitedForDocument(nsIURI*, dom::Document*, VisitedStatus);
48
49
void ScheduleVisitedQuery(nsIURI*);
50
51
// Cancels a visited query, if it is at all possible, because we know we won't
52
// use the results anymore.
53
void CancelVisitedQueryIfPossible(nsIURI*);
54
55
/**
56
* Dispatch a runnable for the document passed in which will call
57
* NotifyVisitedForDocument with the correct URI and Document.
58
*/
59
void DispatchNotifyVisited(nsIURI*, dom::Document*, VisitedStatus);
60
61
protected:
62
// A map from URI to links that depend on that URI, and whether that URI is
63
// known-to-be-visited-or-unvisited already.
64
nsDataHashtable<nsURIHashKey, ObservingLinks> mTrackedURIs;
65
66
private:
67
// The set of pending URIs that we haven't queried yet but need to.
68
PendingVisitedQueries mPendingQueries;
69
// Whether we've successfully scheduled a runnable to call
70
// StartPendingVisitedQueries already.
71
bool mStartPendingVisitedQueriesScheduled = false;
72
};
73
74
} // namespace mozilla
75
76
#endif