Bug 1101553 - Remove nsPIPlacesHistoryListenersNotifier r=mak

This commit is contained in:
Tim Taubert 2015-01-12 14:39:32 +01:00
parent 4c9d2c66c4
commit f31b261cde
6 changed files with 60 additions and 70 deletions

View File

@ -77,9 +77,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Sqlite",
"resource://gre/modules/Sqlite.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "gNotifier",
"@mozilla.org/browser/nav-history-service;1",
Ci.nsPIPlacesHistoryListenersNotifier);
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
Cu.importGlobalProperties(["URL"]);
@ -529,15 +526,14 @@ let remove = Task.async(function*({guids, urls}, onResult = null) {
}
// 5. Notify observers.
let observers = PlacesUtils.history.getObservers();
let reason = Ci.nsINavHistoryObserver.REASON_DELETED;
for (let {guid, uri, toRemove} of pages) {
gNotifier.notifyOnPageExpired(
uri, // uri
0, // visitTime - There are no more visits
toRemove, // wholeEntry
guid, // guid
Ci.nsINavHistoryObserver.REASON_DELETED, // reason
-1 // transition
);
if (toRemove) {
notify(observers, "onDeleteURI", [uri, guid, reason]);
} else {
notify(observers, "onDeleteVisits", [uri, 0, guid, reason, 0]);
}
}
});

View File

@ -28,7 +28,6 @@ if CONFIG['MOZ_PLACES']:
'nsINavBookmarksService.idl',
'nsITaggingService.idl',
'nsPIPlacesDatabase.idl',
'nsPIPlacesHistoryListenersNotifier.idl',
]
EXPORTS.mozilla.places = [

View File

@ -168,7 +168,6 @@ NS_INTERFACE_MAP_BEGIN(nsNavHistory)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsPIPlacesDatabase)
NS_INTERFACE_MAP_ENTRY(nsPIPlacesHistoryListenersNotifier)
NS_INTERFACE_MAP_ENTRY(mozIStorageVacuumParticipant)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsINavHistoryService)
NS_IMPL_QUERY_CLASSINFO(nsNavHistory)
@ -3051,9 +3050,7 @@ nsNavHistory::AsyncExecuteLegacyQueries(nsINavHistoryQuery** aQueries,
}
// nsPIPlacesHistoryListenersNotifier ******************************************
NS_IMETHODIMP
nsresult
nsNavHistory::NotifyOnPageExpired(nsIURI *aURI, PRTime aVisitTime,
bool aWholeEntry, const nsACString& aGUID,
uint16_t aReason, uint32_t aTransitionType)

View File

