Bug 483980: Allow history/bookmark observer components to register with a startup category, r=sdwilsh

This commit is contained in:
Mark Finkle 2009-03-25 15:31:36 -05:00
Родитель a1680d86fb
Коммит 1f32c00d18
10 изменённых файлов: 410 добавлений и 57 удалений

Просмотреть файл

@ -53,6 +53,7 @@
#include "nsILivemarkService.h"
#include "nsPlacesTriggers.h"
#include "nsPlacesTables.h"
#include "nsPlacesMacros.h"
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_ID = 0;
const PRInt32 nsNavBookmarks::kFindBookmarksIndex_Type = 1;
@ -87,7 +88,7 @@ nsNavBookmarks* nsNavBookmarks::sInstance = nsnull;
nsNavBookmarks::nsNavBookmarks()
: mItemCount(0), mRoot(0), mBookmarksRoot(0), mTagRoot(0), mToolbarFolder(0), mBatchLevel(0),
mBatchHasTransaction(PR_FALSE)
mBatchHasTransaction(PR_FALSE), mCanFireNotifs(PR_FALSE), mCacheObservers("bookmark-observers")
{
NS_ASSERTION(!sInstance, "Multiple nsNavBookmarks instances!");
sInstance = this;
@ -124,6 +125,8 @@ nsNavBookmarks::Init()
rv = transaction.Commit();
NS_ENSURE_SUCCESS(rv, rv);
mCanFireNotifs = PR_TRUE;
// Add observers
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
@ -1121,7 +1124,7 @@ nsNavBookmarks::InsertBookmark(PRInt64 aFolder, nsIURI *aItem, PRInt32 aIndex,
AddBookmarkToHash(childID, 0);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemAdded(rowId, aFolder, index))
// If the bookmark has been added to a tag container, notify all
@ -1139,7 +1142,7 @@ nsNavBookmarks::InsertBookmark(PRInt64 aFolder, nsIURI *aItem, PRInt32 aIndex,
if (bookmarks.Length()) {
for (PRUint32 i = 0; i < bookmarks.Length(); i++) {
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(bookmarks[i], NS_LITERAL_CSTRING("tags"),
PR_FALSE, EmptyCString()))
}
@ -1187,7 +1190,7 @@ nsNavBookmarks::RemoveItem(PRInt64 aItemId)
return NS_OK;
}
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnBeforeItemRemoved(aItemId))
mozStorageTransaction transaction(mDBConn, PR_FALSE);
@ -1226,7 +1229,7 @@ nsNavBookmarks::RemoveItem(PRInt64 aItemId)
NS_ENSURE_SUCCESS(rv, rv);
}
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemRemoved(aItemId, folderId, childIndex))
if (itemType == TYPE_BOOKMARK) {
@ -1247,7 +1250,7 @@ nsNavBookmarks::RemoveItem(PRInt64 aItemId)
if (bookmarks.Length()) {
for (PRUint32 i = 0; i < bookmarks.Length(); i++) {
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(bookmarks[i], NS_LITERAL_CSTRING("tags"),
PR_FALSE, EmptyCString()))
}
@ -1396,7 +1399,7 @@ nsNavBookmarks::CreateContainerWithID(PRInt64 aItemId, PRInt64 aParent,
rv = transaction.Commit();
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemAdded(id, aParent, index))
*aIndex = index;
@ -1461,7 +1464,7 @@ nsNavBookmarks::InsertSeparator(PRInt64 aParent, PRInt32 aIndex,
rv = transaction.Commit();
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemAdded(rowId, aParent, index))
return NS_OK;
@ -1598,7 +1601,7 @@ nsNavBookmarks::RemoveFolder(PRInt64 aFolderId)
{
NS_ENSURE_TRUE(aFolderId != mRoot, NS_ERROR_INVALID_ARG);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnBeforeItemRemoved(aFolderId))
mozStorageTransaction transaction(mDBConn, PR_FALSE);
@ -1672,7 +1675,7 @@ nsNavBookmarks::RemoveFolder(PRInt64 aFolderId)
mToolbarFolder = 0;
}
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemRemoved(aFolderId, parent, index))
return NS_OK;
@ -1790,7 +1793,7 @@ nsNavBookmarks::RemoveFolderChildren(PRInt64 aFolderId)
folderChildrenInfo child = folderChildrenArray[i];
// Notify observers that we are about to remove this child.
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnBeforeItemRemoved(child.itemId))
if (child.itemType == TYPE_FOLDER) {
@ -1863,7 +1866,7 @@ nsNavBookmarks::RemoveFolderChildren(PRInt64 aFolderId)
for (PRInt32 i = folderChildrenArray.Length() - 1; i >= 0 ; i--) {
folderChildrenInfo child = folderChildrenArray[i];
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemRemoved(child.itemId,
child.parentId,
child.index));
@ -1884,7 +1887,7 @@ nsNavBookmarks::RemoveFolderChildren(PRInt64 aFolderId)
if (bookmarks.Length()) {
for (PRUint32 i = 0; i < bookmarks.Length(); i++) {
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(bookmarks[i], NS_LITERAL_CSTRING("tags"),
PR_FALSE, EmptyCString()))
}
@ -2041,7 +2044,7 @@ nsNavBookmarks::MoveItem(PRInt64 aItemId, PRInt64 aNewParent, PRInt32 aIndex)
NS_ENSURE_SUCCESS(rv, rv);
// notify bookmark observers
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemMoved(aItemId, oldParent, oldIndex, aNewParent,
newIndex))
@ -2116,7 +2119,7 @@ nsNavBookmarks::SetItemDateAdded(PRInt64 aItemId, PRTime aDateAdded)
nsresult rv = SetItemDateInternal(mDBSetItemDateAdded, aItemId, aDateAdded);
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(aItemId, NS_LITERAL_CSTRING("dateAdded"),
PR_FALSE, nsPrintfCString(16, "%lld", aDateAdded)));
return NS_OK;
@ -2147,7 +2150,7 @@ nsNavBookmarks::SetItemLastModified(PRInt64 aItemId, PRTime aLastModified)
nsresult rv = SetItemDateInternal(mDBSetItemLastModified, aItemId, aLastModified);
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(aItemId, NS_LITERAL_CSTRING("lastModified"),
PR_FALSE, nsPrintfCString(16, "%lld", aLastModified)));
return NS_OK;
@ -2266,7 +2269,7 @@ nsNavBookmarks::SetItemTitle(PRInt64 aItemId, const nsACString &aTitle)
rv = statement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(aItemId, NS_LITERAL_CSTRING("title"),
PR_FALSE, aTitle));
return NS_OK;
@ -2644,7 +2647,7 @@ nsNavBookmarks::ChangeBookmarkURI(PRInt64 aBookmarkId, nsIURI *aNewURI)
NS_ENSURE_SUCCESS(rv, rv);
// Pass the new URI to OnItemChanged.
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(aBookmarkId, NS_LITERAL_CSTRING("uri"), PR_FALSE, spec))
return NS_OK;
@ -2771,11 +2774,11 @@ nsNavBookmarks::SetItemIndex(PRInt64 aItemId, PRInt32 aNewIndex)
// XXX (bug 484096) this is really inefficient and we should look into using
// onItemChanged here!
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnBeforeItemRemoved(aItemId))
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemRemoved(aItemId, parent, oldIndex))
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemAdded(aItemId, parent, aNewIndex))
return NS_OK;
@ -2861,7 +2864,7 @@ nsNavBookmarks::SetKeywordForBookmark(PRInt64 aBookmarkId, const nsAString& aKey
transaction.Commit();
// Pass the new keyword to OnItemChanged.
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(aBookmarkId, NS_LITERAL_CSTRING("keyword"),
PR_FALSE, NS_ConvertUTF16toUTF8(aKeyword)))
@ -2947,7 +2950,7 @@ nsNavBookmarks::BeginUpdateBatch()
if (mBatchHasTransaction)
conn->BeginTransaction();
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnBeginUpdateBatch())
}
return NS_OK;
@ -2960,7 +2963,7 @@ nsNavBookmarks::EndUpdateBatch()
if (mBatchHasTransaction)
mDBConn->CommitTransaction();
mBatchHasTransaction = PR_FALSE;
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnEndUpdateBatch())
}
return NS_OK;
@ -3033,7 +3036,7 @@ nsNavBookmarks::OnVisit(nsIURI *aURI, PRInt64 aVisitID, PRTime aTime,
if (bookmarks.Length()) {
for (PRUint32 i = 0; i < bookmarks.Length(); i++)
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemVisited(bookmarks[i], aVisitID, aTime))
}
}
@ -3055,7 +3058,7 @@ nsNavBookmarks::OnDeleteURI(nsIURI *aURI)
if (bookmarks.Length()) {
for (PRUint32 i = 0; i < bookmarks.Length(); i ++)
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(bookmarks[i], NS_LITERAL_CSTRING("cleartime"),
PR_FALSE, EmptyCString()))
}
@ -3104,7 +3107,7 @@ nsNavBookmarks::OnPageChanged(nsIURI *aURI, PRUint32 aWhat,
NS_ENSURE_STATE(queries.Count() == 1);
NS_ENSURE_STATE(queries[0]->Folders().Length() == 1);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(queries[0]->Folders()[0], NS_LITERAL_CSTRING("favicon"),
PR_FALSE, NS_ConvertUTF16toUTF8(aValue)));
}
@ -3116,7 +3119,7 @@ nsNavBookmarks::OnPageChanged(nsIURI *aURI, PRUint32 aWhat,
if (bookmarks.Length()) {
for (PRUint32 i = 0; i < bookmarks.Length(); i ++)
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(bookmarks[i], NS_LITERAL_CSTRING("favicon"),
PR_FALSE, NS_ConvertUTF16toUTF8(aValue)));
}
@ -3147,7 +3150,7 @@ nsNavBookmarks::OnItemAnnotationSet(PRInt64 aItemId, const nsACString& aName)
nsresult rv = SetItemDateInternal(mDBSetItemLastModified, aItemId, PR_Now());
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(aItemId, aName, PR_TRUE, EmptyCString()));
return NS_OK;
@ -3166,7 +3169,7 @@ nsNavBookmarks::OnItemAnnotationRemoved(PRInt64 aItemId, const nsACString& aName
nsresult rv = SetItemDateInternal(mDBSetItemLastModified, aItemId, PR_Now());
NS_ENSURE_SUCCESS(rv, rv);
ENUMERATE_WEAKARRAY(mObservers, nsINavBookmarkObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavBookmarkObserver,
OnItemChanged(aItemId, aName, PR_TRUE, EmptyCString()));
return NS_OK;

Просмотреть файл

@ -45,6 +45,7 @@
#include "nsNavHistory.h"
#include "nsNavHistoryResult.h" // need for Int64 hashtable
#include "nsToolkitCompsCID.h"
#include "nsCategoryCache.h"
class nsIOutputStream;
@ -296,6 +297,10 @@ private:
nsString mType;
PRInt32 mIndex;
};
// Used to enable and disable the observer notifications
PRBool mCanFireNotifs;
nsCategoryCache<nsINavBookmarkObserver> mCacheObservers;
};
struct nsBookmarksUpdateBatcher

