2009-08-20 18:56:10 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
|
|
|
|
* ***** 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
|
2011-01-13 21:37:04 +00:00
|
|
|
* the Mozilla Foundation.
|
2009-08-20 18:56:10 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
#ifndef mozilla_places_History_h_
|
|
|
|
#define mozilla_places_History_h_
|
|
|
|
|
|
|
|
#include "mozilla/IHistory.h"
|
2012-02-01 10:59:27 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2011-01-13 21:37:04 +00:00
|
|
|
#include "mozIAsyncHistory.h"
|
2012-01-20 12:48:20 +00:00
|
|
|
#include "nsIDownloadHistory.h"
|
2011-10-27 09:11:34 +00:00
|
|
|
#include "Database.h"
|
|
|
|
|
2009-08-20 18:56:10 +00:00
|
|
|
#include "mozilla/dom/Link.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsURIHashKey.h"
|
2011-07-13 21:28:37 +00:00
|
|
|
#include "nsTObserverArray.h"
|
2010-07-14 01:00:33 +00:00
|
|
|
#include "nsDeque.h"
|
|
|
|
#include "nsIObserver.h"
|
2010-10-06 15:21:31 +00:00
|
|
|
#include "mozIStorageConnection.h"
|
2009-08-20 18:56:10 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace places {
|
|
|
|
|
2011-01-11 18:48:14 +00:00
|
|
|
struct VisitData;
|
|
|
|
|
2009-08-20 18:56:10 +00:00
|
|
|
#define NS_HISTORYSERVICE_CID \
|
2010-07-14 01:00:41 +00:00
|
|
|
{0x0937a705, 0x91a6, 0x417a, {0x82, 0x92, 0xb2, 0x2e, 0xb1, 0x0d, 0xa8, 0x6c}}
|
2009-08-20 18:56:10 +00:00
|
|
|
|
|
|
|
class History : public IHistory
|
2012-01-20 12:48:20 +00:00
|
|
|
, public nsIDownloadHistory
|
2011-01-13 21:37:04 +00:00
|
|
|
, public mozIAsyncHistory
|
2010-07-14 01:00:33 +00:00
|
|
|
, public nsIObserver
|
2009-08-20 18:56:10 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_IHISTORY
|
2012-01-20 12:48:20 +00:00
|
|
|
NS_DECL_NSIDOWNLOADHISTORY
|
2011-01-13 21:37:04 +00:00
|
|
|
NS_DECL_MOZIASYNCHISTORY
|
2010-07-14 01:00:33 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
2009-08-20 18:56:10 +00:00
|
|
|
|
|
|
|
History();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies about the visited status of a given URI.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* The URI to notify about.
|
|
|
|
*/
|
2010-10-06 15:21:31 +00:00
|
|
|
void NotifyVisited(nsIURI* aURI);
|
2009-08-20 18:56:10 +00:00
|
|
|
|
2010-10-06 15:21:31 +00:00
|
|
|
/**
|
|
|
|
* Obtains the statement to use to check if a URI is visited or not.
|
|
|
|
*/
|
|
|
|
mozIStorageAsyncStatement* GetIsVisitedStatement();
|
|
|
|
|
2011-01-11 18:48:14 +00:00
|
|
|
/**
|
|
|
|
* Adds an entry in moz_places with the data in aVisitData.
|
|
|
|
*
|
|
|
|
* @param aVisitData
|
|
|
|
* The visit data to use to populate a new row in moz_places.
|
|
|
|
*/
|
|
|
|
nsresult InsertPlace(const VisitData& aVisitData);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates an entry in moz_places with the data in aVisitData.
|
|
|
|
*
|
|
|
|
* @param aVisitData
|
|
|
|
* The visit data to use to update the existing row in moz_places.
|
|
|
|
*/
|
|
|
|
nsresult UpdatePlace(const VisitData& aVisitData);
|
|
|
|
|
2011-01-11 18:48:53 +00:00
|
|
|
/**
|
|
|
|
* Loads information about the page into _place from moz_places.
|
|
|
|
*
|
|
|
|
* @param _place
|
|
|
|
* The VisitData for the place we need to know information about.
|
|
|
|
* @return true if the page was recorded in moz_places, false otherwise.
|
|
|
|
*/
|
|
|
|
bool FetchPageInfo(VisitData& _place);
|
|
|
|
|
2011-09-15 00:37:45 +00:00
|
|
|
/**
|
2011-11-28 03:03:14 +00:00
|
|
|
* Get the number of bytes of memory this History object is using,
|
|
|
|
* including sizeof(*this))
|
2011-09-15 00:37:45 +00:00
|
|
|
*/
|
2011-12-15 22:59:53 +00:00
|
|
|
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
|
2011-09-15 00:37:45 +00:00
|
|
|
|
2009-08-20 18:56:10 +00:00
|
|
|
/**
|
|
|
|
* Obtains a pointer to this service.
|
|
|
|
*/
|
2010-10-06 15:21:31 +00:00
|
|
|
static History* GetService();
|
2009-08-20 18:56:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains a pointer that has had AddRef called on it. Used by the service
|
|
|
|
* manager only.
|
|
|
|
*/
|
2010-10-06 15:21:31 +00:00
|
|
|
static History* GetSingleton();
|
2009-08-20 18:56:10 +00:00
|
|
|
|
2011-10-27 09:11:34 +00:00
|
|
|
template<int N>
|
|
|
|
already_AddRefed<mozIStorageStatement>
|
|
|
|
GetStatement(const char (&aQuery)[N])
|
|
|
|
{
|
|
|
|
mozIStorageConnection* dbConn = GetDBConn();
|
|
|
|
NS_ENSURE_TRUE(dbConn, nsnull);
|
|
|
|
return mDB->GetStatement(aQuery);
|
|
|
|
}
|
2010-11-08 19:43:46 +00:00
|
|
|
|
2012-02-01 10:59:27 +00:00
|
|
|
bool IsShuttingDown() const {
|
|
|
|
return mShuttingDown;
|
|
|
|
}
|
|
|
|
Mutex& GetShutdownMutex() {
|
|
|
|
return mShutdownMutex;
|
|
|
|
}
|
|
|
|
|
2009-08-20 18:56:10 +00:00
|
|
|
private:
|
2010-10-06 15:21:31 +00:00
|
|
|
virtual ~History();
|
|
|
|
|
2010-11-08 19:43:46 +00:00
|
|
|
/**
|
|
|
|
* Obtains a read-write database connection.
|
|
|
|
*/
|
|
|
|
mozIStorageConnection* GetDBConn();
|
|
|
|
|
|
|
|
/**
|
2011-10-27 09:11:34 +00:00
|
|
|
* The database handle. This is initialized lazily by the first call to
|
|
|
|
* GetDBConn(), so never use it directly, or, if you really need, always
|
|
|
|
* invoke GetDBConn() before.
|
2010-11-08 19:43:46 +00:00
|
|
|
*/
|
2011-10-27 09:11:34 +00:00
|
|
|
nsRefPtr<mozilla::places::Database> mDB;
|
2010-11-08 19:43:46 +00:00
|
|
|
|
2010-10-06 15:21:31 +00:00
|
|
|
/**
|
|
|
|
* A read-only database connection used for checking if a URI is visited.
|
|
|
|
*
|
|
|
|
* @note this should only be accessed by GetIsVisistedStatement and Shutdown.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<mozIStorageConnection> mReadOnlyDBConn;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An asynchronous statement to query if a URI is visited or not.
|
|
|
|
*
|
2010-10-13 19:02:22 +00:00
|
|
|
* @note this should only be accessed by GetIsVisistedStatement and Shutdown.
|
2010-10-06 15:21:31 +00:00
|
|
|
*/
|
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> mIsVisitedStatement;
|
2009-08-20 18:56:10 +00:00
|
|
|
|
2010-07-14 01:00:33 +00:00
|
|
|
/**
|
|
|
|
* Remove any memory references to tasks and do not take on any more.
|
|
|
|
*/
|
|
|
|
void Shutdown();
|
|
|
|
|
2010-10-06 15:21:31 +00:00
|
|
|
static History* gService;
|
2009-08-20 18:56:10 +00:00
|
|
|
|
2010-07-14 01:00:33 +00:00
|
|
|
// Ensures new tasks aren't started on destruction.
|
|
|
|
bool mShuttingDown;
|
2012-02-01 10:59:27 +00:00
|
|
|
// This mutex guards mShuttingDown. Code running in other threads that might
|
|
|
|
// schedule tasks that use the database should grab it and check the value of
|
|
|
|
// mShuttingDown. If we are already shutting down, the code must gracefully
|
|
|
|
// avoid using the db. If we are not, the lock will prevent shutdown from
|
|
|
|
// starting in an unexpected moment.
|
|
|
|
Mutex mShutdownMutex;
|
2010-07-14 01:00:33 +00:00
|
|
|
|
2011-07-13 21:28:37 +00:00
|
|
|
typedef nsTObserverArray<mozilla::dom::Link* > ObserverArray;
|
2009-08-20 18:56:10 +00:00
|
|
|
|
|
|
|
class KeyClass : public nsURIHashKey
|
|
|
|
{
|
|
|
|
public:
|
2010-10-06 15:21:31 +00:00
|
|
|
KeyClass(const nsIURI* aURI)
|
2009-08-20 18:56:10 +00:00
|
|
|
: nsURIHashKey(aURI)
|
|
|
|
{
|
|
|
|
}
|
2010-10-06 15:21:31 +00:00
|
|
|
KeyClass(const KeyClass& aOther)
|
2009-08-20 18:56:10 +00:00
|
|
|
: nsURIHashKey(aOther)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Do not call me!");
|
|
|
|
}
|
|
|
|
ObserverArray array;
|
|
|
|
};
|
|
|
|
|
2011-09-15 00:37:45 +00:00
|
|
|
/**
|
2011-12-15 22:59:53 +00:00
|
|
|
* Helper function for nsTHashtable::SizeOfExcludingThis call in
|
|
|
|
* SizeOfIncludingThis().
|
2011-09-15 00:37:45 +00:00
|
|
|
*/
|
2011-12-15 22:59:53 +00:00
|
|
|
static size_t SizeOfEntryExcludingThis(KeyClass* aEntry,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
void*);
|
2011-09-15 00:37:45 +00:00
|
|
|
|
2009-08-20 18:56:10 +00:00
|
|
|
nsTHashtable<KeyClass> mObservers;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace places
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_places_History_h_
|