mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 1436966 - Remove the bookmark-observers & history-observers category listeners. r=mak
MozReview-Commit-ID: 2dsyxZG98IR --HG-- extra : rebase_source : 89767cf42ee5e903f0b72900e7c8f85ac590a3c3
This commit is contained in:
parent
1f1e4dde69
commit
6ccff895ed
@ -163,7 +163,6 @@ nsNavBookmarks::nsNavBookmarks()
|
||||
, mToolbarRoot(0)
|
||||
, mMobileRoot(0)
|
||||
, mCanNotify(false)
|
||||
, mCacheObservers("bookmark-observers")
|
||||
, mBatching(false)
|
||||
{
|
||||
NS_ASSERTION(!gBookmarksService,
|
||||
@ -628,7 +627,7 @@ nsNavBookmarks::InsertBookmark(int64_t aFolder,
|
||||
rv = transaction.Commit();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers,
|
||||
SKIP_TAGS(grandParentId == mTagsRoot),
|
||||
OnItemAdded(*aNewBookmarkId, aFolder, index,
|
||||
TYPE_BOOKMARK, aURI, title, dateAdded,
|
||||
@ -647,8 +646,7 @@ nsNavBookmarks::InsertBookmark(int64_t aFolder,
|
||||
// Check that bookmarks doesn't include the current tag itemId.
|
||||
MOZ_ASSERT(bookmarks[i].id != *aNewBookmarkId);
|
||||
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
DontSkip,
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, DontSkip,
|
||||
OnItemChanged(bookmarks[i].id,
|
||||
NS_LITERAL_CSTRING("tags"),
|
||||
false,
|
||||
@ -758,7 +756,7 @@ nsNavBookmarks::RemoveItem(int64_t aItemId, uint16_t aSource)
|
||||
NS_WARNING_ASSERTION(uri, "Invalid URI in RemoveItem");
|
||||
}
|
||||
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers,
|
||||
SKIP_TAGS(bookmark.parentId == tagsRootId ||
|
||||
bookmark.grandParentId == tagsRootId),
|
||||
OnItemRemoved(bookmark.id,
|
||||
@ -779,8 +777,7 @@ nsNavBookmarks::RemoveItem(int64_t aItemId, uint16_t aSource)
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
for (uint32_t i = 0; i < bookmarks.Length(); ++i) {
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
DontSkip,
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, DontSkip,
|
||||
OnItemChanged(bookmarks[i].id,
|
||||
NS_LITERAL_CSTRING("tags"),
|
||||
false,
|
||||
@ -881,7 +878,7 @@ nsNavBookmarks::CreateContainerWithID(int64_t aItemId,
|
||||
|
||||
int64_t tagsRootId = TagsRootId();
|
||||
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers,
|
||||
SKIP_TAGS(aParent == tagsRootId),
|
||||
OnItemAdded(*aNewFolder, aParent, index, FOLDER,
|
||||
nullptr, title, dateAdded, guid,
|
||||
@ -937,8 +934,7 @@ nsNavBookmarks::InsertSeparator(int64_t aParent,
|
||||
rv = transaction.Commit();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
DontSkip,
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, DontSkip,
|
||||
OnItemAdded(*aNewItemId, aParent, index, TYPE_SEPARATOR,
|
||||
nullptr, EmptyCString(), dateAdded, guid,
|
||||
folderGuid, aSource));
|
||||
@ -1211,7 +1207,7 @@ nsNavBookmarks::RemoveFolderChildren(int64_t aFolderId, uint16_t aSource)
|
||||
NS_WARNING_ASSERTION(uri, "Invalid URI in RemoveFolderChildren");
|
||||
}
|
||||
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers,
|
||||
((child.grandParentId == tagsRootId) ? SkipTags : SkipDescendants),
|
||||
OnItemRemoved(child.id,
|
||||
child.parentId,
|
||||
@ -1232,8 +1228,7 @@ nsNavBookmarks::RemoveFolderChildren(int64_t aFolderId, uint16_t aSource)
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
for (uint32_t i = 0; i < bookmarks.Length(); ++i) {
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
DontSkip,
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, DontSkip,
|
||||
OnItemChanged(bookmarks[i].id,
|
||||
NS_LITERAL_CSTRING("tags"),
|
||||
false,
|
||||
@ -1418,8 +1413,7 @@ nsNavBookmarks::MoveItem(int64_t aItemId,
|
||||
rv = transaction.Commit();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver,
|
||||
OnItemMoved(bookmark.id,
|
||||
bookmark.parentId,
|
||||
bookmark.position,
|
||||
@ -1587,8 +1581,7 @@ nsNavBookmarks::SetItemDateAdded(int64_t aItemId, PRTime aDateAdded,
|
||||
}
|
||||
|
||||
// Note: mDBSetItemDateAdded also sets lastModified to aDateAdded.
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver,
|
||||
OnItemChanged(bookmark.id,
|
||||
NS_LITERAL_CSTRING("dateAdded"),
|
||||
false,
|
||||
@ -1658,8 +1651,7 @@ nsNavBookmarks::SetItemLastModified(int64_t aItemId, PRTime aLastModified,
|
||||
}
|
||||
|
||||
// Note: mDBSetItemDateAdded also sets lastModified to aDateAdded.
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver,
|
||||
OnItemChanged(bookmark.id,
|
||||
NS_LITERAL_CSTRING("lastModified"),
|
||||
false,
|
||||
@ -1910,8 +1902,7 @@ nsNavBookmarks::SetItemTitle(int64_t aItemId, const nsACString& aTitle,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
SKIP_TAGS(isChangingTagFolder),
|
||||
NOTIFY_BOOKMARKS_OBSERVERS(mCanNotify, mObservers, SKIP_TAGS(isChangingTagFolder),
|
||||
OnItemChanged(bookmark.id,
|
||||
NS_LITERAL_CSTRING("title"),
|
||||
false,
|
||||
@ -2457,8 +2448,7 @@ nsNavBookmarks::SetKeywordForBookmark(int64_t aBookmarkId,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
for (uint32_t i = 0; i < bookmarks.Length(); ++i) {
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver,
|
||||
OnItemChanged(bookmarks[i].id,
|
||||
NS_LITERAL_CSTRING("keyword"),
|
||||
false,
|
||||
@ -2514,8 +2504,7 @@ nsNavBookmarks::SetKeywordForBookmark(int64_t aBookmarkId,
|
||||
rv = GetBookmarksForURI(oldUri, bookmarks);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
for (uint32_t i = 0; i < bookmarks.Length(); ++i) {
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver,
|
||||
OnItemChanged(bookmarks[i].id,
|
||||
NS_LITERAL_CSTRING("keyword"),
|
||||
false,
|
||||
@ -2585,8 +2574,7 @@ nsNavBookmarks::SetKeywordForBookmark(int64_t aBookmarkId,
|
||||
|
||||
// In both cases, notify about the change.
|
||||
for (uint32_t i = 0; i < bookmarks.Length(); ++i) {
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver,
|
||||
OnItemChanged(bookmarks[i].id,
|
||||
NS_LITERAL_CSTRING("keyword"),
|
||||
false,
|
||||
@ -2698,10 +2686,6 @@ nsNavBookmarks::GetObservers(uint32_t* _count,
|
||||
|
||||
nsCOMArray<nsINavBookmarkObserver> observers;
|
||||
|
||||
// First add the category cache observers.
|
||||
mCacheObservers.GetEntries(observers);
|
||||
|
||||
// Then add the other observers.
|
||||
for (uint32_t i = 0; i < mObservers.Length(); ++i) {
|
||||
const nsCOMPtr<nsINavBookmarkObserver> &observer = mObservers.ElementAt(i).GetValue();
|
||||
// Skip nullified weak observers.
|
||||
@ -2727,8 +2711,7 @@ nsNavBookmarks::NotifyItemVisited(const ItemVisitData& aData)
|
||||
// couldn't gather enough data from the notification.
|
||||
// This should be false only if there's a bug in the code preceding us.
|
||||
if (uri) {
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver,
|
||||
OnItemVisited(aData.bookmark.id,
|
||||
aData.visitId,
|
||||
aData.time,
|
||||
@ -2754,8 +2737,7 @@ nsNavBookmarks::NotifyItemChanged(const ItemChangeData& aData)
|
||||
aData.bookmark.id, lastModified));
|
||||
}
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavBookmarkObserver,
|
||||
OnItemChanged(aData.bookmark.id,
|
||||
aData.property,
|
||||
aData.isAnnotation,
|
||||
@ -2794,7 +2776,7 @@ nsNavBookmarks::Observe(nsISupports *aSubject, const char *aTopic,
|
||||
NS_IMETHODIMP
|
||||
nsNavBookmarks::OnBeginUpdateBatch()
|
||||
{
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers,
|
||||
nsINavBookmarkObserver, OnBeginUpdateBatch());
|
||||
return NS_OK;
|
||||
}
|
||||
@ -2807,7 +2789,7 @@ nsNavBookmarks::OnEndUpdateBatch()
|
||||
mBatching = false;
|
||||
}
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers,
|
||||
nsINavBookmarkObserver, OnEndUpdateBatch());
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -460,7 +460,6 @@ private:
|
||||
|
||||
// Used to enable and disable the observer notifications.
|
||||
bool mCanNotify;
|
||||
nsCategoryCache<nsINavBookmarkObserver> mCacheObservers;
|
||||
|
||||
// Tracks whether we are in batch mode.
|
||||
// Note: this is only tracking bookmarks batches, not history ones.
|
||||
|
@ -286,7 +286,6 @@ nsNavHistory::nsNavHistory()
|
||||
, mLastCachedStartOfDay(INT64_MAX)
|
||||
, mLastCachedEndOfDay(0)
|
||||
, mCanNotify(true)
|
||||
, mCacheObservers("history-observers")
|
||||
#ifdef XP_WIN
|
||||
, mCryptoProviderInitialized(false)
|
||||
#endif
|
||||
@ -536,8 +535,7 @@ nsNavHistory::NotifyOnVisits(nsIVisitData** aVisits, uint32_t aVisitsCount)
|
||||
}
|
||||
}
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
|
||||
OnVisits(aVisits, aVisitsCount));
|
||||
}
|
||||
|
||||
@ -547,8 +545,8 @@ nsNavHistory::NotifyTitleChange(nsIURI* aURI,
|
||||
const nsACString& aGUID)
|
||||
{
|
||||
MOZ_ASSERT(!aGUID.IsEmpty());
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver, OnTitleChanged(aURI, aTitle, aGUID));
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
|
||||
OnTitleChanged(aURI, aTitle, aGUID));
|
||||
}
|
||||
|
||||
void
|
||||
@ -559,8 +557,7 @@ nsNavHistory::NotifyFrecencyChanged(nsIURI* aURI,
|
||||
PRTime aLastVisitDate)
|
||||
{
|
||||
MOZ_ASSERT(!aGUID.IsEmpty());
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
|
||||
OnFrecencyChanged(aURI, aNewFrecency, aGUID, aHidden,
|
||||
aLastVisitDate));
|
||||
}
|
||||
@ -568,8 +565,7 @@ nsNavHistory::NotifyFrecencyChanged(nsIURI* aURI,
|
||||
void
|
||||
nsNavHistory::NotifyManyFrecenciesChanged()
|
||||
{
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
|
||||
OnManyFrecenciesChanged());
|
||||
}
|
||||
|
||||
@ -2379,9 +2375,6 @@ nsNavHistory::GetObservers(uint32_t* _count,
|
||||
|
||||
nsCOMArray<nsINavHistoryObserver> observers;
|
||||
|
||||
// First add the category cache observers.
|
||||
mCacheObservers.GetEntries(observers);
|
||||
|
||||
// Then add the other observers.
|
||||
for (uint32_t i = 0; i < mObservers.Length(); ++i) {
|
||||
const nsCOMPtr<nsINavHistoryObserver> &observer = mObservers.ElementAt(i).GetValue();
|
||||
@ -2408,8 +2401,7 @@ nsNavHistory::BeginUpdateBatch()
|
||||
mozIStorageConnection::TRANSACTION_DEFERRED,
|
||||
true);
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver, OnBeginUpdateBatch());
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnBeginUpdateBatch());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -2427,8 +2419,7 @@ nsNavHistory::EndUpdateBatch()
|
||||
mBatchDBTransaction = nullptr;
|
||||
}
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver, OnEndUpdateBatch());
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver, OnEndUpdateBatch());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -2556,8 +2547,7 @@ nsNavHistory::CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString)
|
||||
else {
|
||||
// Notify that we will delete all visits for this page, but not the page
|
||||
// itself, since it's bookmarked or a place: query.
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
|
||||
OnDeleteVisits(uri, 0, guid, nsINavHistoryObserver::REASON_DELETED, 0));
|
||||
}
|
||||
}
|
||||
@ -2604,8 +2594,7 @@ nsNavHistory::CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString)
|
||||
|
||||
// Finally notify about the removed URIs.
|
||||
for (int32_t i = 0; i < URIs.Count(); ++i) {
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
|
||||
OnDeleteURI(URIs[i], GUIDs[i], nsINavHistoryObserver::REASON_DELETED));
|
||||
}
|
||||
|
||||
@ -2970,13 +2959,12 @@ nsNavHistory::NotifyOnPageExpired(nsIURI *aURI, PRTime aVisitTime,
|
||||
MOZ_ASSERT(!aGUID.IsEmpty());
|
||||
if (aWholeEntry) {
|
||||
// Notify our observers that the page has been removed.
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver, OnDeleteURI(aURI, aGUID, aReason));
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
|
||||
OnDeleteURI(aURI, aGUID, aReason));
|
||||
}
|
||||
else {
|
||||
// Notify our observers that some visits for the page have been removed.
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
|
||||
OnDeleteVisits(aURI, aVisitTime, aGUID, aReason,
|
||||
aTransitionType));
|
||||
}
|
||||
@ -4171,8 +4159,7 @@ nsNavHistory::SendPageChangedNotification(nsIURI* aURI,
|
||||
const nsACString& aGUID)
|
||||
{
|
||||
MOZ_ASSERT(!aGUID.IsEmpty());
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavHistoryObserver,
|
||||
NOTIFY_OBSERVERS(mCanNotify, mObservers, nsINavHistoryObserver,
|
||||
OnPageChanged(aURI, aChangedAttribute, aNewValue, aGUID));
|
||||
}
|
||||
|
||||
|
@ -656,7 +656,6 @@ protected:
|
||||
|
||||
// Used to enable and disable the observer notifications
|
||||
bool mCanNotify;
|
||||
nsCategoryCache<nsINavHistoryObserver> mCacheObservers;
|
||||
|
||||
// Used to cache the call to CryptAcquireContext, which is expensive
|
||||
// when called thousands of times
|
||||
|
@ -503,6 +503,12 @@ nsPlacesExpiration.prototype = {
|
||||
this._expireWithActionAndLimit(ACTION.IDLE_DAILY, LIMIT.LARGE);
|
||||
} else if (aTopic == TOPIC_TESTING_MODE) {
|
||||
this._testingMode = true;
|
||||
} else if (aTopic == PlacesUtils.TOPIC_INIT_COMPLETE) {
|
||||
// Ideally we'd add this observer only when notifications start being
|
||||
// triggered. However, that's difficult to work out, so we do it on
|
||||
// TOPIC_INIT_COMPLETE which means we have to take the hit of initializing
|
||||
// this service slightly earlier.
|
||||
PlacesUtils.history.addObserver(this, true);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -12,27 +12,16 @@
|
||||
|
||||
// Call a method on each observer in a category cache, then call the same
|
||||
// method on the observer array.
|
||||
#define NOTIFY_OBSERVERS(canFire, cache, array, type, method) \
|
||||
#define NOTIFY_OBSERVERS(canFire, array, type, method) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (canFire) { \
|
||||
nsCOMArray<type> entries; \
|
||||
cache.GetEntries(entries); \
|
||||
for (int32_t idx = 0; idx < entries.Count(); ++idx) \
|
||||
entries[idx]->method; \
|
||||
ENUMERATE_WEAKARRAY(array, type, method) \
|
||||
} \
|
||||
PR_END_MACRO;
|
||||
|
||||
#define NOTIFY_BOOKMARKS_OBSERVERS(canFire, cache, array, skipIf, method) \
|
||||
#define NOTIFY_BOOKMARKS_OBSERVERS(canFire, array, skipIf, method) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (canFire) { \
|
||||
nsCOMArray<nsINavBookmarkObserver> entries; \
|
||||
cache.GetEntries(entries); \
|
||||
for (int32_t idx = 0; idx < entries.Count(); ++idx) { \
|
||||
if (skipIf(entries[idx])) \
|
||||
continue; \
|
||||
entries[idx]->method; \
|
||||
} \
|
||||
for (uint32_t idx = 0; idx < array.Length(); ++idx) { \
|
||||
const nsCOMPtr<nsINavBookmarkObserver> &e = array.ElementAt(idx).GetValue(); \
|
||||
if (e) { \
|
||||
|
@ -1,45 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Dummy boomark/history observer
|
||||
function DummyObserver() {
|
||||
Services.obs.notifyObservers(null, "dummy-observer-created");
|
||||
}
|
||||
|
||||
DummyObserver.prototype = {
|
||||
// history observer
|
||||
onBeginUpdateBatch() {},
|
||||
onEndUpdateBatch() {},
|
||||
onVisits(aVisits) {
|
||||
Services.obs.notifyObservers(null, "dummy-observer-visited");
|
||||
},
|
||||
onTitleChanged() {},
|
||||
onDeleteURI() {},
|
||||
onClearHistory() {},
|
||||
onPageChanged() {},
|
||||
onDeleteVisits() {},
|
||||
|
||||
// bookmark observer
|
||||
// onBeginUpdateBatch: function() {},
|
||||
// onEndUpdateBatch: function() {},
|
||||
onItemAdded(aItemId, aParentId, aIndex, aItemType, aURI) {
|
||||
Services.obs.notifyObservers(null, "dummy-observer-item-added");
|
||||
},
|
||||
onItemChanged() {},
|
||||
onItemRemoved() {},
|
||||
onItemVisited() {},
|
||||
onItemMoved() {},
|
||||
|
||||
classID: Components.ID("62e221d3-68c3-4e1a-8943-a27beb5005fe"),
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsINavBookmarkObserver,
|
||||
Ci.nsINavHistoryObserver,
|
||||
])
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DummyObserver]);
|
@ -1,4 +0,0 @@
|
||||
component 62e221d3-68c3-4e1a-8943-a27beb5005fe nsDummyObserver.js
|
||||
contract @mozilla.org/places/test/dummy-observer;1 62e221d3-68c3-4e1a-8943-a27beb5005fe
|
||||
category bookmark-observers nsDummyObserver @mozilla.org/places/test/dummy-observer;1
|
||||
category history-observers nsDummyObserver @mozilla.org/places/test/dummy-observer;1
|
@ -1,59 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
add_task(async function test_observers() {
|
||||
do_load_manifest("nsDummyObserver.manifest");
|
||||
|
||||
let dummyCreated = false;
|
||||
let dummyReceivedOnItemAdded = false;
|
||||
|
||||
Services.obs.addObserver(function created() {
|
||||
Services.obs.removeObserver(created, "dummy-observer-created");
|
||||
dummyCreated = true;
|
||||
}, "dummy-observer-created");
|
||||
Services.obs.addObserver(function added() {
|
||||
Services.obs.removeObserver(added, "dummy-observer-item-added");
|
||||
dummyReceivedOnItemAdded = true;
|
||||
}, "dummy-observer-item-added");
|
||||
|
||||
// This causes various Async API helpers to be initialised before the main
|
||||
// part of the test runs - the helpers add their own listeners, which we don't
|
||||
// want to count within the test (e.g. gKeywordsCachePromise & GuidHelper).
|
||||
await PlacesUtils.promiseItemId(PlacesUtils.bookmarks.unfiledGuid);
|
||||
|
||||
let initialObservers = PlacesUtils.bookmarks.getObservers();
|
||||
|
||||
// Add a common observer, it should be invoked after the category observer.
|
||||
let notificationsPromised = new Promise((resolve, reject) => {
|
||||
PlacesUtils.bookmarks.addObserver( {
|
||||
__proto__: NavBookmarkObserver.prototype,
|
||||
onItemAdded() {
|
||||
let observers = PlacesUtils.bookmarks.getObservers();
|
||||
Assert.equal(observers.length, initialObservers.length + 1);
|
||||
|
||||
// Check the common observer is the last one.
|
||||
for (let i = 0; i < initialObservers.length; ++i) {
|
||||
Assert.equal(initialObservers[i], observers[i]);
|
||||
}
|
||||
|
||||
PlacesUtils.bookmarks.removeObserver(this);
|
||||
observers = PlacesUtils.bookmarks.getObservers();
|
||||
Assert.equal(observers.length, initialObservers.length);
|
||||
|
||||
// Check the category observer has been invoked before this one.
|
||||
Assert.ok(dummyCreated);
|
||||
Assert.ok(dummyReceivedOnItemAdded);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Add a bookmark
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "bookmark",
|
||||
url: "http://typed.mozilla.org",
|
||||
});
|
||||
|
||||
await notificationsPromised;
|
||||
});
|
@ -1,44 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
add_task(async function() {
|
||||
do_load_manifest("nsDummyObserver.manifest");
|
||||
|
||||
let promises = [];
|
||||
let resolved = 0;
|
||||
promises.push(TestUtils.topicObserved("dummy-observer-created", () => ++resolved));
|
||||
promises.push(TestUtils.topicObserved("dummy-observer-visited", () => ++resolved));
|
||||
|
||||
let initialObservers = PlacesUtils.history.getObservers();
|
||||
|
||||
// Add a common observer, it should be invoked after the category observer.
|
||||
promises.push(new Promise(resolve => {
|
||||
let observer = new NavHistoryObserver();
|
||||
observer.onVisits = visits => {
|
||||
Assert.equal(visits.length, 1, "Got the right number of visits");
|
||||
let uri = visits[0].uri;
|
||||
info("Got visit for " + uri.spec);
|
||||
let observers = PlacesUtils.history.getObservers();
|
||||
let observersCount = observers.length;
|
||||
Assert.ok(observersCount > initialObservers.length);
|
||||
|
||||
// Check the common observer is the last one.
|
||||
for (let i = 0; i < initialObservers.length; ++i) {
|
||||
Assert.equal(initialObservers[i], observers[i]);
|
||||
}
|
||||
|
||||
PlacesUtils.history.removeObserver(observer);
|
||||
observers = PlacesUtils.history.getObservers();
|
||||
Assert.ok(observers.length < observersCount);
|
||||
|
||||
// Check the category observer has been invoked before this one.
|
||||
Assert.equal(resolved, 2);
|
||||
resolve();
|
||||
};
|
||||
PlacesUtils.history.addObserver(observer);
|
||||
}));
|
||||
|
||||
info("Add a visit");
|
||||
await PlacesTestUtils.addVisits(uri("http://typed.mozilla.org"));
|
||||
await Promise.all(promises);
|
||||
});
|
@ -14,8 +14,6 @@ support-files =
|
||||
mobile_bookmarks_multiple_folders.json
|
||||
mobile_bookmarks_root_import.json
|
||||
mobile_bookmarks_root_merge.json
|
||||
nsDummyObserver.js
|
||||
nsDummyObserver.manifest
|
||||
places.sparse.sqlite
|
||||
sync_utils_bookmarks.html
|
||||
sync_utils_bookmarks.json
|
||||
@ -60,7 +58,6 @@ skip-if = os == "linux"
|
||||
[test_async_in_batchmode.js]
|
||||
[test_async_transactions.js]
|
||||
skip-if = (os == "win" && os_version == "5.1") # Bug 1158887
|
||||
[test_bookmark_catobs.js]
|
||||
[test_bookmarks_json.js]
|
||||
skip-if = (os == 'win' && ccov) # Bug 1423667
|
||||
[test_bookmarks_json_corrupt.js]
|
||||
@ -84,7 +81,6 @@ skip-if = (os == 'win' && ccov) # Bug 1423667
|
||||
[test_getChildIndex.js]
|
||||
[test_hash.js]
|
||||
[test_history.js]
|
||||
[test_history_catobs.js]
|
||||
[test_history_clear.js]
|
||||
[test_history_notifications.js]
|
||||
[test_history_observer.js]
|
||||
|
@ -11,7 +11,7 @@ contract @mozilla.org/autocomplete/search;1?name=places-tag-autocomplete {1dcc23
|
||||
# nsPlacesExpiration.js
|
||||
component {705a423f-2f69-42f3-b9fe-1517e0dee56f} nsPlacesExpiration.js
|
||||
contract @mozilla.org/places/expiration;1 {705a423f-2f69-42f3-b9fe-1517e0dee56f}
|
||||
category history-observers nsPlacesExpiration @mozilla.org/places/expiration;1
|
||||
category places-init-complete nsPlacesExpiration @mozilla.org/places/expiration;1
|
||||
|
||||
# PlacesCategoriesStarter.js
|
||||
component {803938d5-e26d-4453-bf46-ad4b26e41114} PlacesCategoriesStarter.js
|
||||
|
Loading…
Reference in New Issue
Block a user