Просмотреть файл

@ -92,6 +92,7 @@
#include "mozStorageCID.h"
#include "mozStorageHelper.h"
#include "nsPlacesTriggers.h"
#include "nsPlacesMacros.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIIdleService.h"
#include "nsILivemarkService.h"
@ -393,7 +394,9 @@ nsNavHistory::nsNavHistory() : mBatchLevel(0),
mNumVisitsForFrecency(10),
mTagsFolder(-1),
mInPrivateBrowsing(PRIVATEBROWSING_NOTINITED),
mDatabaseStatus(DATABASE_STATUS_OK)
mDatabaseStatus(DATABASE_STATUS_OK),
mCanFireNotifs(PR_TRUE),
mCacheObservers("history-observers")
{
#ifdef LAZY_ADD
mLazyTimerSet = PR_TRUE;
@ -2780,7 +2783,7 @@ nsNavHistory::AddVisit(nsIURI* aURI, PRTime aTime, nsIURI* aReferringURI,
PRUint32 added = 0;
if (!hidden && aTransitionType != TRANSITION_EMBED &&
aTransitionType != TRANSITION_DOWNLOAD) {
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavHistoryObserver,
OnVisit(aURI, *aVisitID, aTime, aSessionID,
referringVisitID, aTransitionType, &added));
}
@ -4273,7 +4276,7 @@ nsNavHistory::BeginUpdateBatch()
if (mBatchHasTransaction)
mDBConn->BeginTransaction();
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavHistoryObserver,
OnBeginUpdateBatch())
}
return NS_OK;
@ -4287,7 +4290,8 @@ nsNavHistory::EndUpdateBatch()
if (mBatchHasTransaction)
mDBConn->CommitTransaction();
mBatchHasTransaction = PR_FALSE;
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver, OnEndUpdateBatch())
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavHistoryObserver,
OnEndUpdateBatch())
}
return NS_OK;
}
@ -4558,8 +4562,10 @@ nsNavHistory::RemovePage(nsIURI *aURI)
nsIURI** URIs = &aURI;
nsresult rv = RemovePages(URIs, 1, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
// call observers here for the removed url
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver, OnDeleteURI(aURI))
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavHistoryObserver,
OnDeleteURI(aURI))
return NS_OK;
}
@ -4821,7 +4827,7 @@ nsNavHistory::HidePage(nsIURI *aURI)
// notify observers, finish transaction first
transaction.Commit();
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavHistoryObserver,
OnPageChanged(aURI,
nsINavHistoryObserver::ATTRIBUTE_HIDDEN,
EmptyString()))
@ -5465,7 +5471,7 @@ NS_IMETHODIMP
nsNavHistory::NotifyOnPageExpired(nsIURI *aURI, PRTime aVisitTime,
PRBool aWholeEntry)
{
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavHistoryObserver,
OnPageExpired(aURI, aVisitTime, aWholeEntry));
return NS_OK;
}
@ -6674,6 +6680,14 @@ nsNavHistory::BookmarkIdToResultNode(PRInt64 aBookmarkId, nsNavHistoryQueryOptio
return RowToResult(stmt, aOptions, aResult);
}
void
nsNavHistory::SendPageChangedNotification(nsIURI* aURI, PRUint32 aWhat,
const nsAString& aValue)
{
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavHistoryObserver,
OnPageChanged(aURI, aWhat, aValue));
}
// nsNavHistory::TitleForDomain
//
// This computes the title for a given domain. Normally, this is just the
@ -6803,11 +6817,10 @@ nsNavHistory::SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle)
NS_ENSURE_SUCCESS(rv, rv);
// observers (have to check first if it's bookmarked)
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver,
ENUMERATE_OBSERVERS(mCanFireNotifs, mCacheObservers, mObservers, nsINavHistoryObserver,
OnTitleChanged(aURI, aTitle))
return NS_OK;
}
nsresult

