Bug 492796 - isLivemark should use the livemark cache, instead of the db (r=marco)

This commit is contained in:
Dietrich Ayala
2009-06-12 15:39:42 -07:00
parent 0ad4fa6939
commit 63d5d14b23
7 changed files with 66 additions and 74 deletions

View File

@@ -699,7 +699,7 @@ var BookmarksEventHandler = {
var itemId = target._resultNode.itemId;
var siteURIString = "";
if (itemId != -1 && PlacesUtils.livemarks.isLivemark(itemId)) {
if (itemId != -1 && PlacesUtils.itemIsLivemark(itemId)) {
var siteURI = PlacesUtils.livemarks.getSiteURI(itemId);
if (siteURI)
siteURIString = siteURI.spec;

View File

@@ -283,7 +283,7 @@ var BookmarkPropertiesPanel = {
break;
case "folder":
if (PlacesUtils.livemarks.isLivemark(this._itemId)) {
if (PlacesUtils.itemIsLivemark(this._itemId)) {
this._itemType = LIVEMARK_CONTAINER;
this._feedURI = PlacesUtils.livemarks.getFeedURI(this._itemId);
this._siteURI = PlacesUtils.livemarks.getSiteURI(this._itemId);

View File

@@ -162,12 +162,12 @@ var gEditItemOverlay = {
}
else {
this._itemId = aFor;
var container = PlacesUtils.bookmarks.getFolderIdForItem(this._itemId);
var containerId = PlacesUtils.bookmarks.getFolderIdForItem(this._itemId);
this._itemType = PlacesUtils.bookmarks.getItemType(this._itemId);
if (this._itemType == Ci.nsINavBookmarksService.TYPE_BOOKMARK) {
this._uri = PlacesUtils.bookmarks.getBookmarkURI(this._itemId);
if (!this._readOnly) // If readOnly wasn't forced through aInfo
this._readOnly = PlacesUtils.livemarks.isLivemark(container);
this._readOnly = PlacesUtils.itemIsLivemark(containerId);
this._initTextField("keywordField",
PlacesUtils.bookmarks
.getKeywordForBookmark(this._itemId));
@@ -181,7 +181,7 @@ var gEditItemOverlay = {
this._readOnly = false;
this._uri = null;
this._isLivemark = PlacesUtils.livemarks.isLivemark(this._itemId);
this._isLivemark = PlacesUtils.itemIsLivemark(this._itemId);
if (this._isLivemark) {
var feedURI = PlacesUtils.livemarks.getFeedURI(this._itemId);
var siteURI = PlacesUtils.livemarks.getSiteURI(this._itemId);
@@ -191,7 +191,7 @@ var gEditItemOverlay = {
}
// folder picker
this._initFolderMenuList(container);
this._initFolderMenuList(containerId);
// description field
this._initTextField("descriptionField",

View File

@@ -907,8 +907,7 @@ PlacesTreeView.prototype = {
}
else if (nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER ||
nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT) {
if (PlacesUtils.annotations.itemHasAnnotation(itemId,
LMANNO_FEEDURI))
if (PlacesUtils.nodeIsLivemarkContainer(node))
properties.push(this._getAtomFor("livemark"));
}

View File

@@ -128,7 +128,7 @@ placesTransactionsService.prototype = {
// if the item is a livemark container we will not save its children and
// will use createLivemark to undo.
if (PlacesUtils.livemarks.isLivemark(aItemId))
if (PlacesUtils.itemIsLivemark(aItemId))
return new placesRemoveLivemarkTransaction(aItemId);
return new placesRemoveItemTransaction(aItemId);

View File

@@ -95,33 +95,6 @@ const IDLE_TIMELIMIT = 1800000;
// This cap is used only if the user sets a very high expiration time (>4h)
const MAX_REFRESH_TIME = 3600000;
/* We don't have strings, so this is currently not used.
const PLACES_BUNDLE_URI = "chrome://places/locale/places.properties";
function LOG(str) {
dump("*** " + str + "\n");
}
var gStringBundle;
function GetString(name)
{
try {
if (!gStringBundle) {
var bundleService = Cc[SB_CONTRACTID].getService();
bundleService = bundleService.QueryInterface(Ci.nsIStringBundleService);
gStringBundle = bundleService.createBundle(PLACES_BUNDLE_URI);
}
if (gStringBundle)
return gStringBundle.GetStringFromName(name);
} catch (ex) {
LOG("Exception loading string bundle: " + ex.message);
}
return null;
}
*/
function MarkLivemarkLoadFailed(aFolderId) {
var ans = Cc[AS_CONTRACTID].getService(Ci.nsIAnnotationService);
// if it failed before, nothing more to do
@@ -180,35 +153,35 @@ function LivemarkService() {
LivemarkService.prototype = {
get _bms() {
if (!this.__bms)
this.__bms = Cc[BMS_CONTRACTID].getService(Ci.nsINavBookmarksService);
return this.__bms;
var svc = Cc[BMS_CONTRACTID].getService(Ci.nsINavBookmarksService);
this.__defineGetter__("_bms", function() svc);
return this._bms;
},
get _history() {
if (!this.__history)
this.__history = Cc[NH_CONTRACTID].getService(Ci.nsINavHistoryService);
return this.__history;
var svc = Cc[NH_CONTRACTID].getService(Ci.nsINavHistoryService);
this.__defineGetter__("_history", function() svc);
return this._history;
},
get _ans() {
if (!this.__ans)
this.__ans = Cc[AS_CONTRACTID].getService(Ci.nsIAnnotationService);
return this.__ans;
var svc = Cc[AS_CONTRACTID].getService(Ci.nsIAnnotationService);
this.__defineGetter__("_ans", function() svc);
return this._ans;
},
get _ios() {
if (!this.__ios)
this.__ios = Cc[IO_CONTRACTID].getService(Ci.nsIIOService);
return this.__ios;
var svc = Cc[IO_CONTRACTID].getService(Ci.nsIIOService);
this.__defineGetter__("_ios", function() svc);
return this._ios;
},
get _idleService() {
if (!(IS_CONTRACTID in Cc))
return null;
if (!this.__idleService)
this.__idleService = Cc[IS_CONTRACTID].getService(Ci.nsIIdleService);
return this.__idleService;
var svc = Cc[IS_CONTRACTID].getService(Ci.nsIIdleService);
this.__defineGetter__("_idleService", function() svc);
return this._idleService;
},
_updateTimer: null,
@@ -412,7 +385,12 @@ LivemarkService.prototype = {
isLivemark: function LS_isLivemark(aFolderId) {
if (aFolderId < 1)
throw Cr.NS_ERROR_INVALID_ARG;
return this._ans.itemHasAnnotation(aFolderId, LMANNO_FEEDURI);
try {
this._getLivemarkIndex(aFolderId);
return true;
}
catch (ex) {}
return false;
},
_ensureLivemark: function LS__ensureLivemark(aFolderId) {

View File

@@ -420,17 +420,29 @@ var PlacesUtils = {
},
/**
* Determines whether a result node is a remote container registered by the
* livemark service.
* Determines if a container item id is a livemark.
* @param aItemId
* The id of the potential livemark.
* @returns true if the item is a livemark.
*/
itemIsLivemark: function PU_itemIsLivemark(aItemId) {
// If the Livemark service hasn't yet been initialized then
// use the annotations service directly to avoid instanciating
// it on startup. (bug 398300)
if (this.__lookupGetter__("livemarks"))
return this.annotations.itemHasAnnotation(aItemId, LMANNO_FEEDURI);
// If the livemark service has already been instanciated, use it.
return this.livemarks.isLivemark(aItemId);
},
/**
* Determines whether a result node is a livemark container.
* @param aNode
* A result Node
* @returns true if the node is a livemark container item
*/
nodeIsLivemarkContainer: function PU_nodeIsLivemarkContainer(aNode) {
// Use the annotations service directly to avoid instantiating
// the Livemark service on startup. (bug 398300)
return this.nodeIsFolder(aNode) &&
this.annotations.itemHasAnnotation(aNode.itemId, LMANNO_FEEDURI);
return this.nodeIsFolder(aNode) && this.itemIsLivemark(aNode.itemId);
},
/**
@@ -955,13 +967,13 @@ var PlacesUtils = {
// filter the ids list
return bmkIds.filter(function(aID) {
var parent = this.bookmarks.getFolderIdForItem(aID);
var parentId = this.bookmarks.getFolderIdForItem(aID);
// Livemark child
if (this.annotations.itemHasAnnotation(parent, LMANNO_FEEDURI))
if (this.itemIsLivemark(parentId))
return false;
var grandparent = this.bookmarks.getFolderIdForItem(parent);
var grandparentId = this.bookmarks.getFolderIdForItem(parentId);
// item under a tag container
if (grandparent == this.tagsFolderId)
if (grandparentId == this.tagsFolderId)
return false;
return true;
}, this);
@@ -977,18 +989,21 @@ var PlacesUtils = {
for (var i = 0; i < bmkIds.length; i++) {
// Find the first folder which isn't a tag container
var bk = bmkIds[i];
var parent = this.bookmarks.getFolderIdForItem(bk);
if (parent == this.unfiledBookmarksFolderId)
var parentId = this.bookmarks.getFolderIdForItem(bk);
if (parentId == this.unfiledBookmarksFolderId)
return bk;
var grandparent = this.bookmarks.getFolderIdForItem(parent);
if (grandparent != this.tagsFolderId &&
!this.annotations.itemHasAnnotation(parent, LMANNO_FEEDURI))
var grandparentId = this.bookmarks.getFolderIdForItem(parentId);
if (grandparentId != this.tagsFolderId &&
!this.itemIsLivemark(parentId))
return bk;
}
return -1;
},
/**
* TODO: this should use the livemark service's cache of folder ids (bug 492884).
*/
getMostRecentFolderForFeedURI:
function PU_getMostRecentFolderForFeedURI(aURI) {
var feedSpec = aURI.spec