@ -8,7 +8,6 @@
#include "nsINavHistoryService.h"
#include "nsPIPlacesDatabase.h"
#include "nsPIPlacesHistoryListenersNotifier.h"
#include "nsIBrowserHistory.h"
#include "nsINavBookmarksService.h"
#include "nsIFaviconService.h"
@ -67,7 +66,6 @@ class nsNavHistory MOZ_FINAL : public nsSupportsWeakReference
, public nsIObserver
, public nsIBrowserHistory
, public nsPIPlacesDatabase
, public nsPIPlacesHistoryListenersNotifier
, public mozIStorageVacuumParticipant
{
friend class PlacesSQLQueryBuilder;
@ -80,7 +78,6 @@ public:
NS_DECL_NSIBROWSERHISTORY
NS_DECL_NSIOBSERVER
NS_DECL_NSPIPLACESDATABASE
NS_DECL_NSPIPLACESHISTORYLISTENERSNOTIFIER
NS_DECL_MOZISTORAGEVACUUMPARTICIPANT
/**
@ -183,6 +180,29 @@ public:
*/
nsresult invalidateFrecencies(const nsCString& aPlaceIdsQueryString);
/**
* Calls onDeleteVisits and onDeleteURI notifications on registered listeners
* with the history service.
*
* @param aURI
* The nsIURI object representing the URI of the page being expired.
* @param aVisitTime
* The time, in microseconds, that the page being expired was visited.
* @param aWholeEntry
* Indicates if this is the last visit for this URI.
* @param aGUID
* The unique ID associated with the page.
* @param aReason
* Indicates the reason for the removal.
* See nsINavHistoryObserver::REASON_* constants.
* @param aTransitionType
* If it's a valid TRANSITION_* value, all visits of the specified type
* have been removed.
*/
nsresult NotifyOnPageExpired(nsIURI *aURI, PRTime aVisitTime,
bool aWholeEntry, const nsACString& aGUID,
uint16_t aReason, uint32_t aTransitionType);
/**
* These functions return non-owning references to the locale-specific
* objects for places components.

View File

@ -1,46 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=2 sts=2 expandtab
* 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/. */
#include "nsISupports.idl"
interface nsIURI;
/**
* This is a private interface used by Places components to notify history
* listeners about important notifications. These should not be used by any
* code that is not part of core.
*
* @note See also: nsINavHistoryObserver
*/
[scriptable, uuid(808cf36c-4c9a-4bdb-91a4-d60a6fc25add)]
interface nsPIPlacesHistoryListenersNotifier : nsISupports
{
/**
* Calls onDeleteVisits and onDeleteURI notifications on registered listeners
* with the history service.
*
* @param aURI
* The nsIURI object representing the URI of the page being expired.
* @param aVisitTime
* The time, in microseconds, that the page being expired was visited.
* @param aWholeEntry
* Indicates if this is the last visit for this URI.
* @param aGUID
* The unique ID associated with the page.
* @param aReason
* Indicates the reason for the removal.
* See nsINavHistoryObserver::REASON_* constants.
* @param aTransitionType
* If it's a valid TRANSITION_* value, all visits of the specified type
* have been removed.
*/
void notifyOnPageExpired(in nsIURI aURI,
in PRTime aVisitTime,
in boolean aWholeEntry,
in ACString aGUID,
in unsigned short aReason,
in unsigned long aTransitionType);
};

View File

@ -27,6 +27,9 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
////////////////////////////////////////////////////////////////////////////////
//// Constants
@ -400,6 +403,24 @@ const EXPIRATION_QUERIES = {
},
};
/**
* Sends a bookmarks notification through the given observers.
*
* @param observers
* array of nsINavBookmarkObserver objects.
* @param notification
* the notification name.
* @param args
* array of arguments to pass to the notification.
*/
function notify(observers, notification, args = []) {
for (let observer of observers) {
try {
observer[notification](...args);
} catch (ex) {}
}
}
////////////////////////////////////////////////////////////////////////////////
//// nsPlacesExpiration definition
@ -430,9 +451,6 @@ function nsPlacesExpiration()
return db;
});
XPCOMUtils.defineLazyServiceGetter(this, "_hsn",
"@mozilla.org/browser/nav-history-service;1",
"nsPIPlacesHistoryListenersNotifier");
XPCOMUtils.defineLazyServiceGetter(this, "_sys",
"@mozilla.org/system-info;1",
"nsIPropertyBag2");
@ -626,9 +644,15 @@ nsPlacesExpiration.prototype = {
let guid = row.getResultByName("guid");
let visitDate = row.getResultByName("visit_date");
let wholeEntry = row.getResultByName("whole_entry");
let reason = Ci.nsINavHistoryObserver.REASON_EXPIRED;
let observers = PlacesUtils.history.getObservers();
// Dispatch expiration notifications to history.
this._hsn.notifyOnPageExpired(uri, visitDate, wholeEntry, guid,
Ci.nsINavHistoryObserver.REASON_EXPIRED, 0);
if (wholeEntry) {
notify(observers, "onDeleteURI", [uri, guid, reason]);
} else {
notify(observers, "onDeleteVisits", [uri, visitDate, guid, reason, 0]);
}
}
},