Просмотреть файл

@ -82,6 +82,7 @@
#include "nsTArray.h"
#include "nsINavBookmarksService.h"
#include "nsMaybeWeakPtr.h"
#include "nsCategoryCache.h"
#include "nsNavHistoryExpire.h"
#include "nsNavHistoryResult.h"
@ -307,11 +308,7 @@ public:
// used by other places components to send history notifications (for example,
// when the favicon has changed)
void SendPageChangedNotification(nsIURI* aURI, PRUint32 aWhat,
const nsAString& aValue)
{
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver,
OnPageChanged(aURI, aWhat, aValue));
}
const nsAString& aValue);
// current time optimization
PRTime GetNow();
@ -831,6 +828,10 @@ protected:
PRBool mInPrivateBrowsing;
PRUint16 mDatabaseStatus;
// Used to enable and disable the observer notifications
PRBool mCanFireNotifs;
nsCategoryCache<nsINavHistoryObserver> mCacheObservers;
};
/**

Просмотреть файл

@ -47,6 +47,7 @@
#include "nsNetUtil.h"
#include "nsIAnnotationService.h"
#include "nsPrintfCString.h"
#include "nsPlacesMacros.h"
struct nsNavHistoryExpireRecord {
nsNavHistoryExpireRecord(mozIStorageStatement* statement);
@ -278,8 +279,8 @@ nsNavHistoryExpire::ClearHistory()
// forcibly call the "on idle" timer here to do a little work
// but the rest will happen on idle.
ENUMERATE_WEAKARRAY(mHistory->mObservers, nsINavHistoryObserver,
OnClearHistory())
ENUMERATE_OBSERVERS(PR_TRUE, mHistory->mCacheObservers, mHistory->mObservers,
nsINavHistoryObserver, OnClearHistory())
return NS_OK;
}
@ -383,7 +384,8 @@ nsNavHistoryExpire::ExpireItems(PRUint32 aNumToExpire, PRBool* aKeepGoing)
// FIXME bug 325241 provide a way to observe hidden elements
if (expiredVisits[i].hidden) continue;
ENUMERATE_WEAKARRAY(mHistory->mObservers, nsINavHistoryObserver,
ENUMERATE_OBSERVERS(PR_TRUE, mHistory->mCacheObservers, mHistory->mObservers,
nsINavHistoryObserver,
OnPageExpired(uri, expiredVisits[i].visitDate,
expiredVisits[i].erased));
}

Просмотреть файл

@ -103,10 +103,6 @@ function nsPlacesDBFlush()
}
// Register observers
this._bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
this._bs.addObserver(this, false);
this._os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
this._os.addObserver(this, kQuitApplication, false);
@ -149,7 +145,6 @@ nsPlacesDBFlush.prototype = {
observe: function DBFlush_observe(aSubject, aTopic, aData)
{
if (aTopic == kQuitApplication) {
this._bs.removeObserver(this);
this._os.removeObserver(this, kQuitApplication);
let (pb2 = this._prefs.QueryInterface(Ci.nsIPrefBranch2)) {
pb2.removeObserver(kSyncPrefName, this);
@ -226,10 +221,12 @@ nsPlacesDBFlush.prototype = {
onItemAdded: function(aItemId, aParentId, aIndex)
{
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
// Sync only if we added a TYPE_BOOKMARK item. Note, we want to run the
// least amount of queries as possible here for performance reasons.
if (!this._inBatchMode &&
this._bs.getItemType(aItemId) == this._bs.TYPE_BOOKMARK)
if (!this._inBatchMode && bs.getItemType(aItemId) == bs.TYPE_BOOKMARK)
this._flushWithQueries([kQuerySyncPlacesId]);
},
@ -245,6 +242,24 @@ nsPlacesDBFlush.prototype = {
onItemVisited: function() { },
onItemMoved: function() { },
//////////////////////////////////////////////////////////////////////////////
//// nsINavHistoryObserver
// We currently only use the history observer to know when the history service
// is activated. At that point, we actually get initialized, and our timer
// to sync history is added.
// These methods share the name of the ones on nsINavBookmarkObserver, so
// the implementations can be found above.
//onBeginUpdateBatch: function() { },
//onEndUpdateBatch: function() { },
onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID, aTransitionType) { },
onTitleChanged: function(aURI, aPageTitle) { },
onDeleteURI: function(aURI) { },
onClearHistory: function() { },
onPageChanged: function(aURI, aWhat, aValue) { },
onPageExpired: function(aURI, aVisitTime, aWholeEntry) { },
//////////////////////////////////////////////////////////////////////////////
//// nsITimerCallback
@ -458,13 +473,18 @@ nsPlacesDBFlush.prototype = {
classDescription: "Used to synchronize the temporary and permanent tables of Places",
classID: Components.ID("c1751cfc-e8f1-4ade-b0bb-f74edfb8ef6a"),
contractID: "@mozilla.org/places/sync;1",
_xpcom_categories: [{
category: "profile-after-change",
}],
// Registering in these categories makes us get initialized when either of
// those listeners would be notified.
_xpcom_categories: [
{ category: "bookmark-observers" },
{ category: "history-observers" },
],
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIObserver,
Ci.nsINavBookmarkObserver,
Ci.nsINavHistoryObserver,
Ci.nsITimerCallback,
Ci.mozIStorageStatementCallback,
])

Просмотреть файл

@ -0,0 +1,50 @@
/* -*- 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.
*
* The Initial Developer of the Original Code is Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Finkle <mfinkle@mozilla.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 ***** */
#include "prtypes.h"
// Call a method on each observer in a category cache, then call the same
// method the observer array.
#define ENUMERATE_OBSERVERS(canFire, cache, array, type, method) \
PR_BEGIN_MACRO \
if (canFire) { \
const nsCOMArray<type> &entries = cache.GetEntries(); \
for (PRInt32 idx = 0; idx < entries.Count(); ++idx) \
entries[idx]->method; \
ENUMERATE_WEAKARRAY(array, type, method) \
} \
PR_END_MACRO;

