LCOV - code coverage report
Current view: directory - toolkit/components/places - nsNavHistory.h (source / functions) Found Hit Coverage
Test: app.info Lines: 57 52 91.2 %
Date: 2012-06-02 Functions: 12 12 100.0 %

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

Generated by: LCOV version 1.7