toolkit/components/places/nsNavHistory.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/nsNavHistory.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,622 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsNavHistory_h_
    1.10 +#define nsNavHistory_h_
    1.11 +
    1.12 +#include "nsINavHistoryService.h"
    1.13 +#include "nsPIPlacesDatabase.h"
    1.14 +#include "nsPIPlacesHistoryListenersNotifier.h"
    1.15 +#include "nsIBrowserHistory.h"
    1.16 +#include "nsINavBookmarksService.h"
    1.17 +#include "nsIFaviconService.h"
    1.18 +
    1.19 +#include "nsIObserverService.h"
    1.20 +#include "nsICollation.h"
    1.21 +#include "nsIStringBundle.h"
    1.22 +#include "nsITimer.h"
    1.23 +#include "nsMaybeWeakPtr.h"
    1.24 +#include "nsCategoryCache.h"
    1.25 +#include "nsNetCID.h"
    1.26 +#include "nsToolkitCompsCID.h"
    1.27 +#include "nsURIHashKey.h"
    1.28 +#include "nsTHashtable.h"
    1.29 +
    1.30 +#include "nsNavHistoryResult.h"
    1.31 +#include "nsNavHistoryQuery.h"
    1.32 +#include "Database.h"
    1.33 +#include "mozilla/Attributes.h"
    1.34 +
    1.35 +#define QUERYUPDATE_TIME 0
    1.36 +#define QUERYUPDATE_SIMPLE 1
    1.37 +#define QUERYUPDATE_COMPLEX 2
    1.38 +#define QUERYUPDATE_COMPLEX_WITH_BOOKMARKS 3
    1.39 +#define QUERYUPDATE_HOST 4
    1.40 +
    1.41 +// Clamp title and URL to generously large, but not too large, length.
    1.42 +// See bug 319004 for details.
    1.43 +#define URI_LENGTH_MAX 65536
    1.44 +#define TITLE_LENGTH_MAX 4096
    1.45 +
    1.46 +// Microsecond timeout for "recent" events such as typed and bookmark following.
    1.47 +// If you typed it more than this time ago, it's not recent.
    1.48 +#define RECENT_EVENT_THRESHOLD PRTime((int64_t)15 * 60 * PR_USEC_PER_SEC)
    1.49 +
    1.50 +#ifdef MOZ_XUL
    1.51 +// Fired after autocomplete feedback has been updated.
    1.52 +#define TOPIC_AUTOCOMPLETE_FEEDBACK_UPDATED "places-autocomplete-feedback-updated"
    1.53 +#endif
    1.54 +
    1.55 +// Fired after frecency has been updated.
    1.56 +#define TOPIC_FRECENCY_UPDATED "places-frecency-updated"
    1.57 +
    1.58 +class mozIAnnotationService;
    1.59 +class nsNavHistory;
    1.60 +class QueryKeyValuePair;
    1.61 +class nsIEffectiveTLDService;
    1.62 +class nsIIDNService;
    1.63 +class PlacesSQLQueryBuilder;
    1.64 +class nsIAutoCompleteController;
    1.65 +
    1.66 +// nsNavHistory
    1.67 +
    1.68 +class nsNavHistory MOZ_FINAL : public nsSupportsWeakReference
    1.69 +                             , public nsINavHistoryService
    1.70 +                             , public nsIObserver
    1.71 +                             , public nsIBrowserHistory
    1.72 +                             , public nsPIPlacesDatabase
    1.73 +                             , public nsPIPlacesHistoryListenersNotifier
    1.74 +                             , public mozIStorageVacuumParticipant
    1.75 +{
    1.76 +  friend class PlacesSQLQueryBuilder;
    1.77 +
    1.78 +public:
    1.79 +  nsNavHistory();
    1.80 +
    1.81 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.82 +  NS_DECL_NSINAVHISTORYSERVICE
    1.83 +  NS_DECL_NSIBROWSERHISTORY
    1.84 +  NS_DECL_NSIOBSERVER
    1.85 +  NS_DECL_NSPIPLACESDATABASE
    1.86 +  NS_DECL_NSPIPLACESHISTORYLISTENERSNOTIFIER
    1.87 +  NS_DECL_MOZISTORAGEVACUUMPARTICIPANT
    1.88 +
    1.89 +  /**
    1.90 +   * Obtains the nsNavHistory object.
    1.91 +   */
    1.92 +  static already_AddRefed<nsNavHistory> GetSingleton();
    1.93 +
    1.94 +  /**
    1.95 +   * Initializes the nsNavHistory object.  This should only be called once.
    1.96 +   */
    1.97 +  nsresult Init();
    1.98 +
    1.99 +  /**
   1.100 +   * Used by other components in the places directory such as the annotation
   1.101 +   * service to get a reference to this history object. Returns a pointer to
   1.102 +   * the service if it exists. Otherwise creates one. Returns nullptr on error.
   1.103 +   */
   1.104 +  static nsNavHistory* GetHistoryService()
   1.105 +  {
   1.106 +    if (!gHistoryService) {
   1.107 +      nsCOMPtr<nsINavHistoryService> serv =
   1.108 +        do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
   1.109 +      NS_ENSURE_TRUE(serv, nullptr);
   1.110 +      NS_ASSERTION(gHistoryService, "Should have static instance pointer now");
   1.111 +    }
   1.112 +    return gHistoryService;
   1.113 +  }
   1.114 +
   1.115 +  /**
   1.116 +   * Used by other components in the places directory to get a reference to a
   1.117 +   * const version of this history object.
   1.118 +   *
   1.119 +   * @return A pointer to a const version of the service if it exists,
   1.120 +   *         nullptr otherwise.
   1.121 +   */
   1.122 +  static const nsNavHistory* GetConstHistoryService()
   1.123 +  {
   1.124 +    const nsNavHistory* const history = gHistoryService;
   1.125 +    return history;
   1.126 +  }
   1.127 +
   1.128 +  /**
   1.129 +   * Fetches the database id and the GUID associated to the given URI.
   1.130 +   *
   1.131 +   * @param aURI
   1.132 +   *        The page to look for.
   1.133 +   * @param _pageId
   1.134 +   *        Will be set to the database id associated with the page.
   1.135 +   *        If the page doesn't exist, this will be zero.
   1.136 +   * @param _GUID
   1.137 +   *        Will be set to the unique id associated with the page.
   1.138 +   *        If the page doesn't exist, this will be empty.
   1.139 +   * @note This DOES NOT check for bad URLs other than that they're nonempty.
   1.140 +   */
   1.141 +  nsresult GetIdForPage(nsIURI* aURI,
   1.142 +                        int64_t* _pageId, nsCString& _GUID);
   1.143 +
   1.144 +  /**
   1.145 +   * Fetches the database id and the GUID associated to the given URI, creating
   1.146 +   * a new database entry if one doesn't exist yet.
   1.147 +   *
   1.148 +   * @param aURI
   1.149 +   *        The page to look for or create.
   1.150 +   * @param _pageId
   1.151 +   *        Will be set to the database id associated with the page.
   1.152 +   * @param _GUID
   1.153 +   *        Will be set to the unique id associated with the page.
   1.154 +   * @note This DOES NOT check for bad URLs other than that they're nonempty.
   1.155 +   * @note This DOES NOT update frecency of the page.
   1.156 +   */
   1.157 +  nsresult GetOrCreateIdForPage(nsIURI* aURI,
   1.158 +                                int64_t* _pageId, nsCString& _GUID);
   1.159 +
   1.160 +  /**
   1.161 +   * Asynchronously recalculates frecency for a given page.
   1.162 +   *
   1.163 +   * @param aPlaceId
   1.164 +   *        Place id to recalculate the frecency for.
   1.165 +   * @note If the new frecency is a non-zero value it will also unhide the page,
   1.166 +   *       otherwise will reuse the old hidden value.
   1.167 +   */
   1.168 +  nsresult UpdateFrecency(int64_t aPlaceId);
   1.169 +
   1.170 +  /**
   1.171 +   * Recalculates frecency for all pages requesting that (frecency < 0). Those
   1.172 +   * may be generated:
   1.173 +   *  * After a "clear private data"
   1.174 +   *  * After removing visits
   1.175 +   *  * After migrating from older versions
   1.176 +   */
   1.177 +  nsresult FixInvalidFrecencies();
   1.178 +
   1.179 +  /**
   1.180 +   * Invalidate the frecencies of a list of places, so they will be recalculated
   1.181 +   * at the first idle-daily notification.
   1.182 +   *
   1.183 +   * @param aPlacesIdsQueryString
   1.184 +   *        Query string containing list of places to be invalidated.  If it's
   1.185 +   *        an empty string all places will be invalidated.
   1.186 +   */
   1.187 +  nsresult invalidateFrecencies(const nsCString& aPlaceIdsQueryString);
   1.188 +
   1.189 +  /**
   1.190 +   * These functions return non-owning references to the locale-specific
   1.191 +   * objects for places components.
   1.192 +   */
   1.193 +  nsIStringBundle* GetBundle();
   1.194 +  nsIStringBundle* GetDateFormatBundle();
   1.195 +  nsICollation* GetCollation();
   1.196 +  void GetStringFromName(const char16_t* aName, nsACString& aResult);
   1.197 +  void GetAgeInDaysString(int32_t aInt, const char16_t *aName,
   1.198 +                          nsACString& aResult);
   1.199 +  void GetMonthName(int32_t aIndex, nsACString& aResult);
   1.200 +  void GetMonthYear(int32_t aMonth, int32_t aYear, nsACString& aResult);
   1.201 +
   1.202 +  // Returns whether history is enabled or not.
   1.203 +  bool IsHistoryDisabled() {
   1.204 +    return !mHistoryEnabled;
   1.205 +  }
   1.206 +
   1.207 +  // Constants for the columns returned by the above statement.
   1.208 +  static const int32_t kGetInfoIndex_PageID;
   1.209 +  static const int32_t kGetInfoIndex_URL;
   1.210 +  static const int32_t kGetInfoIndex_Title;
   1.211 +  static const int32_t kGetInfoIndex_RevHost;
   1.212 +  static const int32_t kGetInfoIndex_VisitCount;
   1.213 +  static const int32_t kGetInfoIndex_VisitDate;
   1.214 +  static const int32_t kGetInfoIndex_FaviconURL;
   1.215 +  static const int32_t kGetInfoIndex_ItemId;
   1.216 +  static const int32_t kGetInfoIndex_ItemDateAdded;
   1.217 +  static const int32_t kGetInfoIndex_ItemLastModified;
   1.218 +  static const int32_t kGetInfoIndex_ItemParentId;
   1.219 +  static const int32_t kGetInfoIndex_ItemTags;
   1.220 +  static const int32_t kGetInfoIndex_Frecency;
   1.221 +  static const int32_t kGetInfoIndex_Hidden;
   1.222 +  static const int32_t kGetInfoIndex_Guid;
   1.223 +
   1.224 +  int64_t GetTagsFolder();
   1.225 +
   1.226 +  // this actually executes a query and gives you results, it is used by
   1.227 +  // nsNavHistoryQueryResultNode
   1.228 +  nsresult GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
   1.229 +                           const nsCOMArray<nsNavHistoryQuery>& aQueries,
   1.230 +                           nsNavHistoryQueryOptions *aOptions,
   1.231 +                           nsCOMArray<nsNavHistoryResultNode>* aResults);
   1.232 +
   1.233 +  // Take a row of kGetInfoIndex_* columns and construct a ResultNode.
   1.234 +  // The row must contain the full set of columns.
   1.235 +  nsresult RowToResult(mozIStorageValueArray* aRow,
   1.236 +                       nsNavHistoryQueryOptions* aOptions,
   1.237 +                       nsNavHistoryResultNode** aResult);
   1.238 +  nsresult QueryRowToResult(int64_t aItemId, const nsACString& aURI,
   1.239 +                            const nsACString& aTitle,
   1.240 +                            uint32_t aAccessCount, PRTime aTime,
   1.241 +                            const nsACString& aFavicon,
   1.242 +                            nsNavHistoryResultNode** aNode);
   1.243 +
   1.244 +  nsresult VisitIdToResultNode(int64_t visitId,
   1.245 +                               nsNavHistoryQueryOptions* aOptions,
   1.246 +                               nsNavHistoryResultNode** aResult);
   1.247 +
   1.248 +  nsresult BookmarkIdToResultNode(int64_t aBookmarkId,
   1.249 +                                  nsNavHistoryQueryOptions* aOptions,
   1.250 +                                  nsNavHistoryResultNode** aResult);
   1.251 +  nsresult URIToResultNode(nsIURI* aURI,
   1.252 +                           nsNavHistoryQueryOptions* aOptions,
   1.253 +                           nsNavHistoryResultNode** aResult);
   1.254 +
   1.255 +  // used by other places components to send history notifications (for example,
   1.256 +  // when the favicon has changed)
   1.257 +  void SendPageChangedNotification(nsIURI* aURI, uint32_t aChangedAttribute,
   1.258 +                                   const nsAString& aValue,
   1.259 +                                   const nsACString& aGUID);
   1.260 +
   1.261 +  /**
   1.262 +   * Returns current number of days stored in history.
   1.263 +   */
   1.264 +  int32_t GetDaysOfHistory();
   1.265 +
   1.266 +  // used by query result nodes to update: see comment on body of CanLiveUpdateQuery
   1.267 +  static uint32_t GetUpdateRequirements(const nsCOMArray<nsNavHistoryQuery>& aQueries,
   1.268 +                                        nsNavHistoryQueryOptions* aOptions,
   1.269 +                                        bool* aHasSearchTerms);
   1.270 +  bool EvaluateQueryForNode(const nsCOMArray<nsNavHistoryQuery>& aQueries,
   1.271 +                              nsNavHistoryQueryOptions* aOptions,
   1.272 +                              nsNavHistoryResultNode* aNode);
   1.273 +
   1.274 +  static nsresult AsciiHostNameFromHostString(const nsACString& aHostName,
   1.275 +                                              nsACString& aAscii);
   1.276 +  void DomainNameFromURI(nsIURI* aURI,
   1.277 +                         nsACString& aDomainName);
   1.278 +  static PRTime NormalizeTime(uint32_t aRelative, PRTime aOffset);
   1.279 +
   1.280 +  // Don't use these directly, inside nsNavHistory use UpdateBatchScoper,
   1.281 +  // else use nsINavHistoryService::RunInBatchMode
   1.282 +  nsresult BeginUpdateBatch();
   1.283 +  nsresult EndUpdateBatch();
   1.284 +
   1.285 +  // The level of batches' nesting, 0 when no batches are open.
   1.286 +  int32_t mBatchLevel;
   1.287 +  // Current active transaction for a batch.
   1.288 +  mozStorageTransaction* mBatchDBTransaction;
   1.289 +
   1.290 +  // better alternative to QueryStringToQueries (in nsNavHistoryQuery.cpp)
   1.291 +  nsresult QueryStringToQueryArray(const nsACString& aQueryString,
   1.292 +                                   nsCOMArray<nsNavHistoryQuery>* aQueries,
   1.293 +                                   nsNavHistoryQueryOptions** aOptions);
   1.294 +
   1.295 +  typedef nsDataHashtable<nsCStringHashKey, nsCString> StringHash;
   1.296 +
   1.297 +  /**
   1.298 +   * Indicates if it is OK to notify history observers or not.
   1.299 +   *
   1.300 +   * @return true if it is OK to notify, false otherwise.
   1.301 +   */
   1.302 +  bool canNotify() { return mCanNotify; }
   1.303 +
   1.304 +  enum RecentEventFlags {
   1.305 +    RECENT_TYPED      = 1 << 0,    // User typed in URL recently
   1.306 +    RECENT_ACTIVATED  = 1 << 1,    // User tapped URL link recently
   1.307 +    RECENT_BOOKMARKED = 1 << 2     // User bookmarked URL recently
   1.308 +  };
   1.309 +
   1.310 +  /**
   1.311 +   * Returns any recent activity done with a URL.
   1.312 +   * @return Any recent events associated with this URI.  Each bit is set
   1.313 +   *         according to RecentEventFlags enum values.
   1.314 +   */
   1.315 +  uint32_t GetRecentFlags(nsIURI *aURI);
   1.316 +
   1.317 +  /**
   1.318 +   * Registers a TRANSITION_EMBED visit for the session.
   1.319 +   *
   1.320 +   * @param aURI
   1.321 +   *        URI of the page.
   1.322 +   * @param aTime
   1.323 +   *        Visit time.  Only the last registered visit time is retained.
   1.324 +   */
   1.325 +  void registerEmbedVisit(nsIURI* aURI, int64_t aTime);
   1.326 +
   1.327 +  /**
   1.328 +   * Returns whether the specified url has a embed visit.
   1.329 +   *
   1.330 +   * @param aURI
   1.331 +   *        URI of the page.
   1.332 +   * @return whether the page has a embed visit.
   1.333 +   */
   1.334 +  bool hasEmbedVisit(nsIURI* aURI);
   1.335 +
   1.336 +  /**
   1.337 +   * Clears all registered embed visits.
   1.338 +   */
   1.339 +  void clearEmbedVisits();
   1.340 +
   1.341 +  int32_t GetFrecencyAgedWeight(int32_t aAgeInDays) const
   1.342 +  {
   1.343 +    if (aAgeInDays <= mFirstBucketCutoffInDays) {
   1.344 +      return mFirstBucketWeight;
   1.345 +    }
   1.346 +    if (aAgeInDays <= mSecondBucketCutoffInDays) {
   1.347 +      return mSecondBucketWeight;
   1.348 +    }
   1.349 +    if (aAgeInDays <= mThirdBucketCutoffInDays) {
   1.350 +      return mThirdBucketWeight;
   1.351 +    }
   1.352 +    if (aAgeInDays <= mFourthBucketCutoffInDays) {
   1.353 +      return mFourthBucketWeight;
   1.354 +    }
   1.355 +    return mDefaultWeight;
   1.356 +  }
   1.357 +
   1.358 +  int32_t GetFrecencyBucketWeight(int32_t aBucketIndex) const
   1.359 +  {
   1.360 +    switch(aBucketIndex) {
   1.361 +      case 1:
   1.362 +        return mFirstBucketWeight;
   1.363 +      case 2:
   1.364 +        return mSecondBucketWeight;
   1.365 +      case 3:
   1.366 +        return mThirdBucketWeight;
   1.367 +      case 4:
   1.368 +        return mFourthBucketWeight;
   1.369 +      default:
   1.370 +        return mDefaultWeight;
   1.371 +    }
   1.372 +  }
   1.373 +
   1.374 +  int32_t GetFrecencyTransitionBonus(int32_t aTransitionType,
   1.375 +                                     bool aVisited) const
   1.376 +  {
   1.377 +    switch (aTransitionType) {
   1.378 +      case nsINavHistoryService::TRANSITION_EMBED:
   1.379 +        return mEmbedVisitBonus;
   1.380 +      case nsINavHistoryService::TRANSITION_FRAMED_LINK:
   1.381 +        return mFramedLinkVisitBonus;
   1.382 +      case nsINavHistoryService::TRANSITION_LINK:
   1.383 +        return mLinkVisitBonus;
   1.384 +      case nsINavHistoryService::TRANSITION_TYPED:
   1.385 +        return aVisited ? mTypedVisitBonus : mUnvisitedTypedBonus;
   1.386 +      case nsINavHistoryService::TRANSITION_BOOKMARK:
   1.387 +        return aVisited ? mBookmarkVisitBonus : mUnvisitedBookmarkBonus;
   1.388 +      case nsINavHistoryService::TRANSITION_DOWNLOAD:
   1.389 +        return mDownloadVisitBonus;
   1.390 +      case nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT:
   1.391 +        return mPermRedirectVisitBonus;
   1.392 +      case nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY:
   1.393 +        return mTempRedirectVisitBonus;
   1.394 +      default:
   1.395 +        // 0 == undefined (see bug #375777 for details)
   1.396 +        NS_WARN_IF_FALSE(!aTransitionType, "new transition but no bonus for frecency");
   1.397 +        return mDefaultVisitBonus;
   1.398 +    }
   1.399 +  }
   1.400 +
   1.401 +  int32_t GetNumVisitsForFrecency() const
   1.402 +  {
   1.403 +    return mNumVisitsForFrecency;
   1.404 +  }
   1.405 +
   1.406 +  /**
   1.407 +   * Fires onVisit event to nsINavHistoryService observers
   1.408 +   */
   1.409 +  void NotifyOnVisit(nsIURI* aURI,
   1.410 +                     int64_t aVisitID,
   1.411 +                     PRTime aTime,
   1.412 +                     int64_t referringVisitID,
   1.413 +                     int32_t aTransitionType,
   1.414 +                     const nsACString& aGUID,
   1.415 +                     bool aHidden);
   1.416 +
   1.417 +  /**
   1.418 +   * Fires onTitleChanged event to nsINavHistoryService observers
   1.419 +   */
   1.420 +  void NotifyTitleChange(nsIURI* aURI,
   1.421 +                         const nsString& title,
   1.422 +                         const nsACString& aGUID);
   1.423 +
   1.424 +  /**
   1.425 +   * Fires onFrecencyChanged event to nsINavHistoryService observers
   1.426 +   */
   1.427 +  void NotifyFrecencyChanged(nsIURI* aURI,
   1.428 +                             int32_t aNewFrecency,
   1.429 +                             const nsACString& aGUID,
   1.430 +                             bool aHidden,
   1.431 +                             PRTime aLastVisitDate);
   1.432 +
   1.433 +  /**
   1.434 +   * Fires onManyFrecenciesChanged event to nsINavHistoryService observers
   1.435 +   */
   1.436 +  void NotifyManyFrecenciesChanged();
   1.437 +
   1.438 +  /**
   1.439 +   * Posts a runnable to the main thread that calls NotifyFrecencyChanged.
   1.440 +   */
   1.441 +  void DispatchFrecencyChangedNotification(const nsACString& aSpec,
   1.442 +                                           int32_t aNewFrecency,
   1.443 +                                           const nsACString& aGUID,
   1.444 +                                           bool aHidden,
   1.445 +                                           PRTime aLastVisitDate) const;
   1.446 +
   1.447 +  bool isBatching() {
   1.448 +    return mBatchLevel > 0;
   1.449 +  }
   1.450 +
   1.451 +private:
   1.452 +  ~nsNavHistory();
   1.453 +
   1.454 +  // used by GetHistoryService
   1.455 +  static nsNavHistory *gHistoryService;
   1.456 +
   1.457 +protected:
   1.458 +
   1.459 +  // Database handle.
   1.460 +  nsRefPtr<mozilla::places::Database> mDB;
   1.461 +
   1.462 +  /**
   1.463 +   * Decays frecency and inputhistory values.  Runs on idle-daily.
   1.464 +   */
   1.465 +  nsresult DecayFrecency();
   1.466 +
   1.467 +  nsresult CalculateFrecency(int64_t aPageID, int32_t aTyped, int32_t aVisitCount, nsAutoCString &aURL, int32_t *aFrecency);
   1.468 +  nsresult CalculateFrecencyInternal(int64_t aPageID, int32_t aTyped, int32_t aVisitCount, bool aIsBookmarked, int32_t *aFrecency);
   1.469 +
   1.470 +  nsresult RemovePagesInternal(const nsCString& aPlaceIdsQueryString);
   1.471 +  nsresult CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString);
   1.472 +
   1.473 +  /**
   1.474 +   * Loads all of the preferences that we use into member variables.
   1.475 +   *
   1.476 +   * @note If mPrefBranch is nullptr, this does nothing.
   1.477 +   */
   1.478 +  void LoadPrefs();
   1.479 +
   1.480 +  /**
   1.481 +   * Calculates and returns value for mCachedNow.
   1.482 +   * This is an hack to avoid calling PR_Now() too often, as is the case when
   1.483 +   * we're asked the ageindays of many history entries in a row.  A timer is
   1.484 +   * set which will clear our valid flag after a short timeout.
   1.485 +   */
   1.486 +  PRTime GetNow();
   1.487 +  PRTime mCachedNow;
   1.488 +  nsCOMPtr<nsITimer> mExpireNowTimer;
   1.489 +  /**
   1.490 +   * Called when the cached now value is expired and needs renewal.
   1.491 +   */
   1.492 +  static void expireNowTimerCallback(nsITimer* aTimer, void* aClosure);
   1.493 +
   1.494 +  nsresult ConstructQueryString(const nsCOMArray<nsNavHistoryQuery>& aQueries, 
   1.495 +                                nsNavHistoryQueryOptions* aOptions,
   1.496 +                                nsCString& queryString,
   1.497 +                                bool& aParamsPresent,
   1.498 +                                StringHash& aAddParams);
   1.499 +
   1.500 +  nsresult QueryToSelectClause(nsNavHistoryQuery* aQuery,
   1.501 +                               nsNavHistoryQueryOptions* aOptions,
   1.502 +                               int32_t aQueryIndex,
   1.503 +                               nsCString* aClause);
   1.504 +  nsresult BindQueryClauseParameters(mozIStorageBaseStatement* statement,
   1.505 +                                     int32_t aQueryIndex,
   1.506 +                                     nsNavHistoryQuery* aQuery,
   1.507 +                                     nsNavHistoryQueryOptions* aOptions);
   1.508 +
   1.509 +  nsresult ResultsAsList(mozIStorageStatement* statement,
   1.510 +                         nsNavHistoryQueryOptions* aOptions,
   1.511 +                         nsCOMArray<nsNavHistoryResultNode>* aResults);
   1.512 +
   1.513 +  void TitleForDomain(const nsCString& domain, nsACString& aTitle);
   1.514 +
   1.515 +  nsresult FilterResultSet(nsNavHistoryQueryResultNode *aParentNode,
   1.516 +                           const nsCOMArray<nsNavHistoryResultNode>& aSet,
   1.517 +                           nsCOMArray<nsNavHistoryResultNode>* aFiltered,
   1.518 +                           const nsCOMArray<nsNavHistoryQuery>& aQueries,
   1.519 +                           nsNavHistoryQueryOptions* aOptions);
   1.520 +
   1.521 +  // observers
   1.522 +  nsMaybeWeakPtrArray<nsINavHistoryObserver> mObservers;
   1.523 +
   1.524 +  // effective tld service
   1.525 +  nsCOMPtr<nsIEffectiveTLDService> mTLDService;
   1.526 +  nsCOMPtr<nsIIDNService>          mIDNService;
   1.527 +
   1.528 +  // localization
   1.529 +  nsCOMPtr<nsIStringBundle> mBundle;
   1.530 +  nsCOMPtr<nsIStringBundle> mDateFormatBundle;
   1.531 +  nsCOMPtr<nsICollation> mCollation;
   1.532 +
   1.533 +  // recent events
   1.534 +  typedef nsDataHashtable<nsCStringHashKey, int64_t> RecentEventHash;
   1.535 +  RecentEventHash mRecentTyped;
   1.536 +  RecentEventHash mRecentLink;
   1.537 +  RecentEventHash mRecentBookmark;
   1.538 +
   1.539 +  // Embed visits tracking.
   1.540 +  class VisitHashKey : public nsURIHashKey
   1.541 +  {
   1.542 +  public:
   1.543 +    VisitHashKey(const nsIURI* aURI)
   1.544 +    : nsURIHashKey(aURI)
   1.545 +    {
   1.546 +    }
   1.547 +    VisitHashKey(const VisitHashKey& aOther)
   1.548 +    : nsURIHashKey(aOther)
   1.549 +    {
   1.550 +      NS_NOTREACHED("Do not call me!");
   1.551 +    }
   1.552 +    PRTime visitTime;
   1.553 +  };
   1.554 +
   1.555 +  nsTHashtable<VisitHashKey> mEmbedVisits;
   1.556 +
   1.557 +  bool CheckIsRecentEvent(RecentEventHash* hashTable,
   1.558 +                            const nsACString& url);
   1.559 +  void ExpireNonrecentEvents(RecentEventHash* hashTable);
   1.560 +
   1.561 +#ifdef MOZ_XUL
   1.562 +  nsresult AutoCompleteFeedback(int32_t aIndex,
   1.563 +                                nsIAutoCompleteController *aController);
   1.564 +#endif
   1.565 +
   1.566 +  // Whether history is enabled or not.
   1.567 +  // Will mimic value of the places.history.enabled preference.
   1.568 +  bool mHistoryEnabled;
   1.569 +
   1.570 +  // Frecency preferences.
   1.571 +  int32_t mNumVisitsForFrecency;
   1.572 +  int32_t mFirstBucketCutoffInDays;
   1.573 +  int32_t mSecondBucketCutoffInDays;
   1.574 +  int32_t mThirdBucketCutoffInDays;
   1.575 +  int32_t mFourthBucketCutoffInDays;
   1.576 +  int32_t mFirstBucketWeight;
   1.577 +  int32_t mSecondBucketWeight;
   1.578 +  int32_t mThirdBucketWeight;
   1.579 +  int32_t mFourthBucketWeight;
   1.580 +  int32_t mDefaultWeight;
   1.581 +  int32_t mEmbedVisitBonus;
   1.582 +  int32_t mFramedLinkVisitBonus;
   1.583 +  int32_t mLinkVisitBonus;
   1.584 +  int32_t mTypedVisitBonus;
   1.585 +  int32_t mBookmarkVisitBonus;
   1.586 +  int32_t mDownloadVisitBonus;
   1.587 +  int32_t mPermRedirectVisitBonus;
   1.588 +  int32_t mTempRedirectVisitBonus;
   1.589 +  int32_t mDefaultVisitBonus;
   1.590 +  int32_t mUnvisitedBookmarkBonus;
   1.591 +  int32_t mUnvisitedTypedBonus;
   1.592 +
   1.593 +  // in nsNavHistoryQuery.cpp
   1.594 +  nsresult TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
   1.595 +                           nsCOMArray<nsNavHistoryQuery>* aQueries,
   1.596 +                           nsNavHistoryQueryOptions* aOptions);
   1.597 +
   1.598 +  int64_t mTagsFolder;
   1.599 +
   1.600 +  int32_t mDaysOfHistory;
   1.601 +  int64_t mLastCachedStartOfDay;
   1.602 +  int64_t mLastCachedEndOfDay;
   1.603 +
   1.604 +  // Used to enable and disable the observer notifications
   1.605 +  bool mCanNotify;
   1.606 +  nsCategoryCache<nsINavHistoryObserver> mCacheObservers;
   1.607 +};
   1.608 +
   1.609 +
   1.610 +#define PLACES_URI_PREFIX "place:"
   1.611 +
   1.612 +/* Returns true if the given URI represents a history query. */
   1.613 +inline bool IsQueryURI(const nsCString &uri)
   1.614 +{
   1.615 +  return StringBeginsWith(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX));
   1.616 +}
   1.617 +
   1.618 +/* Extracts the query string from a query URI. */
   1.619 +inline const nsDependentCSubstring QueryURIToQuery(const nsCString &uri)
   1.620 +{
   1.621 +  NS_ASSERTION(IsQueryURI(uri), "should only be called for query URIs");
   1.622 +  return Substring(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX).Length());
   1.623 +}
   1.624 +
   1.625 +#endif // nsNavHistory_h_

mercurial