Просмотреть файл

@ -0,0 +1,97 @@
/* ***** 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 unit test code.
*
* The Initial Developer of the Original Code is Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Finkle <mfinkle@mozilla.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 ***** */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
const Cc = Components.classes;
const Ci = Components.interfaces;
// Dummy boomark/history observer
function DummyObserver() {
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.notifyObservers(null, "dummy-observer-created", null);
}
DummyObserver.prototype = {
// history observer
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID, aTransitionType) {
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.notifyObservers(null, "dummy-observer-visited", null);
},
onTitleChanged: function(aURI, aPageTitle) {},
onDeleteURI: function(aURI) {},
onClearHistory: function() {},
onPageChanged: function(aURI, aWhat, aValue) {},
onPageExpired: function(aURI, aVisitTime, aWholeEntry) {},
// bookmark observer
//onBeginUpdateBatch: function() {},
//onEndUpdateBatch: function() {},
onItemAdded: function(aItemId, aParentId, aIndex) {
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
os.notifyObservers(null, "dummy-observer-item-added", null);
},
onItemChanged: function (aItemId, aProperty, aIsAnnotationProperty, aValue) {},
onBeforeItemRemoved: function() {},
onItemRemoved: function() {},
onItemVisited: function() {},
onItemMoved: function() {},
classDescription: "Dummy observer used to test category observers",
classID: Components.ID("62e221d3-68c3-4e1a-8943-a27beb5005fe"),
contractID: "@mozilla.org/places/test/dummy-observer;1",
// Registering in these categories makes us get initialized when either of
// those listeners would be notified.
_xpcom_categories: [
{ category: "bookmark-observers" },
{ category: "history-observers" }
],
QueryInterface: XPCOMUtils.generateQI([
Ci.nsINavBookmarkObserver,
Ci.nsINavHistoryObserver,
])
};
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule([DummyObserver]);
}

