2006-07-18 19:19:31 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Places code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Google Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brett Wilson <brettw@gmail.com> (original author)
|
2008-02-28 19:04:13 +03:00
|
|
|
* Edward Lee <edward.lee@engineering.uiuc.edu>
|
2008-10-20 01:14:59 +04:00
|
|
|
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2009-10-09 14:30:12 +04:00
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2006-07-18 19:19:31 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2006-07-18 19:21:48 +04:00
|
|
|
#ifndef nsNavHistory_h_
|
|
|
|
#define nsNavHistory_h_
|
2006-07-18 19:19:31 +04:00
|
|
|
|
2006-07-18 19:32:44 +04:00
|
|
|
#include "nsINavHistoryService.h"
|
2008-08-17 02:21:23 +04:00
|
|
|
#include "nsPIPlacesDatabase.h"
|
2009-03-03 21:27:01 +03:00
|
|
|
#include "nsPIPlacesHistoryListenersNotifier.h"
|
2006-07-18 19:19:31 +04:00
|
|
|
#include "nsIBrowserHistory.h"
|
|
|
|
#include "nsIGlobalHistory.h"
|
2006-07-18 19:39:13 +04:00
|
|
|
#include "nsIGlobalHistory3.h"
|
2007-12-22 05:27:11 +03:00
|
|
|
#include "nsIDownloadHistory.h"
|
2009-11-11 14:04:18 +03:00
|
|
|
|
2006-07-18 19:19:31 +04:00
|
|
|
#include "nsIPrefService.h"
|
2010-01-15 19:40:19 +03:00
|
|
|
#include "nsIPrefBranch2.h"
|
2006-07-18 19:19:31 +04:00
|
|
|
#include "nsIObserverService.h"
|
2009-11-11 14:04:18 +03:00
|
|
|
#include "nsICollation.h"
|
2006-07-18 19:19:31 +04:00
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsITimer.h"
|
2006-07-18 19:29:17 +04:00
|
|
|
#include "nsMaybeWeakPtr.h"
|
2009-03-25 23:31:36 +03:00
|
|
|
#include "nsCategoryCache.h"
|
2009-11-11 14:04:18 +03:00
|
|
|
#include "nsICharsetResolver.h"
|
|
|
|
#include "nsNetCID.h"
|
2009-12-01 16:00:45 +03:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2010-10-11 16:53:31 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2010-11-13 01:24:25 +03:00
|
|
|
#include "nsURIHashKey.h"
|
|
|
|
#include "nsTHashtable.h"
|
2009-11-11 14:04:18 +03:00
|
|
|
|
|
|
|
#include "nsINavBookmarksService.h"
|
|
|
|
#include "nsIPrivateBrowsingService.h"
|
2010-03-25 14:34:49 +03:00
|
|
|
#include "nsIFaviconService.h"
|
2006-07-18 19:34:16 +04:00
|
|
|
#include "nsNavHistoryResult.h"
|
|
|
|
#include "nsNavHistoryQuery.h"
|
|
|
|
|
2009-11-11 14:04:18 +03:00
|
|
|
#include "mozilla/storage.h"
|
2008-10-20 01:14:59 +04:00
|
|
|
|
2006-07-18 19:36:33 +04:00
|
|
|
#define QUERYUPDATE_TIME 0
|
|
|
|
#define QUERYUPDATE_SIMPLE 1
|
|
|
|
#define QUERYUPDATE_COMPLEX 2
|
|
|
|
#define QUERYUPDATE_COMPLEX_WITH_BOOKMARKS 3
|
2008-02-27 07:48:51 +03:00
|
|
|
#define QUERYUPDATE_HOST 4
|
2008-01-05 08:16:27 +03:00
|
|
|
|
2008-10-20 01:14:59 +04:00
|
|
|
// This magic number specified an uninitialized value for the
|
|
|
|
// mInPrivateBrowsing member
|
|
|
|
#define PRIVATEBROWSING_NOTINITED (PRBool(0xffffffff))
|
|
|
|
|
2009-12-22 15:05:14 +03:00
|
|
|
// Clamp title and URL to generously large, but not too large, length.
|
|
|
|
// See bug 319004 for details.
|
|
|
|
#define URI_LENGTH_MAX 65536
|
|
|
|
#define TITLE_LENGTH_MAX 4096
|
|
|
|
|
2010-07-14 05:00:33 +04:00
|
|
|
// Microsecond timeout for "recent" events such as typed and bookmark following.
|
|
|
|
// If you typed it more than this time ago, it's not recent.
|
|
|
|
#define RECENT_EVENT_THRESHOLD PRTime((PRInt64)15 * 60 * PR_USEC_PER_SEC)
|
|
|
|
|
2010-04-22 16:53:54 +04:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
// Fired after autocomplete feedback has been updated.
|
|
|
|
#define TOPIC_AUTOCOMPLETE_FEEDBACK_UPDATED "places-autocomplete-feedback-updated"
|
|
|
|
#endif
|
2010-08-28 05:24:54 +04:00
|
|
|
|
2010-10-11 16:53:31 +04:00
|
|
|
// Fired after frecency has been updated.
|
|
|
|
#define TOPIC_FRECENCY_UPDATED "places-frecency-updated"
|
|
|
|
|
2010-10-11 16:53:39 +04:00
|
|
|
// Fired after frecency has been updated.
|
|
|
|
#define TOPIC_FRECENCY_UPDATED "places-frecency-updated"
|
|
|
|
|
2010-08-28 05:24:54 +04:00
|
|
|
// Fired when Places is shutting down. Any code should stop accessing Places
|
|
|
|
// APIs after this notification. If you need to listen for Places shutdown
|
|
|
|
// you should only use this notification, next ones are intended only for
|
|
|
|
// internal Places use.
|
2010-04-22 16:53:54 +04:00
|
|
|
#define TOPIC_PLACES_SHUTDOWN "places-shutdown"
|
2010-08-28 05:24:54 +04:00
|
|
|
// For Internal use only. Fired when connection is about to be closed, only
|
|
|
|
// cleanup tasks should run at this stage, nothing should be added to the
|
|
|
|
// database, nor APIs should be called.
|
|
|
|
#define TOPIC_PLACES_WILL_CLOSE_CONNECTION "places-will-close-connection"
|
|
|
|
// For Internal use only. Fired as the last notification before the connection
|
|
|
|
// is gone.
|
|
|
|
#define TOPIC_PLACES_CONNECTION_CLOSING "places-connection-closing"
|
|
|
|
// Fired when the connection has gone, nothing will work from now on.
|
|
|
|
#define TOPIC_PLACES_CONNECTION_CLOSED "places-connection-closed"
|
|
|
|
|
2010-04-22 16:53:54 +04:00
|
|
|
// Fired when Places found a locked database while initing.
|
|
|
|
#define TOPIC_DATABASE_LOCKED "places-database-locked"
|
|
|
|
// Fired after Places inited.
|
|
|
|
#define TOPIC_PLACES_INIT_COMPLETE "places-init-complete"
|
|
|
|
|
2010-03-25 14:34:33 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace places {
|
|
|
|
|
|
|
|
enum HistoryStatementId {
|
2010-04-27 15:25:03 +04:00
|
|
|
DB_GET_PAGE_INFO_BY_URL = 0
|
2010-10-11 16:53:31 +04:00
|
|
|
, DB_GET_TAGS
|
|
|
|
, DB_IS_PAGE_VISITED
|
|
|
|
, DB_INSERT_VISIT
|
|
|
|
, DB_RECENT_VISIT_OF_URL
|
|
|
|
, DB_GET_PAGE_VISIT_STATS
|
|
|
|
, DB_UPDATE_PAGE_VISIT_STATS
|
|
|
|
, DB_ADD_NEW_PAGE
|
|
|
|
, DB_GET_URL_PAGE_INFO
|
|
|
|
, DB_SET_PLACE_TITLE
|
|
|
|
, DB_PAGE_INFO_FOR_FRECENCY
|
|
|
|
, DB_VISITS_FOR_FRECENCY
|
2010-03-25 14:34:33 +03:00
|
|
|
};
|
|
|
|
|
2010-09-13 20:29:42 +04:00
|
|
|
enum JournalMode {
|
|
|
|
// Default SQLite journal mode.
|
|
|
|
JOURNAL_DELETE = 0
|
|
|
|
// Can reduce fsyncs on Linux when journal is deleted (See bug 460315).
|
|
|
|
// We fallback to this mode when WAL is unavailable.
|
|
|
|
, JOURNAL_TRUNCATE
|
|
|
|
// Unsafe in case of crashes on database swap or low memory.
|
|
|
|
, JOURNAL_MEMORY
|
|
|
|
// Can reduce number of fsyncs. We try to use this mode by default.
|
|
|
|
, JOURNAL_WAL
|
|
|
|
};
|
|
|
|
|
2010-03-25 14:34:33 +03:00
|
|
|
} // namespace places
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-11-12 23:45:53 +03:00
|
|
|
|
2006-07-18 19:19:31 +04:00
|
|
|
class mozIAnnotationService;
|
2006-07-18 19:21:48 +04:00
|
|
|
class nsNavHistory;
|
2006-07-18 19:26:16 +04:00
|
|
|
class nsNavBookmarks;
|
2006-07-18 19:35:25 +04:00
|
|
|
class QueryKeyValuePair;
|
2008-02-07 07:18:17 +03:00
|
|
|
class nsIEffectiveTLDService;
|
|
|
|
class nsIIDNService;
|
2008-02-27 07:48:51 +03:00
|
|
|
class PlacesSQLQueryBuilder;
|
2009-07-13 23:19:03 +04:00
|
|
|
class nsIAutoCompleteController;
|
2006-07-18 19:19:31 +04:00
|
|
|
|
|
|
|
// nsNavHistory
|
|
|
|
|
2009-03-03 21:27:01 +03:00
|
|
|
class nsNavHistory : public nsSupportsWeakReference
|
|
|
|
, public nsINavHistoryService
|
|
|
|
, public nsIObserver
|
|
|
|
, public nsIBrowserHistory
|
|
|
|
, public nsIGlobalHistory3
|
|
|
|
, public nsIDownloadHistory
|
|
|
|
, public nsICharsetResolver
|
2008-08-17 02:21:23 +04:00
|
|
|
, public nsPIPlacesDatabase
|
2009-03-03 21:27:01 +03:00
|
|
|
, public nsPIPlacesHistoryListenersNotifier
|
2010-10-21 14:19:05 +04:00
|
|
|
, public mozIStorageVacuumParticipant
|
2006-07-18 19:19:31 +04:00
|
|
|
{
|
2008-02-27 07:48:51 +03:00
|
|
|
friend class PlacesSQLQueryBuilder;
|
|
|
|
|
2006-07-18 19:19:31 +04:00
|
|
|
public:
|
|
|
|
nsNavHistory();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2006-07-18 19:32:44 +04:00
|
|
|
NS_DECL_NSINAVHISTORYSERVICE
|
2006-07-18 19:19:31 +04:00
|
|
|
NS_DECL_NSIGLOBALHISTORY2
|
2006-07-18 19:39:13 +04:00
|
|
|
NS_DECL_NSIGLOBALHISTORY3
|
2007-12-22 05:27:11 +03:00
|
|
|
NS_DECL_NSIDOWNLOADHISTORY
|
2006-07-18 19:19:31 +04:00
|
|
|
NS_DECL_NSIBROWSERHISTORY
|
|
|
|
NS_DECL_NSIOBSERVER
|
2008-08-17 02:21:23 +04:00
|
|
|
NS_DECL_NSPIPLACESDATABASE
|
2009-03-03 21:27:01 +03:00
|
|
|
NS_DECL_NSPIPLACESHISTORYLISTENERSNOTIFIER
|
2010-10-21 14:19:05 +04:00
|
|
|
NS_DECL_MOZISTORAGEVACUUMPARTICIPANT
|
2008-02-18 06:36:32 +03:00
|
|
|
|
2008-02-18 06:36:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains the nsNavHistory object.
|
|
|
|
*/
|
2009-12-02 19:39:16 +03:00
|
|
|
static nsNavHistory *GetSingleton();
|
2008-02-18 06:36:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the nsNavHistory object. This should only be called once.
|
|
|
|
*/
|
2006-07-18 19:19:31 +04:00
|
|
|
nsresult Init();
|
|
|
|
|
2006-07-18 19:20:39 +04:00
|
|
|
/**
|
|
|
|
* Used by other components in the places directory such as the annotation
|
|
|
|
* service to get a reference to this history object. Returns a pointer to
|
|
|
|
* the service if it exists. Otherwise creates one. Returns NULL on error.
|
|
|
|
*/
|
2009-12-02 19:39:16 +03:00
|
|
|
static nsNavHistory *GetHistoryService()
|
2006-07-18 19:20:39 +04:00
|
|
|
{
|
2009-12-01 16:00:45 +03:00
|
|
|
if (!gHistoryService) {
|
|
|
|
nsCOMPtr<nsINavHistoryService> serv =
|
|
|
|
do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(serv, nsnull);
|
|
|
|
NS_ASSERTION(gHistoryService, "Should have static instance pointer now");
|
|
|
|
}
|
2006-07-18 19:20:39 +04:00
|
|
|
return gHistoryService;
|
|
|
|
}
|
|
|
|
|
2010-10-11 16:53:31 +04:00
|
|
|
/**
|
|
|
|
* Used by other components in the places directory to get a reference to a
|
|
|
|
* const version of this history object.
|
|
|
|
*
|
|
|
|
* @return A pointer to a const version of the service if it exists,
|
|
|
|
* NULL otherwise.
|
|
|
|
*/
|
|
|
|
static const nsNavHistory* GetConstHistoryService()
|
|
|
|
{
|
|
|
|
const nsNavHistory* const history = gHistoryService;
|
|
|
|
return history;
|
|
|
|
}
|
|
|
|
|
2006-07-18 19:43:26 +04:00
|
|
|
/**
|
2007-02-26 03:54:36 +03:00
|
|
|
* Returns the database ID for the given URI, or 0 if not found and autoCreate
|
2006-07-18 19:43:26 +04:00
|
|
|
* is false.
|
|
|
|
*/
|
2006-07-18 19:20:39 +04:00
|
|
|
nsresult GetUrlIdFor(nsIURI* aURI, PRInt64* aEntryID,
|
|
|
|
PRBool aAutoCreate);
|
|
|
|
|
2010-10-11 16:53:31 +04:00
|
|
|
nsresult UpdateFrecency(PRInt64 aPlaceId);
|
2008-01-25 20:11:14 +03:00
|
|
|
|
2009-04-10 19:24:10 +04:00
|
|
|
/**
|
|
|
|
* Calculate frecencies for places that don't have a valid value yet
|
|
|
|
*/
|
|
|
|
nsresult FixInvalidFrecencies();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the frecencies of excluded places so they don't show up in queries
|
|
|
|
*/
|
2008-01-25 20:11:14 +03:00
|
|
|
nsresult FixInvalidFrecenciesForExcludedPlaces();
|
|
|
|
|
2006-07-18 19:20:39 +04:00
|
|
|
/**
|
2006-07-18 19:44:34 +04:00
|
|
|
* Returns a pointer to the storage connection used by history. This
|
|
|
|
* connection object is also used by the annotation service and bookmarks, so
|
|
|
|
* that things can be grouped into transactions across these components.
|
|
|
|
*
|
|
|
|
* NOT ADDREFed.
|
2006-07-18 19:20:39 +04:00
|
|
|
*
|
|
|
|
* This connection can only be used in the thread that created it the
|
|
|
|
* history service!
|
|
|
|
*/
|
|
|
|
mozIStorageConnection* GetStorageConnection()
|
|
|
|
{
|
|
|
|
return mDBConn;
|
|
|
|
}
|
|
|
|
|
2006-07-18 19:36:33 +04:00
|
|
|
/**
|
|
|
|
* These functions return non-owning references to the locale-specific
|
2008-10-28 01:52:21 +03:00
|
|
|
* objects for places components.
|
2006-07-18 19:36:33 +04:00
|
|
|
*/
|
2008-10-28 01:52:22 +03:00
|
|
|
nsIStringBundle* GetBundle();
|
2009-03-23 15:42:03 +03:00
|
|
|
nsIStringBundle* GetDateFormatBundle();
|
2008-10-28 01:52:21 +03:00
|
|
|
nsICollation* GetCollation();
|
2008-02-27 07:48:51 +03:00
|
|
|
void GetStringFromName(const PRUnichar* aName, nsACString& aResult);
|
2008-10-28 01:52:22 +03:00
|
|
|
void GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName,
|
|
|
|
nsACString& aResult);
|
2009-03-23 15:42:03 +03:00
|
|
|
void GetMonthName(PRInt32 aIndex, nsACString& aResult);
|
2011-04-28 21:55:06 +04:00
|
|
|
void GetMonthYear(PRInt32 aMonth, PRInt32 aYear, nsACString& aResult);
|
2006-07-18 19:20:39 +04:00
|
|
|
|
2010-01-15 19:40:14 +03:00
|
|
|
// Returns whether history is enabled or not.
|
|
|
|
PRBool IsHistoryDisabled() {
|
2010-01-15 19:40:19 +03:00
|
|
|
return !mHistoryEnabled || InPrivateBrowsingMode();
|
2010-01-15 19:40:14 +03:00
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2006-07-18 19:21:48 +04:00
|
|
|
// Constants for the columns returned by the above statement.
|
|
|
|
static const PRInt32 kGetInfoIndex_PageID;
|
|
|
|
static const PRInt32 kGetInfoIndex_URL;
|
|
|
|
static const PRInt32 kGetInfoIndex_Title;
|
|
|
|
static const PRInt32 kGetInfoIndex_RevHost;
|
2006-07-18 19:30:25 +04:00
|
|
|
static const PRInt32 kGetInfoIndex_VisitCount;
|
2011-04-14 00:15:41 +04:00
|
|
|
static const PRInt32 kGetInfoIndex_VisitDate;
|
|
|
|
static const PRInt32 kGetInfoIndex_FaviconURL;
|
|
|
|
static const PRInt32 kGetInfoIndex_SessionId;
|
2007-05-10 12:05:19 +04:00
|
|
|
static const PRInt32 kGetInfoIndex_ItemId;
|
2007-05-19 04:40:55 +04:00
|
|
|
static const PRInt32 kGetInfoIndex_ItemDateAdded;
|
|
|
|
static const PRInt32 kGetInfoIndex_ItemLastModified;
|
2009-10-05 14:12:38 +04:00
|
|
|
static const PRInt32 kGetInfoIndex_ItemParentId;
|
2011-04-14 00:15:41 +04:00
|
|
|
static const PRInt32 kGetInfoIndex_ItemTags;
|
|
|
|
static const PRInt32 kGetInfoIndex_Frecency;
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2008-11-05 21:20:00 +03:00
|
|
|
PRInt64 GetTagsFolder();
|
|
|
|
|
2006-07-18 19:36:33 +04:00
|
|
|
// this actually executes a query and gives you results, it is used by
|
|
|
|
// nsNavHistoryQueryResultNode
|
2007-06-20 09:19:06 +04:00
|
|
|
nsresult GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
|
|
|
|
const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2006-07-18 19:36:33 +04:00
|
|
|
nsNavHistoryQueryOptions *aOptions,
|
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aResults);
|
|
|
|
|
2006-07-18 19:29:40 +04:00
|
|
|
// Take a row of kGetInfoIndex_* columns and construct a ResultNode.
|
|
|
|
// The row must contain the full set of columns.
|
2010-04-09 22:30:29 +04:00
|
|
|
nsresult RowToResult(mozIStorageValueArray* aRow,
|
2006-07-18 19:31:59 +04:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2006-07-18 19:21:48 +04:00
|
|
|
nsNavHistoryResultNode** aResult);
|
2007-09-02 01:23:36 +04:00
|
|
|
nsresult QueryRowToResult(PRInt64 aItemId, const nsACString& aURI,
|
|
|
|
const nsACString& aTitle,
|
2006-07-18 19:37:19 +04:00
|
|
|
PRUint32 aAccessCount, PRTime aTime,
|
|
|
|
const nsACString& aFavicon,
|
|
|
|
nsNavHistoryResultNode** aNode);
|
2006-07-18 19:21:48 +04:00
|
|
|
|
2006-07-18 19:36:33 +04:00
|
|
|
nsresult VisitIdToResultNode(PRInt64 visitId,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aResult);
|
2008-01-05 08:16:27 +03:00
|
|
|
|
2007-04-26 01:03:29 +04:00
|
|
|
nsresult BookmarkIdToResultNode(PRInt64 aBookmarkId,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aResult);
|
2006-07-18 19:21:48 +04:00
|
|
|
|
2006-07-18 19:30:25 +04:00
|
|
|
// used by other places components to send history notifications (for example,
|
|
|
|
// when the favicon has changed)
|
|
|
|
void SendPageChangedNotification(nsIURI* aURI, PRUint32 aWhat,
|
2009-03-25 23:31:36 +03:00
|
|
|
const nsAString& aValue);
|
2006-07-18 19:30:25 +04:00
|
|
|
|
2009-12-22 15:05:04 +03:00
|
|
|
/**
|
|
|
|
* Returns current number of days stored in history.
|
|
|
|
*/
|
|
|
|
PRInt32 GetDaysOfHistory();
|
|
|
|
|
2006-07-18 19:36:33 +04:00
|
|
|
// used by query result nodes to update: see comment on body of CanLiveUpdateQuery
|
2006-07-18 19:37:19 +04:00
|
|
|
static PRUint32 GetUpdateRequirements(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2006-07-18 19:36:33 +04:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
PRBool* aHasSearchTerms);
|
2006-07-18 19:37:19 +04:00
|
|
|
PRBool EvaluateQueryForNode(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2006-07-18 19:36:33 +04:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2006-07-18 19:38:28 +04:00
|
|
|
nsNavHistoryResultNode* aNode);
|
2006-07-18 19:36:33 +04:00
|
|
|
|
|
|
|
static nsresult AsciiHostNameFromHostString(const nsACString& aHostName,
|
|
|
|
nsACString& aAscii);
|
2008-02-07 07:18:17 +03:00
|
|
|
void DomainNameFromURI(nsIURI* aURI,
|
|
|
|
nsACString& aDomainName);
|
2006-07-18 19:36:33 +04:00
|
|
|
static PRTime NormalizeTime(PRUint32 aRelative, PRTime aOffset);
|
2007-08-14 18:20:42 +04:00
|
|
|
|
2007-06-01 04:44:43 +04:00
|
|
|
// Don't use these directly, inside nsNavHistory use UpdateBatchScoper,
|
|
|
|
// else use nsINavHistoryService::RunInBatchMode
|
|
|
|
nsresult BeginUpdateBatch();
|
|
|
|
nsresult EndUpdateBatch();
|
|
|
|
|
2010-04-16 16:31:21 +04:00
|
|
|
// The level of batches' nesting, 0 when no batches are open.
|
2007-08-14 18:20:42 +04:00
|
|
|
PRInt32 mBatchLevel;
|
2010-04-16 16:31:21 +04:00
|
|
|
// Current active transaction for a batch.
|
|
|
|
mozStorageTransaction* mBatchDBTransaction;
|
2007-08-14 18:20:42 +04:00
|
|
|
|
2006-07-18 19:37:19 +04:00
|
|
|
// better alternative to QueryStringToQueries (in nsNavHistoryQuery.cpp)
|
|
|
|
nsresult QueryStringToQueryArray(const nsACString& aQueryString,
|
|
|
|
nsCOMArray<nsNavHistoryQuery>* aQueries,
|
|
|
|
nsNavHistoryQueryOptions** aOptions);
|
|
|
|
|
2008-03-13 02:36:24 +03:00
|
|
|
// Import-friendly version of AddVisit.
|
2006-07-18 19:42:17 +04:00
|
|
|
// This method adds a page to history along with a single last visit.
|
|
|
|
// aLastVisitDate can be -1 if there is no last visit date to record.
|
2007-11-20 21:23:38 +03:00
|
|
|
//
|
2009-01-13 13:48:25 +03:00
|
|
|
// This is only for use by the import of history.dat on first-run of Places,
|
|
|
|
// which currently occurs if no places.sqlite file previously exists.
|
|
|
|
nsresult AddPageWithVisits(nsIURI *aURI,
|
|
|
|
const nsString &aTitle,
|
|
|
|
PRInt32 aVisitCount,
|
|
|
|
PRInt32 aTransitionType,
|
|
|
|
PRTime aFirstVisitDate,
|
|
|
|
PRTime aLastVisitDate);
|
2006-07-18 19:42:17 +04:00
|
|
|
|
2007-05-02 23:07:57 +04:00
|
|
|
// sets the schema version in the database to match SCHEMA_VERSION
|
|
|
|
nsresult UpdateSchemaVersion();
|
|
|
|
|
2008-10-20 01:14:59 +04:00
|
|
|
// Returns true if we are currently in private browsing mode
|
|
|
|
PRBool InPrivateBrowsingMode()
|
|
|
|
{
|
|
|
|
if (mInPrivateBrowsing == PRIVATEBROWSING_NOTINITED) {
|
|
|
|
mInPrivateBrowsing = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIPrivateBrowsingService> pbs =
|
|
|
|
do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
|
|
|
|
if (pbs) {
|
|
|
|
pbs->GetPrivateBrowsingEnabled(&mInPrivateBrowsing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mInPrivateBrowsing;
|
|
|
|
}
|
|
|
|
|
2008-03-20 00:08:10 +03:00
|
|
|
typedef nsDataHashtable<nsCStringHashKey, nsCString> StringHash;
|
|
|
|
|
2008-11-14 09:45:49 +03:00
|
|
|
/**
|
|
|
|
* Helper method to finalize a statement
|
|
|
|
*/
|
|
|
|
static nsresult
|
|
|
|
FinalizeStatement(mozIStorageStatement *aStatement) {
|
|
|
|
nsresult rv;
|
|
|
|
if (aStatement) {
|
|
|
|
rv = aStatement->Finalize();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-25 23:31:36 +03:00
|
|
|
/**
|
|
|
|
* Indicates if it is OK to notify history observers or not.
|
|
|
|
*
|
2010-11-13 01:24:25 +03:00
|
|
|
* @return true if it is OK to notify, false otherwise.
|
2009-03-25 23:31:36 +03:00
|
|
|
*/
|
|
|
|
bool canNotify() { return mCanNotify; }
|
2010-03-25 14:34:33 +03:00
|
|
|
|
2010-07-14 05:00:33 +04:00
|
|
|
enum RecentEventFlags {
|
|
|
|
RECENT_TYPED = 1 << 0, // User typed in URL recently
|
|
|
|
RECENT_ACTIVATED = 1 << 1, // User tapped URL link recently
|
|
|
|
RECENT_BOOKMARKED = 1 << 2 // User bookmarked URL recently
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns any recent activity done with a URL.
|
|
|
|
* @return Any recent events associated with this URI. Each bit is set
|
|
|
|
* according to RecentEventFlags enum values.
|
|
|
|
*/
|
|
|
|
PRUint32 GetRecentFlags(nsIURI *aURI);
|
|
|
|
|
2010-11-13 01:24:25 +03:00
|
|
|
/**
|
|
|
|
* Registers a TRANSITION_EMBED visit for the session.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* URI of the page.
|
|
|
|
* @param aTime
|
|
|
|
* Visit time. Only the last registered visit time is retained.
|
|
|
|
*/
|
|
|
|
void registerEmbedVisit(nsIURI* aURI, PRInt64 aTime);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the specified url has a embed visit.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* URI of the page.
|
|
|
|
* @return whether the page has a embed visit.
|
|
|
|
*/
|
|
|
|
bool hasEmbedVisit(nsIURI* aURI);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears all registered embed visits.
|
|
|
|
*/
|
|
|
|
void clearEmbedVisits();
|
|
|
|
|
2010-03-25 14:34:33 +03:00
|
|
|
mozIStorageStatement* GetStatementById(
|
|
|
|
enum mozilla::places::HistoryStatementId aStatementId
|
2010-10-21 04:37:59 +04:00
|
|
|
)
|
2010-03-25 14:34:33 +03:00
|
|
|
{
|
|
|
|
using namespace mozilla::places;
|
2010-10-11 16:53:31 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Can only get statement on main thread");
|
|
|
|
|
2010-03-25 14:34:33 +03:00
|
|
|
switch(aStatementId) {
|
2010-04-27 15:25:03 +04:00
|
|
|
case DB_GET_PAGE_INFO_BY_URL:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBGetURLPageInfo);
|
2010-04-27 15:24:54 +04:00
|
|
|
case DB_GET_TAGS:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBGetTags);
|
2010-04-27 15:24:56 +04:00
|
|
|
case DB_IS_PAGE_VISITED:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBIsPageVisited);
|
2010-07-14 05:00:33 +04:00
|
|
|
case DB_INSERT_VISIT:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBInsertVisit);
|
2010-07-14 05:00:33 +04:00
|
|
|
case DB_RECENT_VISIT_OF_URL:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBRecentVisitOfURL);
|
2010-07-14 05:00:33 +04:00
|
|
|
case DB_GET_PAGE_VISIT_STATS:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBGetPageVisitStats);
|
2010-07-14 05:00:33 +04:00
|
|
|
case DB_UPDATE_PAGE_VISIT_STATS:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBUpdatePageVisitStats);
|
2010-07-14 05:00:33 +04:00
|
|
|
case DB_ADD_NEW_PAGE:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBAddNewPage);
|
2010-07-14 05:00:41 +04:00
|
|
|
case DB_GET_URL_PAGE_INFO:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBGetURLPageInfo);
|
2010-07-14 05:00:41 +04:00
|
|
|
case DB_SET_PLACE_TITLE:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBSetPlaceTitle);
|
2010-10-11 16:53:31 +04:00
|
|
|
case DB_PAGE_INFO_FOR_FRECENCY:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBPageInfoForFrecency);
|
2010-10-11 16:53:31 +04:00
|
|
|
case DB_VISITS_FOR_FRECENCY:
|
2010-10-21 04:37:59 +04:00
|
|
|
return GetStatement(mDBVisitsForFrecency);
|
2010-03-25 14:34:33 +03:00
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-10-11 16:53:31 +04:00
|
|
|
mozIStorageStatement* GetStatementByStoragePool(
|
|
|
|
enum mozilla::places::HistoryStatementId aStatementId
|
|
|
|
) const
|
|
|
|
{
|
|
|
|
using namespace mozilla::places;
|
|
|
|
|
|
|
|
switch(aStatementId) {
|
|
|
|
case DB_PAGE_INFO_FOR_FRECENCY:
|
|
|
|
return NS_IsMainThread() ? mDBPageInfoForFrecency
|
|
|
|
: mDBAsyncThreadPageInfoForFrecency;
|
|
|
|
case DB_VISITS_FOR_FRECENCY:
|
|
|
|
return NS_IsMainThread() ? mDBVisitsForFrecency
|
|
|
|
: mDBAsyncThreadVisitsForFrecency;
|
2010-11-16 15:44:05 +03:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Trying to handle an unknown statement");
|
2010-10-11 16:53:31 +04:00
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 GetFrecencyAgedWeight(PRInt32 aAgeInDays) const
|
|
|
|
{
|
|
|
|
if (aAgeInDays <= mFirstBucketCutoffInDays) {
|
|
|
|
return mFirstBucketWeight;
|
|
|
|
}
|
|
|
|
if (aAgeInDays <= mSecondBucketCutoffInDays) {
|
|
|
|
return mSecondBucketWeight;
|
|
|
|
}
|
|
|
|
if (aAgeInDays <= mThirdBucketCutoffInDays) {
|
|
|
|
return mThirdBucketWeight;
|
|
|
|
}
|
|
|
|
if (aAgeInDays <= mFourthBucketCutoffInDays) {
|
|
|
|
return mFourthBucketWeight;
|
|
|
|
}
|
|
|
|
return mDefaultWeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 GetFrecencyBucketWeight(PRInt32 aBucketIndex) const
|
|
|
|
{
|
|
|
|
switch(aBucketIndex) {
|
|
|
|
case 1:
|
|
|
|
return mFirstBucketWeight;
|
|
|
|
case 2:
|
|
|
|
return mSecondBucketWeight;
|
|
|
|
case 3:
|
|
|
|
return mThirdBucketWeight;
|
|
|
|
case 4:
|
|
|
|
return mFourthBucketWeight;
|
|
|
|
default:
|
|
|
|
return mDefaultWeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 GetFrecencyTransitionBonus(PRInt32 aTransitionType,
|
|
|
|
bool aVisited) const
|
|
|
|
{
|
|
|
|
switch (aTransitionType) {
|
|
|
|
case nsINavHistoryService::TRANSITION_EMBED:
|
|
|
|
return mEmbedVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_FRAMED_LINK:
|
|
|
|
return mFramedLinkVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_LINK:
|
|
|
|
return mLinkVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_TYPED:
|
|
|
|
return aVisited ? mTypedVisitBonus : mUnvisitedTypedBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_BOOKMARK:
|
|
|
|
return aVisited ? mBookmarkVisitBonus : mUnvisitedBookmarkBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_DOWNLOAD:
|
|
|
|
return mDownloadVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT:
|
|
|
|
return mPermRedirectVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY:
|
|
|
|
return mTempRedirectVisitBonus;
|
|
|
|
default:
|
|
|
|
// 0 == undefined (see bug #375777 for details)
|
|
|
|
NS_WARN_IF_FALSE(!aTransitionType, "new transition but no bonus for frecency");
|
|
|
|
return mDefaultVisitBonus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-14 05:00:33 +04:00
|
|
|
PRInt64 GetNewSessionID();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires onVisit event to nsINavHistoryService observers
|
|
|
|
*/
|
|
|
|
void NotifyOnVisit(nsIURI* aURI,
|
|
|
|
PRInt64 aVisitID,
|
|
|
|
PRTime aTime,
|
|
|
|
PRInt64 aSessionID,
|
|
|
|
PRInt64 referringVisitID,
|
|
|
|
PRInt32 aTransitionType);
|
|
|
|
|
2010-07-14 05:00:41 +04:00
|
|
|
/**
|
|
|
|
* Fires onTitleChanged event to nsINavHistoryService observers
|
|
|
|
*/
|
|
|
|
void NotifyTitleChange(nsIURI* aURI, const nsString& title);
|
|
|
|
|
2010-11-13 00:14:47 +03:00
|
|
|
bool isBatching() {
|
|
|
|
return mBatchLevel > 0;
|
|
|
|
}
|
|
|
|
|
2010-03-25 14:34:33 +03:00
|
|
|
private:
|
2006-07-18 19:19:31 +04:00
|
|
|
~nsNavHistory();
|
|
|
|
|
2006-07-18 19:20:39 +04:00
|
|
|
// used by GetHistoryService
|
2009-12-01 16:00:45 +03:00
|
|
|
static nsNavHistory *gHistoryService;
|
2006-07-18 19:20:39 +04:00
|
|
|
|
2006-07-18 19:19:31 +04:00
|
|
|
protected:
|
|
|
|
|
2010-01-15 19:40:19 +03:00
|
|
|
nsCOMPtr<nsIPrefBranch2> mPrefBranch; // MAY BE NULL when we are shutting down
|
|
|
|
|
2006-07-18 19:19:31 +04:00
|
|
|
nsDataHashtable<nsStringHashKey, int> gExpandedItems;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Database stuff
|
|
|
|
//
|
|
|
|
nsCOMPtr<mozIStorageService> mDBService;
|
|
|
|
nsCOMPtr<mozIStorageConnection> mDBConn;
|
2007-06-28 00:57:56 +04:00
|
|
|
nsCOMPtr<nsIFile> mDBFile;
|
2010-09-13 20:29:42 +04:00
|
|
|
PRInt32 mDBPageSize;
|
2006-07-18 19:19:31 +04:00
|
|
|
|
2010-10-21 04:37:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Always use this getter and never use directly the statement nsCOMPtr.
|
|
|
|
*/
|
|
|
|
mozIStorageStatement* GetStatement(const nsCOMPtr<mozIStorageStatement>& aStmt);
|
|
|
|
|
|
|
|
// These are mutable because GetStatementById needs to be const, but these are
|
|
|
|
// lazy inited.
|
2006-07-18 19:19:31 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetURLPageInfo; // kGetInfoIndex_* results
|
2006-07-18 19:38:51 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetIdPageInfo; // kGetInfoIndex_* results
|
2006-07-18 19:33:08 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBRecentVisitOfURL; // converts URL into most recent visit ID/session ID
|
2008-08-17 02:28:28 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBRecentVisitOfPlace; // converts placeID into most recent visit ID/session ID
|
2006-07-18 19:31:35 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBInsertVisit; // used by AddVisit
|
2006-07-18 19:39:13 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetPageVisitStats; // used by AddVisit
|
2008-03-29 09:48:28 +03:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBIsPageVisited; // used by IsURIStringVisited
|
2006-07-18 19:39:13 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBUpdatePageVisitStats; // used by AddVisit
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBAddNewPage; // used by InternalAddNewPage
|
2009-10-05 14:12:38 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetTags; // used by GetTags
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetItemsWithAnno; // used by AutoComplete::StartSearch and FilterResultSet
|
2008-10-28 01:52:21 +03:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBSetPlaceTitle; // used by SetPageTitleInternal
|
2006-07-18 19:36:33 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBVisitToURLResult; // kGetInfoIndex_* results
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBVisitToVisitResult; // kGetInfoIndex_* results
|
2007-04-26 01:03:29 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBBookmarkToUrlResult; // kGetInfoIndex_* results
|
2010-10-21 04:37:59 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mDBUpdateFrecency;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBUpdateHiddenOnFrecency;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBGetPlaceVisitStats;
|
|
|
|
// Cached statements used in frecency calculation. Since it could happen on
|
|
|
|
// both main thread or storage async thread, we keep two versions of them
|
|
|
|
// for thread-safety.
|
|
|
|
mutable nsCOMPtr<mozIStorageStatement> mDBVisitsForFrecency;
|
|
|
|
mutable nsCOMPtr<mozIStorageStatement> mDBPageInfoForFrecency;
|
|
|
|
mutable nsCOMPtr<mozIStorageStatement> mDBAsyncThreadVisitsForFrecency;
|
|
|
|
mutable nsCOMPtr<mozIStorageStatement> mDBAsyncThreadPageInfoForFrecency;
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
// AutoComplete stuff
|
|
|
|
nsCOMPtr<mozIStorageStatement> mDBFeedbackIncrease;
|
|
|
|
#endif
|
2008-01-25 20:11:14 +03:00
|
|
|
|
2008-11-14 09:45:49 +03:00
|
|
|
/**
|
|
|
|
* Finalize all internal statements.
|
|
|
|
*/
|
2009-12-22 15:05:14 +03:00
|
|
|
nsresult FinalizeStatements();
|
2008-11-14 09:45:49 +03:00
|
|
|
|
2009-09-14 15:06:45 +04:00
|
|
|
/**
|
2010-10-21 14:19:05 +04:00
|
|
|
* Decays frecency and inputhistory values. Runs on idle-daily.
|
2009-09-14 15:06:45 +04:00
|
|
|
*/
|
2009-12-22 15:05:14 +03:00
|
|
|
nsresult DecayFrecency();
|
2009-09-14 15:06:45 +04:00
|
|
|
|
2009-10-14 13:53:13 +04:00
|
|
|
/**
|
|
|
|
* Finalizes all Places internal statements, allowing to safely close the
|
|
|
|
* database connection.
|
|
|
|
*/
|
2009-12-22 15:05:14 +03:00
|
|
|
nsresult FinalizeInternalStatements();
|
2009-10-14 13:53:13 +04:00
|
|
|
|
2008-04-08 22:41:04 +04:00
|
|
|
// nsICharsetResolver
|
|
|
|
NS_DECL_NSICHARSETRESOLVER
|
|
|
|
|
2008-01-25 20:11:14 +03:00
|
|
|
nsresult CalculateFrecency(PRInt64 aPageID, PRInt32 aTyped, PRInt32 aVisitCount, nsCAutoString &aURL, PRInt32 *aFrecency);
|
|
|
|
nsresult CalculateFrecencyInternal(PRInt64 aPageID, PRInt32 aTyped, PRInt32 aVisitCount, PRBool aIsBookmarked, PRInt32 *aFrecency);
|
|
|
|
|
2008-02-06 21:10:39 +03:00
|
|
|
/**
|
|
|
|
* Initializes the database file. If the database does not exist, was
|
|
|
|
* corrupted, or aForceInit is true, we recreate the database. We also backup
|
|
|
|
* the database if it was corrupted or aForceInit is true.
|
|
|
|
*
|
|
|
|
* @param aForceInit
|
|
|
|
* Indicates if we should close an open database connection or not.
|
2008-02-09 22:15:45 +03:00
|
|
|
* Note: A valid database connection must be opened if this is true.
|
2008-02-06 21:10:39 +03:00
|
|
|
*/
|
2007-06-28 00:57:56 +04:00
|
|
|
nsresult InitDBFile(PRBool aForceInit);
|
2008-02-06 21:10:39 +03:00
|
|
|
|
2010-09-13 20:29:42 +04:00
|
|
|
/**
|
|
|
|
* Set journal mode on the database.
|
|
|
|
*/
|
|
|
|
nsresult SetJournalMode(enum mozilla::places::JournalMode aJournalMode);
|
|
|
|
enum mozilla::places::JournalMode mCurrentJournalMode;
|
|
|
|
|
2008-02-06 21:10:39 +03:00
|
|
|
/**
|
|
|
|
* Initializes the database. This performs any necessary migrations for the
|
|
|
|
* database. All migration is done inside a transaction that is rolled back
|
|
|
|
* if any error occurs. Upon initialization, history is imported, and some
|
|
|
|
* preferences that are used are set.
|
|
|
|
*/
|
2008-12-31 00:42:23 +03:00
|
|
|
nsresult InitDB();
|
2009-05-19 03:06:46 +04:00
|
|
|
|
|
|
|
/**
|
2010-11-20 03:39:55 +03:00
|
|
|
* Initializes additional database items like functions, triggers, and
|
|
|
|
* statements.
|
2009-05-19 03:06:46 +04:00
|
|
|
*/
|
|
|
|
nsresult InitAdditionalDBItems();
|
2008-02-27 07:48:51 +03:00
|
|
|
nsresult InitFunctions();
|
2010-11-24 18:36:05 +03:00
|
|
|
nsresult InitTriggers();
|
2010-12-02 20:40:18 +03:00
|
|
|
nsresult CheckAndUpdateGUIDs();
|
2008-08-04 20:59:56 +04:00
|
|
|
nsresult MigrateV7Up(mozIStorageConnection *aDBConn);
|
2008-10-28 01:52:20 +03:00
|
|
|
nsresult MigrateV8Up(mozIStorageConnection *aDBConn);
|
2009-05-15 03:28:03 +04:00
|
|
|
nsresult MigrateV9Up(mozIStorageConnection *aDBConn);
|
2009-06-24 12:59:14 +04:00
|
|
|
nsresult MigrateV10Up(mozIStorageConnection *aDBConn);
|
2010-08-09 19:59:59 +04:00
|
|
|
nsresult MigrateV11Up(mozIStorageConnection *aDBConn);
|
2006-07-18 19:19:31 +04:00
|
|
|
|
2008-02-09 01:13:29 +03:00
|
|
|
nsresult RemovePagesInternal(const nsCString& aPlaceIdsQueryString);
|
2009-05-17 06:32:13 +04:00
|
|
|
nsresult PreparePlacesForVisitsDelete(const nsCString& aPlaceIdsQueryString);
|
|
|
|
nsresult CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString);
|
2008-02-09 01:13:29 +03:00
|
|
|
|
2006-07-18 19:43:26 +04:00
|
|
|
nsresult AddURIInternal(nsIURI* aURI, PRTime aTime, PRBool aRedirect,
|
|
|
|
PRBool aToplevel, nsIURI* aReferrer);
|
|
|
|
|
|
|
|
nsresult AddVisitChain(nsIURI* aURI, PRTime aTime,
|
|
|
|
PRBool aToplevel, PRBool aRedirect,
|
2006-07-18 19:39:13 +04:00
|
|
|
nsIURI* aReferrer, PRInt64* aVisitID,
|
2010-03-10 15:40:52 +03:00
|
|
|
PRInt64* aSessionID);
|
2006-07-18 19:42:17 +04:00
|
|
|
nsresult InternalAddNewPage(nsIURI* aURI, const nsAString& aTitle,
|
|
|
|
PRBool aHidden, PRBool aTyped,
|
2008-01-25 20:11:14 +03:00
|
|
|
PRInt32 aVisitCount, PRBool aCalculateFrecency,
|
|
|
|
PRInt64* aPageID);
|
2006-07-18 19:39:13 +04:00
|
|
|
nsresult InternalAddVisit(PRInt64 aPageID, PRInt64 aReferringVisit,
|
|
|
|
PRInt64 aSessionID, PRTime aTime,
|
|
|
|
PRInt32 aTransitionType, PRInt64* aVisitID);
|
2010-03-10 15:40:32 +03:00
|
|
|
PRBool FindLastVisit(nsIURI* aURI,
|
|
|
|
PRInt64* aVisitID,
|
|
|
|
PRTime* aTime,
|
2006-07-18 19:39:13 +04:00
|
|
|
PRInt64* aSessionID);
|
2006-07-18 19:19:31 +04:00
|
|
|
PRBool IsURIStringVisited(const nsACString& url);
|
2008-02-06 21:10:39 +03:00
|
|
|
|
|
|
|
/**
|
2010-01-15 19:40:19 +03:00
|
|
|
* Loads all of the preferences that we use into member variables.
|
2008-02-06 21:10:39 +03:00
|
|
|
*
|
2010-01-15 19:40:19 +03:00
|
|
|
* @note If mPrefBranch is NULL, this does nothing.
|
2008-02-06 21:10:39 +03:00
|
|
|
*/
|
2010-01-15 19:40:19 +03:00
|
|
|
void LoadPrefs();
|
2006-07-18 19:19:31 +04:00
|
|
|
|
2009-12-22 15:05:06 +03:00
|
|
|
/**
|
|
|
|
* Calculates and returns value for mCachedNow.
|
|
|
|
* This is an hack to avoid calling PR_Now() too often, as is the case when
|
|
|
|
* we're asked the ageindays of many history entries in a row. A timer is
|
|
|
|
* set which will clear our valid flag after a short timeout.
|
|
|
|
*/
|
|
|
|
PRTime GetNow();
|
|
|
|
PRTime mCachedNow;
|
2006-07-18 19:19:31 +04:00
|
|
|
nsCOMPtr<nsITimer> mExpireNowTimer;
|
2009-12-22 15:05:06 +03:00
|
|
|
/**
|
|
|
|
* Called when the cached now value is expired and needs renewal.
|
|
|
|
*/
|
2006-07-18 19:19:31 +04:00
|
|
|
static void expireNowTimerCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
2007-07-27 01:39:06 +04:00
|
|
|
nsresult ConstructQueryString(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2008-03-20 00:08:10 +03:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2008-02-27 07:48:51 +03:00
|
|
|
nsCString& queryString,
|
2008-03-20 00:08:10 +03:00
|
|
|
PRBool& aParamsPresent,
|
|
|
|
StringHash& aAddParams);
|
2007-07-27 01:39:06 +04:00
|
|
|
|
2006-07-18 19:37:19 +04:00
|
|
|
nsresult QueryToSelectClause(nsNavHistoryQuery* aQuery,
|
2007-04-26 01:03:29 +04:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2008-03-20 00:08:10 +03:00
|
|
|
PRInt32 aQueryIndex,
|
|
|
|
nsCString* aClause);
|
2006-07-18 19:19:31 +04:00
|
|
|
nsresult BindQueryClauseParameters(mozIStorageStatement* statement,
|
2008-03-20 00:08:10 +03:00
|
|
|
PRInt32 aQueryIndex,
|
2006-07-18 19:37:19 +04:00
|
|
|
nsNavHistoryQuery* aQuery,
|
2008-03-20 00:08:10 +03:00
|
|
|
nsNavHistoryQueryOptions* aOptions);
|
2006-07-18 19:19:31 +04:00
|
|
|
|
2006-07-18 19:31:59 +04:00
|
|
|
nsresult ResultsAsList(mozIStorageStatement* statement,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2006-07-18 19:19:31 +04:00
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aResults);
|
|
|
|
|
2006-07-18 19:36:33 +04:00
|
|
|
void TitleForDomain(const nsCString& domain, nsACString& aTitle);
|
2006-11-22 02:02:16 +03:00
|
|
|
|
2007-07-26 20:23:11 +04:00
|
|
|
nsresult SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle);
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-09-02 01:23:36 +04:00
|
|
|
nsresult FilterResultSet(nsNavHistoryQueryResultNode *aParentNode,
|
|
|
|
const nsCOMArray<nsNavHistoryResultNode>& aSet,
|
2006-07-18 19:19:31 +04:00
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aFiltered,
|
2007-10-01 21:36:18 +04:00
|
|
|
const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
|
|
|
nsNavHistoryQueryOptions* aOptions);
|
2006-07-18 19:19:31 +04:00
|
|
|
|
|
|
|
// observers
|
2006-07-18 19:29:17 +04:00
|
|
|
nsMaybeWeakPtrArray<nsINavHistoryObserver> mObservers;
|
2008-02-07 07:18:17 +03:00
|
|
|
|
2008-02-07 07:18:17 +03:00
|
|
|
// effective tld service
|
|
|
|
nsCOMPtr<nsIEffectiveTLDService> mTLDService;
|
|
|
|
nsCOMPtr<nsIIDNService> mIDNService;
|
|
|
|
|
2006-07-18 19:36:33 +04:00
|
|
|
// localization
|
2006-07-18 19:19:31 +04:00
|
|
|
nsCOMPtr<nsIStringBundle> mBundle;
|
2009-03-23 15:42:03 +03:00
|
|
|
nsCOMPtr<nsIStringBundle> mDateFormatBundle;
|
2006-07-18 19:36:33 +04:00
|
|
|
nsCOMPtr<nsICollation> mCollation;
|
2006-07-18 19:19:31 +04:00
|
|
|
|
|
|
|
// annotation service : MAY BE NULL!
|
|
|
|
//nsCOMPtr<mozIAnnotationService> mAnnotationService;
|
|
|
|
|
2006-07-18 19:33:08 +04:00
|
|
|
// recent events
|
|
|
|
typedef nsDataHashtable<nsCStringHashKey, PRInt64> RecentEventHash;
|
|
|
|
RecentEventHash mRecentTyped;
|
2010-03-10 15:40:34 +03:00
|
|
|
RecentEventHash mRecentLink;
|
2006-07-18 19:33:08 +04:00
|
|
|
RecentEventHash mRecentBookmark;
|
|
|
|
|
2010-11-13 01:24:25 +03:00
|
|
|
// Embed visits tracking.
|
|
|
|
class VisitHashKey : public nsURIHashKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VisitHashKey(const nsIURI* aURI)
|
|
|
|
: nsURIHashKey(aURI)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
VisitHashKey(const VisitHashKey& aOther)
|
|
|
|
: nsURIHashKey(aOther)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Do not call me!");
|
|
|
|
}
|
|
|
|
PRTime visitTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTHashtable<VisitHashKey> mEmbedVisits;
|
|
|
|
|
2006-07-18 19:33:08 +04:00
|
|
|
PRBool CheckIsRecentEvent(RecentEventHash* hashTable,
|
|
|
|
const nsACString& url);
|
|
|
|
void ExpireNonrecentEvents(RecentEventHash* hashTable);
|
|
|
|
|
2006-07-18 19:39:13 +04:00
|
|
|
// redirect tracking. See GetRedirectFor for a description of how this works.
|
|
|
|
struct RedirectInfo {
|
|
|
|
nsCString mSourceURI;
|
|
|
|
PRTime mTimeCreated;
|
|
|
|
PRUint32 mType; // one of TRANSITION_REDIRECT_[TEMPORARY,PERMANENT]
|
|
|
|
};
|
|
|
|
typedef nsDataHashtable<nsCStringHashKey, RedirectInfo> RedirectHash;
|
|
|
|
RedirectHash mRecentRedirects;
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator ExpireNonrecentRedirects(
|
2006-07-18 19:39:13 +04:00
|
|
|
nsCStringHashKey::KeyType aKey, RedirectInfo& aData, void* aUserArg);
|
|
|
|
PRBool GetRedirectFor(const nsACString& aDestination, nsACString& aSource,
|
|
|
|
PRTime* aTime, PRUint32* aRedirectType);
|
|
|
|
|
2009-12-22 15:05:08 +03:00
|
|
|
// Sessions tracking.
|
2006-07-18 19:33:08 +04:00
|
|
|
PRInt64 mLastSessionID;
|
|
|
|
|
2009-07-13 23:19:03 +04:00
|
|
|
#ifdef MOZ_XUL
|
2008-02-26 00:35:57 +03:00
|
|
|
nsresult AutoCompleteFeedback(PRInt32 aIndex,
|
|
|
|
nsIAutoCompleteController *aController);
|
2008-01-19 09:58:21 +03:00
|
|
|
#endif
|
2008-01-25 20:11:14 +03:00
|
|
|
|
2010-01-15 19:40:14 +03:00
|
|
|
// Whether history is enabled or not.
|
|
|
|
// Will mimic value of the places.history.enabled preference.
|
|
|
|
PRBool mHistoryEnabled;
|
|
|
|
|
2009-12-22 15:05:08 +03:00
|
|
|
// Frecency preferences.
|
2008-01-25 20:11:14 +03:00
|
|
|
PRInt32 mNumVisitsForFrecency;
|
|
|
|
PRInt32 mFirstBucketCutoffInDays;
|
|
|
|
PRInt32 mSecondBucketCutoffInDays;
|
|
|
|
PRInt32 mThirdBucketCutoffInDays;
|
|
|
|
PRInt32 mFourthBucketCutoffInDays;
|
|
|
|
PRInt32 mFirstBucketWeight;
|
|
|
|
PRInt32 mSecondBucketWeight;
|
|
|
|
PRInt32 mThirdBucketWeight;
|
|
|
|
PRInt32 mFourthBucketWeight;
|
|
|
|
PRInt32 mDefaultWeight;
|
|
|
|
PRInt32 mEmbedVisitBonus;
|
2010-03-10 15:40:34 +03:00
|
|
|
PRInt32 mFramedLinkVisitBonus;
|
2008-01-25 20:11:14 +03:00
|
|
|
PRInt32 mLinkVisitBonus;
|
|
|
|
PRInt32 mTypedVisitBonus;
|
|
|
|
PRInt32 mBookmarkVisitBonus;
|
|
|
|
PRInt32 mDownloadVisitBonus;
|
|
|
|
PRInt32 mPermRedirectVisitBonus;
|
|
|
|
PRInt32 mTempRedirectVisitBonus;
|
|
|
|
PRInt32 mDefaultVisitBonus;
|
|
|
|
PRInt32 mUnvisitedBookmarkBonus;
|
|
|
|
PRInt32 mUnvisitedTypedBonus;
|
|
|
|
|
2006-07-18 19:22:34 +04:00
|
|
|
// in nsNavHistoryQuery.cpp
|
2006-07-18 19:35:25 +04:00
|
|
|
nsresult TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
|
2006-07-18 19:37:19 +04:00
|
|
|
nsCOMArray<nsNavHistoryQuery>* aQueries,
|
2006-07-18 19:35:25 +04:00
|
|
|
nsNavHistoryQueryOptions* aOptions);
|
2006-07-18 19:40:00 +04:00
|
|
|
|
2007-11-20 05:01:53 +03:00
|
|
|
PRInt64 mTagsFolder;
|
2008-10-20 01:14:59 +04:00
|
|
|
|
|
|
|
PRBool mInPrivateBrowsing;
|
2008-11-12 23:45:53 +03:00
|
|
|
|
2008-12-13 12:57:30 +03:00
|
|
|
PRUint16 mDatabaseStatus;
|
2009-03-25 23:31:36 +03:00
|
|
|
|
2010-02-10 21:08:58 +03:00
|
|
|
PRInt8 mHasHistoryEntries;
|
|
|
|
|
2009-03-25 23:31:36 +03:00
|
|
|
// Used to enable and disable the observer notifications
|
|
|
|
bool mCanNotify;
|
|
|
|
nsCategoryCache<nsINavHistoryObserver> mCacheObservers;
|
2006-07-18 19:19:31 +04:00
|
|
|
};
|
2006-07-18 19:20:39 +04:00
|
|
|
|
2010-04-27 15:25:07 +04:00
|
|
|
|
2006-07-18 19:40:45 +04:00
|
|
|
#define PLACES_URI_PREFIX "place:"
|
2006-07-18 19:24:29 +04:00
|
|
|
|
|
|
|
/* Returns true if the given URI represents a history query. */
|
|
|
|
inline PRBool IsQueryURI(const nsCString &uri)
|
|
|
|
{
|
2006-07-18 19:40:45 +04:00
|
|
|
return StringBeginsWith(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX));
|
2006-07-18 19:24:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Extracts the query string from a query URI. */
|
|
|
|
inline const nsDependentCSubstring QueryURIToQuery(const nsCString &uri)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(IsQueryURI(uri), "should only be called for query URIs");
|
2006-07-18 19:40:45 +04:00
|
|
|
return Substring(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX).Length());
|
2006-07-18 19:24:29 +04:00
|
|
|
}
|
|
|
|
|
2006-07-18 19:21:48 +04:00
|
|
|
#endif // nsNavHistory_h_
|