tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

BaseHistory.h (2963B)


      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/dom/ContentParent.h"
     10 #include "nsTHashSet.h"
     11 
     12 /* A base class for history implementations that implement link coloring. */
     13 
     14 namespace mozilla {
     15 
     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;
     23 
     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*);
     27 
     28 protected:
     29  void NotifyVisitedInThisProcess(nsIURI*, VisitedStatus);
     30  void NotifyVisitedFromParent(nsIURI*, VisitedStatus, const ContentParentSet*);
     31  static constexpr const size_t kTrackedUrisInitialSize = 64;
     32 
     33  BaseHistory();
     34  ~BaseHistory();
     35 
     36  using ObserverArray = nsTObserverArray<dom::Link*>;
     37  struct ObservingLinks {
     38    ObserverArray mLinks;
     39    VisitedStatus mStatus = VisitedStatus::Unknown;
     40 
     41    size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
     42      return mLinks.ShallowSizeOfExcludingThis(aMallocSizeOf);
     43    }
     44  };
     45 
     46  using PendingVisitedQueries = nsTHashMap<nsURIHashKey, ContentParentSet>;
     47  struct PendingVisitedResult {
     48    dom::VisitedQueryResult mResult;
     49    ContentParentSet mProcessesToNotify;
     50  };
     51  using PendingVisitedResults = nsTArray<PendingVisitedResult>;
     52 
     53  // Starts all the queries in the pending queries list, potentially at the same
     54  // time.
     55  virtual void StartPendingVisitedQueries(PendingVisitedQueries&&) = 0;
     56 
     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*);
     61 
     62  void SendPendingVisitedResultsToChildProcesses();
     63 
     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;
     68 
     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;
     81 };
     82 
     83 }  // namespace mozilla
     84 
     85 #endif