LCOV - code coverage report
Current view: top level - toolkit/components/places - nsNavHistory.h (source / functions) Hit Total Coverage
Test: output.info Lines: 17 53 32.1 %
Date: 2017-07-14 16:53:18 Functions: 6 11 54.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef nsNavHistory_h_
       7             : #define nsNavHistory_h_
       8             : 
       9             : #include "nsINavHistoryService.h"
      10             : #include "nsPIPlacesDatabase.h"
      11             : #include "nsIBrowserHistory.h"
      12             : #include "nsINavBookmarksService.h"
      13             : #include "nsIFaviconService.h"
      14             : 
      15             : #include "nsIObserverService.h"
      16             : #include "nsICollation.h"
      17             : #include "nsIStringBundle.h"
      18             : #include "nsITimer.h"
      19             : #include "nsMaybeWeakPtr.h"
      20             : #include "nsCategoryCache.h"
      21             : #include "nsNetCID.h"
      22             : #include "nsToolkitCompsCID.h"
      23             : #include "nsURIHashKey.h"
      24             : #include "nsTHashtable.h"
      25             : 
      26             : #include "nsNavHistoryResult.h"
      27             : #include "nsNavHistoryQuery.h"
      28             : #include "Database.h"
      29             : #include "mozilla/Attributes.h"
      30             : #include "mozilla/Atomics.h"
      31             : 
      32             : #define QUERYUPDATE_TIME 0
      33             : #define QUERYUPDATE_SIMPLE 1
      34             : #define QUERYUPDATE_COMPLEX 2
      35             : #define QUERYUPDATE_COMPLEX_WITH_BOOKMARKS 3
      36             : #define QUERYUPDATE_HOST 4
      37             : 
      38             : // Clamp title and URL to generously large, but not too large, length.
      39             : // See bug 319004 for details.
      40             : #define URI_LENGTH_MAX 65536
      41             : #define TITLE_LENGTH_MAX 4096
      42             : 
      43             : // Microsecond timeout for "recent" events such as typed and bookmark following.
      44             : // If you typed it more than this time ago, it's not recent.
      45             : #define RECENT_EVENT_THRESHOLD PRTime((int64_t)15 * 60 * PR_USEC_PER_SEC)
      46             : 
      47             : #ifdef MOZ_XUL
      48             : // Fired after autocomplete feedback has been updated.
      49             : #define TOPIC_AUTOCOMPLETE_FEEDBACK_UPDATED "places-autocomplete-feedback-updated"
      50             : #endif
      51             : 
      52             : // Fired after frecency has been updated.
      53             : #define TOPIC_FRECENCY_UPDATED "places-frecency-updated"
      54             : 
      55             : class nsNavHistory;
      56             : class QueryKeyValuePair;
      57             : class nsIEffectiveTLDService;
      58             : class nsIIDNService;
      59             : class PlacesSQLQueryBuilder;
      60             : class nsIAutoCompleteController;
      61             : 
      62             : // nsNavHistory
      63             : 
      64             : class nsNavHistory final : public nsSupportsWeakReference
      65             :                          , public nsINavHistoryService
      66             :                          , public nsIObserver
      67             :                          , public nsIBrowserHistory
      68             :                          , public nsPIPlacesDatabase
      69             :                          , public mozIStorageVacuumParticipant
      70             : {
      71             :   friend class PlacesSQLQueryBuilder;
      72             : 
      73             : public:
      74             :   nsNavHistory();
      75             : 
      76             :   NS_DECL_THREADSAFE_ISUPPORTS
      77             :   NS_DECL_NSINAVHISTORYSERVICE
      78             :   NS_DECL_NSIBROWSERHISTORY
      79             :   NS_DECL_NSIOBSERVER
      80             :   NS_DECL_NSPIPLACESDATABASE
      81             :   NS_DECL_MOZISTORAGEVACUUMPARTICIPANT
      82             : 
      83             :   /**
      84             :    * Obtains the nsNavHistory object.
      85             :    */
      86             :   static already_AddRefed<nsNavHistory> GetSingleton();
      87             : 
      88             :   /**
      89             :    * Initializes the nsNavHistory object.  This should only be called once.
      90             :    */
      91             :   nsresult Init();
      92             : 
      93             :   /**
      94             :    * Used by other components in the places directory such as the annotation
      95             :    * service to get a reference to this history object. Returns a pointer to
      96             :    * the service if it exists. Otherwise creates one. Returns nullptr on error.
      97             :    */
      98           9 :   static nsNavHistory* GetHistoryService()
      99             :   {
     100           9 :     if (!gHistoryService) {
     101             :       nsCOMPtr<nsINavHistoryService> serv =
     102           0 :         do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
     103           0 :       NS_ENSURE_TRUE(serv, nullptr);
     104           0 :       NS_ASSERTION(gHistoryService, "Should have static instance pointer now");
     105             :     }
     106           9 :     return gHistoryService;
     107             :   }
     108             : 
     109             :   /**
     110             :    * Used by other components in the places directory to get a reference to a
     111             :    * const version of this history object.
     112             :    *
     113             :    * @return A pointer to a const version of the service if it exists,
     114             :    *         nullptr otherwise.
     115             :    */
     116           3 :   static const nsNavHistory* GetConstHistoryService()
     117             :   {
     118           3 :     const nsNavHistory* const history = gHistoryService;
     119           3 :     return history;
     120             :   }
     121             : 
     122             :   /**
     123             :    * Fetches the database id and the GUID associated to the given URI.
     124             :    *
     125             :    * @param aURI
     126             :    *        The page to look for.
     127             :    * @param _pageId
     128             :    *        Will be set to the database id associated with the page.
     129             :    *        If the page doesn't exist, this will be zero.
     130             :    * @param _GUID
     131             :    *        Will be set to the unique id associated with the page.
     132             :    *        If the page doesn't exist, this will be empty.
     133             :    * @note This DOES NOT check for bad URLs other than that they're nonempty.
     134             :    */
     135             :   nsresult GetIdForPage(nsIURI* aURI,
     136             :                         int64_t* _pageId, nsCString& _GUID);
     137             : 
     138             :   /**
     139             :    * Fetches the database id and the GUID associated to the given URI, creating
     140             :    * a new database entry if one doesn't exist yet.
     141             :    *
     142             :    * @param aURI
     143             :    *        The page to look for or create.
     144             :    * @param _pageId
     145             :    *        Will be set to the database id associated with the page.
     146             :    * @param _GUID
     147             :    *        Will be set to the unique id associated with the page.
     148             :    * @note This DOES NOT check for bad URLs other than that they're nonempty.
     149             :    * @note This DOES NOT update frecency of the page.
     150             :    */
     151             :   nsresult GetOrCreateIdForPage(nsIURI* aURI,
     152             :                                 int64_t* _pageId, nsCString& _GUID);
     153             : 
     154             :   /**
     155             :    * Asynchronously recalculates frecency for a given page.
     156             :    *
     157             :    * @param aPlaceId
     158             :    *        Place id to recalculate the frecency for.
     159             :    * @note If the new frecency is a non-zero value it will also unhide the page,
     160             :    *       otherwise will reuse the old hidden value.
     161             :    */
     162             :   nsresult UpdateFrecency(int64_t aPlaceId);
     163             : 
     164             :   /**
     165             :    * Recalculates frecency for all pages requesting that (frecency < 0). Those
     166             :    * may be generated:
     167             :    *  * After a "clear private data"
     168             :    *  * After removing visits
     169             :    *  * After migrating from older versions
     170             :    */
     171             :   nsresult FixInvalidFrecencies();
     172             : 
     173             :   /**
     174             :    * Invalidate the frecencies of a list of places, so they will be recalculated
     175             :    * at the first idle-daily notification.
     176             :    *
     177             :    * @param aPlacesIdsQueryString
     178             :    *        Query string containing list of places to be invalidated.  If it's
     179             :    *        an empty string all places will be invalidated.
     180             :    */
     181             :   nsresult invalidateFrecencies(const nsCString& aPlaceIdsQueryString);
     182             : 
     183             :   /**
     184             :    * Calls onDeleteVisits and onDeleteURI notifications on registered listeners
     185             :    * with the history service.
     186             :    *
     187             :    * @param aURI
     188             :    *        The nsIURI object representing the URI of the page being expired.
     189             :    * @param aVisitTime
     190             :    *        The time, in microseconds, that the page being expired was visited.
     191             :    * @param aWholeEntry
     192             :    *        Indicates if this is the last visit for this URI.
     193             :    * @param aGUID
     194             :    *        The unique ID associated with the page.
     195             :    * @param aReason
     196             :    *        Indicates the reason for the removal.
     197             :    *        See nsINavHistoryObserver::REASON_* constants.
     198             :    * @param aTransitionType
     199             :    *        If it's a valid TRANSITION_* value, all visits of the specified type
     200             :    *        have been removed.
     201             :    */
     202             :   nsresult NotifyOnPageExpired(nsIURI *aURI, PRTime aVisitTime,
     203             :                                bool aWholeEntry, const nsACString& aGUID,
     204             :                                uint16_t aReason, uint32_t aTransitionType);
     205             : 
     206             :   /**
     207             :    * These functions return non-owning references to the locale-specific
     208             :    * objects for places components.
     209             :    */
     210             :   nsIStringBundle* GetBundle();
     211             :   nsICollation* GetCollation();
     212             :   void GetStringFromName(const char16_t* aName, nsACString& aResult);
     213             :   void GetAgeInDaysString(int32_t aInt, const char16_t *aName,
     214             :                           nsACString& aResult);
     215             :   static void GetMonthName(const PRExplodedTime& aTime, nsACString& aResult);
     216             :   static void GetMonthYear(const PRExplodedTime& aTime, nsACString& aResult);
     217             : 
     218             :   // Returns whether history is enabled or not.
     219           4 :   bool IsHistoryDisabled() {
     220           4 :     return !mHistoryEnabled;
     221             :   }
     222             : 
     223             :   // Constants for the columns returned by the above statement.
     224             :   static const int32_t kGetInfoIndex_PageID;
     225             :   static const int32_t kGetInfoIndex_URL;
     226             :   static const int32_t kGetInfoIndex_Title;
     227             :   static const int32_t kGetInfoIndex_RevHost;
     228             :   static const int32_t kGetInfoIndex_VisitCount;
     229             :   static const int32_t kGetInfoIndex_VisitDate;
     230             :   static const int32_t kGetInfoIndex_FaviconURL;
     231             :   static const int32_t kGetInfoIndex_ItemId;
     232             :   static const int32_t kGetInfoIndex_ItemDateAdded;
     233             :   static const int32_t kGetInfoIndex_ItemLastModified;
     234             :   static const int32_t kGetInfoIndex_ItemParentId;
     235             :   static const int32_t kGetInfoIndex_ItemTags;
     236             :   static const int32_t kGetInfoIndex_Frecency;
     237             :   static const int32_t kGetInfoIndex_Hidden;
     238             :   static const int32_t kGetInfoIndex_Guid;
     239             :   static const int32_t kGetInfoIndex_VisitId;
     240             :   static const int32_t kGetInfoIndex_FromVisitId;
     241             :   static const int32_t kGetInfoIndex_VisitType;
     242             : 
     243             :   int64_t GetTagsFolder();
     244             : 
     245             :   // this actually executes a query and gives you results, it is used by
     246             :   // nsNavHistoryQueryResultNode
     247             :   nsresult GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
     248             :                            const nsCOMArray<nsNavHistoryQuery>& aQueries,
     249             :                            nsNavHistoryQueryOptions *aOptions,
     250             :                            nsCOMArray<nsNavHistoryResultNode>* aResults);
     251             : 
     252             :   // Take a row of kGetInfoIndex_* columns and construct a ResultNode.
     253             :   // The row must contain the full set of columns.
     254             :   nsresult RowToResult(mozIStorageValueArray* aRow,
     255             :                        nsNavHistoryQueryOptions* aOptions,
     256             :                        nsNavHistoryResultNode** aResult);
     257             :   nsresult QueryRowToResult(int64_t aItemId,
     258             :                             const nsACString& aBookmarkGuid,
     259             :                             const nsACString& aURI,
     260             :                             const nsACString& aTitle,
     261             :                             uint32_t aAccessCount,
     262             :                             PRTime aTime,
     263             :                             nsNavHistoryResultNode** aNode);
     264             : 
     265             :   nsresult VisitIdToResultNode(int64_t visitId,
     266             :                                nsNavHistoryQueryOptions* aOptions,
     267             :                                nsNavHistoryResultNode** aResult);
     268             : 
     269             :   nsresult BookmarkIdToResultNode(int64_t aBookmarkId,
     270             :                                   nsNavHistoryQueryOptions* aOptions,
     271             :                                   nsNavHistoryResultNode** aResult);
     272             :   nsresult URIToResultNode(nsIURI* aURI,
     273             :                            nsNavHistoryQueryOptions* aOptions,
     274             :                            nsNavHistoryResultNode** aResult);
     275             : 
     276             :   // used by other places components to send history notifications (for example,
     277             :   // when the favicon has changed)
     278             :   void SendPageChangedNotification(nsIURI* aURI, uint32_t aChangedAttribute,
     279             :                                    const nsAString& aValue,
     280             :                                    const nsACString& aGUID);
     281             : 
     282             :   /**
     283             :    * Returns current number of days stored in history.
     284             :    */
     285             :   int32_t GetDaysOfHistory();
     286             : 
     287             :   // used by query result nodes to update: see comment on body of CanLiveUpdateQuery
     288             :   static uint32_t GetUpdateRequirements(const nsCOMArray<nsNavHistoryQuery>& aQueries,
     289             :                                         nsNavHistoryQueryOptions* aOptions,
     290             :                                         bool* aHasSearchTerms);
     291             :   bool EvaluateQueryForNode(const nsCOMArray<nsNavHistoryQuery>& aQueries,
     292             :                               nsNavHistoryQueryOptions* aOptions,
     293             :                               nsNavHistoryResultNode* aNode);
     294             : 
     295             :   static nsresult AsciiHostNameFromHostString(const nsACString& aHostName,
     296             :                                               nsACString& aAscii);
     297             :   void DomainNameFromURI(nsIURI* aURI,
     298             :                          nsACString& aDomainName);
     299             :   static PRTime NormalizeTime(uint32_t aRelative, PRTime aOffset);
     300             : 
     301             :   // Don't use these directly, inside nsNavHistory use UpdateBatchScoper,
     302             :   // else use nsINavHistoryService::RunInBatchMode
     303             :   nsresult BeginUpdateBatch();
     304             :   nsresult EndUpdateBatch();
     305             : 
     306             :   // The level of batches' nesting, 0 when no batches are open.
     307             :   int32_t mBatchLevel;
     308             :   // Current active transaction for a batch.
     309             :   mozStorageTransaction* mBatchDBTransaction;
     310             : 
     311             :   // better alternative to QueryStringToQueries (in nsNavHistoryQuery.cpp)
     312             :   nsresult QueryStringToQueryArray(const nsACString& aQueryString,
     313             :                                    nsCOMArray<nsNavHistoryQuery>* aQueries,
     314             :                                    nsNavHistoryQueryOptions** aOptions);
     315             : 
     316             :   typedef nsDataHashtable<nsCStringHashKey, nsCString> StringHash;
     317             : 
     318             :   /**
     319             :    * Indicates if it is OK to notify history observers or not.
     320             :    *
     321             :    * @return true if it is OK to notify, false otherwise.
     322             :    */
     323             :   bool canNotify() { return mCanNotify; }
     324             : 
     325             :   enum RecentEventFlags {
     326             :     RECENT_TYPED      = 1 << 0,    // User typed in URL recently
     327             :     RECENT_ACTIVATED  = 1 << 1,    // User tapped URL link recently
     328             :     RECENT_BOOKMARKED = 1 << 2     // User bookmarked URL recently
     329             :   };
     330             : 
     331             :   /**
     332             :    * Returns any recent activity done with a URL.
     333             :    * @return Any recent events associated with this URI.  Each bit is set
     334             :    *         according to RecentEventFlags enum values.
     335             :    */
     336             :   uint32_t GetRecentFlags(nsIURI *aURI);
     337             : 
     338             :   /**
     339             :    * Registers a TRANSITION_EMBED visit for the session.
     340             :    *
     341             :    * @param aURI
     342             :    *        URI of the page.
     343             :    * @param aTime
     344             :    *        Visit time.  Only the last registered visit time is retained.
     345             :    */
     346             :   void registerEmbedVisit(nsIURI* aURI, int64_t aTime);
     347             : 
     348             :   /**
     349             :    * Returns whether the specified url has a embed visit.
     350             :    *
     351             :    * @param aURI
     352             :    *        URI of the page.
     353             :    * @return whether the page has a embed visit.
     354             :    */
     355             :   bool hasEmbedVisit(nsIURI* aURI);
     356             : 
     357             :   /**
     358             :    * Clears all registered embed visits.
     359             :    */
     360             :   void clearEmbedVisits();
     361             : 
     362           1 :   int32_t GetFrecencyAgedWeight(int32_t aAgeInDays) const
     363             :   {
     364           1 :     if (aAgeInDays <= mFirstBucketCutoffInDays) {
     365           1 :       return mFirstBucketWeight;
     366             :     }
     367           0 :     if (aAgeInDays <= mSecondBucketCutoffInDays) {
     368           0 :       return mSecondBucketWeight;
     369             :     }
     370           0 :     if (aAgeInDays <= mThirdBucketCutoffInDays) {
     371           0 :       return mThirdBucketWeight;
     372             :     }
     373           0 :     if (aAgeInDays <= mFourthBucketCutoffInDays) {
     374           0 :       return mFourthBucketWeight;
     375             :     }
     376           0 :     return mDefaultWeight;
     377             :   }
     378             : 
     379           0 :   int32_t GetFrecencyBucketWeight(int32_t aBucketIndex) const
     380             :   {
     381           0 :     switch(aBucketIndex) {
     382             :       case 1:
     383           0 :         return mFirstBucketWeight;
     384             :       case 2:
     385           0 :         return mSecondBucketWeight;
     386             :       case 3:
     387           0 :         return mThirdBucketWeight;
     388             :       case 4:
     389           0 :         return mFourthBucketWeight;
     390             :       default:
     391           0 :         return mDefaultWeight;
     392             :     }
     393             :   }
     394             : 
     395           1 :   int32_t GetFrecencyTransitionBonus(int32_t aTransitionType,
     396             :                                      bool aVisited,
     397             :                                      bool aRedirect = false) const
     398             :   {
     399           1 :     if (aRedirect) {
     400           0 :       return mRedirectSourceVisitBonus;
     401             :     }
     402             : 
     403           1 :     switch (aTransitionType) {
     404             :       case nsINavHistoryService::TRANSITION_EMBED:
     405           0 :         return mEmbedVisitBonus;
     406             :       case nsINavHistoryService::TRANSITION_FRAMED_LINK:
     407           0 :         return mFramedLinkVisitBonus;
     408             :       case nsINavHistoryService::TRANSITION_LINK:
     409           1 :         return mLinkVisitBonus;
     410             :       case nsINavHistoryService::TRANSITION_TYPED:
     411           0 :         return aVisited ? mTypedVisitBonus : mUnvisitedTypedBonus;
     412             :       case nsINavHistoryService::TRANSITION_BOOKMARK:
     413           0 :         return aVisited ? mBookmarkVisitBonus : mUnvisitedBookmarkBonus;
     414             :       case nsINavHistoryService::TRANSITION_DOWNLOAD:
     415           0 :         return mDownloadVisitBonus;
     416             :       case nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT:
     417           0 :         return mPermRedirectVisitBonus;
     418             :       case nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY:
     419           0 :         return mTempRedirectVisitBonus;
     420             :       case nsINavHistoryService::TRANSITION_RELOAD:
     421           0 :         return mReloadVisitBonus;
     422             :       default:
     423             :         // 0 == undefined (see bug #375777 for details)
     424           0 :         NS_WARNING_ASSERTION(!aTransitionType,
     425             :                              "new transition but no bonus for frecency");
     426           0 :         return mDefaultVisitBonus;
     427             :     }
     428             :   }
     429             : 
     430           1 :   int32_t GetNumVisitsForFrecency() const
     431             :   {
     432           1 :     return mNumVisitsForFrecency;
     433             :   }
     434             : 
     435             :   /**
     436             :    * Fires onVisit event to nsINavHistoryService observers
     437             :    */
     438             :   void NotifyOnVisit(nsIURI* aURI,
     439             :                      int64_t aVisitId,
     440             :                      PRTime aTime,
     441             :                      int64_t aReferrerVisitId,
     442             :                      int32_t aTransitionType,
     443             :                      const nsACString& aGuid,
     444             :                      bool aHidden,
     445             :                      uint32_t aVisitCount,
     446             :                      uint32_t aTyped,
     447             :                      const nsAString& aLastKnownTitle);
     448             : 
     449             :   /**
     450             :    * Fires onTitleChanged event to nsINavHistoryService observers
     451             :    */
     452             :   void NotifyTitleChange(nsIURI* aURI,
     453             :                          const nsString& title,
     454             :                          const nsACString& aGUID);
     455             : 
     456             :   /**
     457             :    * Fires onFrecencyChanged event to nsINavHistoryService observers
     458             :    */
     459             :   void NotifyFrecencyChanged(nsIURI* aURI,
     460             :                              int32_t aNewFrecency,
     461             :                              const nsACString& aGUID,
     462             :                              bool aHidden,
     463             :                              PRTime aLastVisitDate);
     464             : 
     465             :   /**
     466             :    * Fires onManyFrecenciesChanged event to nsINavHistoryService observers
     467             :    */
     468             :   void NotifyManyFrecenciesChanged();
     469             : 
     470             :   /**
     471             :    * Posts a runnable to the main thread that calls NotifyFrecencyChanged.
     472             :    */
     473             :   void DispatchFrecencyChangedNotification(const nsACString& aSpec,
     474             :                                            int32_t aNewFrecency,
     475             :                                            const nsACString& aGUID,
     476             :                                            bool aHidden,
     477             :                                            PRTime aLastVisitDate) const;
     478             : 
     479             :   /**
     480             :    * Store last insterted id for a table.
     481             :    */
     482             :   static mozilla::Atomic<int64_t> sLastInsertedPlaceId;
     483             :   static mozilla::Atomic<int64_t> sLastInsertedVisitId;
     484             : 
     485             :   static void StoreLastInsertedId(const nsACString& aTable,
     486             :                                   const int64_t aLastInsertedId);
     487             : 
     488           0 :   bool isBatching() {
     489           0 :     return mBatchLevel > 0;
     490             :   }
     491             : 
     492             : private:
     493             :   ~nsNavHistory();
     494             : 
     495             :   // used by GetHistoryService
     496             :   static nsNavHistory *gHistoryService;
     497             : 
     498             : protected:
     499             : 
     500             :   // Database handle.
     501             :   RefPtr<mozilla::places::Database> mDB;
     502             : 
     503             :   /**
     504             :    * Decays frecency and inputhistory values.  Runs on idle-daily.
     505             :    */
     506             :   nsresult DecayFrecency();
     507             : 
     508             :   nsresult RemovePagesInternal(const nsCString& aPlaceIdsQueryString);
     509             :   nsresult CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString);
     510             : 
     511             :   /**
     512             :    * Loads all of the preferences that we use into member variables.
     513             :    *
     514             :    * @note If mPrefBranch is nullptr, this does nothing.
     515             :    */
     516             :   void LoadPrefs();
     517             : 
     518             :   /**
     519             :    * Calculates and returns value for mCachedNow.
     520             :    * This is an hack to avoid calling PR_Now() too often, as is the case when
     521             :    * we're asked the ageindays of many history entries in a row.  A timer is
     522             :    * set which will clear our valid flag after a short timeout.
     523             :    */
     524             :   PRTime GetNow();
     525             :   PRTime mCachedNow;
     526             :   nsCOMPtr<nsITimer> mExpireNowTimer;
     527             :   /**
     528             :    * Called when the cached now value is expired and needs renewal.
     529             :    */
     530             :   static void expireNowTimerCallback(nsITimer* aTimer, void* aClosure);
     531             : 
     532             :   nsresult ConstructQueryString(const nsCOMArray<nsNavHistoryQuery>& aQueries,
     533             :                                 nsNavHistoryQueryOptions* aOptions,
     534             :                                 nsCString& queryString,
     535             :                                 bool& aParamsPresent,
     536             :                                 StringHash& aAddParams);
     537             : 
     538             :   nsresult QueryToSelectClause(nsNavHistoryQuery* aQuery,
     539             :                                nsNavHistoryQueryOptions* aOptions,
     540             :                                int32_t aQueryIndex,
     541             :                                nsCString* aClause);
     542             :   nsresult BindQueryClauseParameters(mozIStorageBaseStatement* statement,
     543             :                                      int32_t aQueryIndex,
     544             :                                      nsNavHistoryQuery* aQuery,
     545             :                                      nsNavHistoryQueryOptions* aOptions);
     546             : 
     547             :   nsresult ResultsAsList(mozIStorageStatement* statement,
     548             :                          nsNavHistoryQueryOptions* aOptions,
     549             :                          nsCOMArray<nsNavHistoryResultNode>* aResults);
     550             : 
     551             :   void TitleForDomain(const nsCString& domain, nsACString& aTitle);
     552             : 
     553             :   nsresult FilterResultSet(nsNavHistoryQueryResultNode *aParentNode,
     554             :                            const nsCOMArray<nsNavHistoryResultNode>& aSet,
     555             :                            nsCOMArray<nsNavHistoryResultNode>* aFiltered,
     556             :                            const nsCOMArray<nsNavHistoryQuery>& aQueries,
     557             :                            nsNavHistoryQueryOptions* aOptions);
     558             : 
     559             :   // observers
     560             :   nsMaybeWeakPtrArray<nsINavHistoryObserver> mObservers;
     561             : 
     562             :   // effective tld service
     563             :   nsCOMPtr<nsIEffectiveTLDService> mTLDService;
     564             :   nsCOMPtr<nsIIDNService>          mIDNService;
     565             : 
     566             :   // localization
     567             :   nsCOMPtr<nsIStringBundle> mBundle;
     568             :   nsCOMPtr<nsICollation> mCollation;
     569             : 
     570             :   // recent events
     571             :   typedef nsDataHashtable<nsCStringHashKey, int64_t> RecentEventHash;
     572             :   RecentEventHash mRecentTyped;
     573             :   RecentEventHash mRecentLink;
     574             :   RecentEventHash mRecentBookmark;
     575             : 
     576             :   // Embed visits tracking.
     577           0 :   class VisitHashKey : public nsURIHashKey
     578             :   {
     579             :   public:
     580           0 :     explicit VisitHashKey(const nsIURI* aURI)
     581           0 :     : nsURIHashKey(aURI)
     582             :     {
     583           0 :     }
     584             :     VisitHashKey(const VisitHashKey& aOther)
     585             :     : nsURIHashKey(aOther)
     586             :     {
     587             :       NS_NOTREACHED("Do not call me!");
     588             :     }
     589             :     PRTime visitTime;
     590             :   };
     591             : 
     592             :   nsTHashtable<VisitHashKey> mEmbedVisits;
     593             : 
     594             :   bool CheckIsRecentEvent(RecentEventHash* hashTable,
     595             :                             const nsACString& url);
     596             :   void ExpireNonrecentEvents(RecentEventHash* hashTable);
     597             : 
     598             : #ifdef MOZ_XUL
     599             :   nsresult AutoCompleteFeedback(int32_t aIndex,
     600             :                                 nsIAutoCompleteController *aController);
     601             : #endif
     602             : 
     603             :   // Whether history is enabled or not.
     604             :   // Will mimic value of the places.history.enabled preference.
     605             :   bool mHistoryEnabled;
     606             : 
     607             :   // Frecency preferences.
     608             :   int32_t mNumVisitsForFrecency;
     609             :   int32_t mFirstBucketCutoffInDays;
     610             :   int32_t mSecondBucketCutoffInDays;
     611             :   int32_t mThirdBucketCutoffInDays;
     612             :   int32_t mFourthBucketCutoffInDays;
     613             :   int32_t mFirstBucketWeight;
     614             :   int32_t mSecondBucketWeight;
     615             :   int32_t mThirdBucketWeight;
     616             :   int32_t mFourthBucketWeight;
     617             :   int32_t mDefaultWeight;
     618             :   int32_t mEmbedVisitBonus;
     619             :   int32_t mFramedLinkVisitBonus;
     620             :   int32_t mLinkVisitBonus;
     621             :   int32_t mTypedVisitBonus;
     622             :   int32_t mBookmarkVisitBonus;
     623             :   int32_t mDownloadVisitBonus;
     624             :   int32_t mPermRedirectVisitBonus;
     625             :   int32_t mTempRedirectVisitBonus;
     626             :   int32_t mRedirectSourceVisitBonus;
     627             :   int32_t mDefaultVisitBonus;
     628             :   int32_t mUnvisitedBookmarkBonus;
     629             :   int32_t mUnvisitedTypedBonus;
     630             :   int32_t mReloadVisitBonus;
     631             : 
     632             :   // in nsNavHistoryQuery.cpp
     633             :   nsresult TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
     634             :                            nsCOMArray<nsNavHistoryQuery>* aQueries,
     635             :                            nsNavHistoryQueryOptions* aOptions);
     636             : 
     637             :   int64_t mTagsFolder;
     638             : 
     639             :   int32_t mDaysOfHistory;
     640             :   int64_t mLastCachedStartOfDay;
     641             :   int64_t mLastCachedEndOfDay;
     642             : 
     643             :   // Used to enable and disable the observer notifications
     644             :   bool mCanNotify;
     645             :   nsCategoryCache<nsINavHistoryObserver> mCacheObservers;
     646             : };
     647             : 
     648             : 
     649             : #define PLACES_URI_PREFIX "place:"
     650             : 
     651             : /* Returns true if the given URI represents a history query. */
     652           0 : inline bool IsQueryURI(const nsCString &uri)
     653             : {
     654           0 :   return StringBeginsWith(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX));
     655             : }
     656             : 
     657             : /* Extracts the query string from a query URI. */
     658             : inline const nsDependentCSubstring QueryURIToQuery(const nsCString &uri)
     659             : {
     660             :   NS_ASSERTION(IsQueryURI(uri), "should only be called for query URIs");
     661             :   return Substring(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX).Length());
     662             : }
     663             : 
     664             : #endif // nsNavHistory_h_

Generated by: LCOV version 1.13