Просмотреть файл

@ -0,0 +1,81 @@
/* ***** 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 unit test code.
*
* The Initial Developer of the Original Code is Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Finkle <mfinkle@mozilla.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 ***** */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
// Get services.
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let gDummyCreated = false;
let gDummyAdded = false;
let observer = {
observe: function(subject, topic, data) {
if (topic == "dummy-observer-created")
gDummyCreated = true;
else if (topic == "dummy-observer-item-added")
gDummyAdded = true;
},
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIObserver,
Ci.nsISupportsWeakReference
])
};
function verify() {
do_check_true(gDummyCreated);
do_check_true(gDummyAdded);
do_test_finished();
}
// main
function run_test() {
do_load_module("toolkit/components/places/tests/unit/nsDummyObserver.js");
os.addObserver(observer, "dummy-observer-created", true);
os.addObserver(observer, "dummy-observer-item-added", true);
// Add a bookmark
bs.insertBookmark(bs.unfiledBookmarksFolder, uri("http://typed.mozilla.org"),
bs.DEFAULT_INDEX, "bookmark");
do_test_pending();
do_timeout(1000, "verify();");
}

Просмотреть файл

@ -0,0 +1,81 @@
/* ***** 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 unit test code.
*
* The Initial Developer of the Original Code is Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Finkle <mfinkle@mozilla.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 ***** */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
// Get services.
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let gDummyCreated = false;
let gDummyVisited = false;
let observer = {
observe: function(subject, topic, data) {
if (topic == "dummy-observer-created")
gDummyCreated = true;
else if (topic == "dummy-observer-visited")
gDummyVisited = true;
},
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIObserver,
Ci.nsISupportsWeakReference
])
};
function verify() {
do_check_true(gDummyCreated);
do_check_true(gDummyVisited);
do_test_finished();
}
// main
function run_test() {
do_load_module("toolkit/components/places/tests/unit/nsDummyObserver.js");
os.addObserver(observer, "dummy-observer-created", true);
os.addObserver(observer, "dummy-observer-visited", true);
// Add a visit
hs.addVisit(uri("http://typed.mozilla.org"), Date.now(), null,
hs.TRANSITION_TYPED, false, 0);
do_test_pending();
do_timeout(1000, "verify();");
}