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 itemId = target._resultNode.itemId;
var siteURIString = ""; var siteURIString = "";
if (itemId != -1 && PlacesUtils.livemarks.isLivemark(itemId)) { if (itemId != -1 && PlacesUtils.itemIsLivemark(itemId)) {
var siteURI = PlacesUtils.livemarks.getSiteURI(itemId); var siteURI = PlacesUtils.livemarks.getSiteURI(itemId);
if (siteURI) if (siteURI)
siteURIString = siteURI.spec; siteURIString = siteURI.spec;

View File

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

View File

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

View File

@@ -907,8 +907,7 @@ PlacesTreeView.prototype = {
} }
else if (nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER || else if (nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER ||
nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT) { nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT) {
if (PlacesUtils.annotations.itemHasAnnotation(itemId, if (PlacesUtils.nodeIsLivemarkContainer(node))
LMANNO_FEEDURI))
properties.push(this._getAtomFor("livemark")); 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 // if the item is a livemark container we will not save its children and
// will use createLivemark to undo. // will use createLivemark to undo.
if (PlacesUtils.livemarks.isLivemark(aItemId)) if (PlacesUtils.itemIsLivemark(aItemId))
return new placesRemoveLivemarkTransaction(aItemId); return new placesRemoveLivemarkTransaction(aItemId);
return new placesRemoveItemTransaction(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) // This cap is used only if the user sets a very high expiration time (>4h)
const MAX_REFRESH_TIME = 3600000; 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) { function MarkLivemarkLoadFailed(aFolderId) {
var ans = Cc[AS_CONTRACTID].getService(Ci.nsIAnnotationService); var ans = Cc[AS_CONTRACTID].getService(Ci.nsIAnnotationService);
// if it failed before, nothing more to do // if it failed before, nothing more to do
@@ -180,35 +153,35 @@ function LivemarkService() {
LivemarkService.prototype = { LivemarkService.prototype = {
get _bms() { get _bms() {
if (!this.__bms) var svc = Cc[BMS_CONTRACTID].getService(Ci.nsINavBookmarksService);
this.__bms = Cc[BMS_CONTRACTID].getService(Ci.nsINavBookmarksService); this.__defineGetter__("_bms", function() svc);
return this.__bms; return this._bms;
}, },
get _history() { get _history() {
if (!this.__history) var svc = Cc[NH_CONTRACTID].getService(Ci.nsINavHistoryService);
this.__history = Cc[NH_CONTRACTID].getService(Ci.nsINavHistoryService); this.__defineGetter__("_history", function() svc);
return this.__history; return this._history;
}, },
get _ans() { get _ans() {
if (!this.__ans) var svc = Cc[AS_CONTRACTID].getService(Ci.nsIAnnotationService);
this.__ans = Cc[AS_CONTRACTID].getService(Ci.nsIAnnotationService); this.__defineGetter__("_ans", function() svc);
return this.__ans; return this._ans;
}, },
get _ios() { get _ios() {
if (!this.__ios) var svc = Cc[IO_CONTRACTID].getService(Ci.nsIIOService);
this.__ios = Cc[IO_CONTRACTID].getService(Ci.nsIIOService); this.__defineGetter__("_ios", function() svc);
return this.__ios; return this._ios;
}, },
get _idleService() { get _idleService() {
if (!(IS_CONTRACTID in Cc)) if (!(IS_CONTRACTID in Cc))
return null; return null;
if (!this.__idleService) var svc = Cc[IS_CONTRACTID].getService(Ci.nsIIdleService);
this.__idleService = Cc[IS_CONTRACTID].getService(Ci.nsIIdleService); this.__defineGetter__("_idleService", function() svc);
return this.__idleService; return this._idleService;
}, },
_updateTimer: null, _updateTimer: null,
@@ -412,7 +385,12 @@ LivemarkService.prototype = {
isLivemark: function LS_isLivemark(aFolderId) { isLivemark: function LS_isLivemark(aFolderId) {
if (aFolderId < 1) if (aFolderId < 1)
throw Cr.NS_ERROR_INVALID_ARG; 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) { _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 * Determines if a container item id is a livemark.
* livemark service. * @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 * @param aNode
* A result Node * A result Node
* @returns true if the node is a livemark container item * @returns true if the node is a livemark container item
*/ */
nodeIsLivemarkContainer: function PU_nodeIsLivemarkContainer(aNode) { nodeIsLivemarkContainer: function PU_nodeIsLivemarkContainer(aNode) {
// Use the annotations service directly to avoid instantiating return this.nodeIsFolder(aNode) && this.itemIsLivemark(aNode.itemId);
// the Livemark service on startup. (bug 398300)
return this.nodeIsFolder(aNode) &&
this.annotations.itemHasAnnotation(aNode.itemId, LMANNO_FEEDURI);
}, },
/** /**
@@ -955,13 +967,13 @@ var PlacesUtils = {
// filter the ids list // filter the ids list
return bmkIds.filter(function(aID) { return bmkIds.filter(function(aID) {
var parent = this.bookmarks.getFolderIdForItem(aID); var parentId = this.bookmarks.getFolderIdForItem(aID);
// Livemark child // Livemark child
if (this.annotations.itemHasAnnotation(parent, LMANNO_FEEDURI)) if (this.itemIsLivemark(parentId))
return false; return false;
var grandparent = this.bookmarks.getFolderIdForItem(parent); var grandparentId = this.bookmarks.getFolderIdForItem(parentId);
// item under a tag container // item under a tag container
if (grandparent == this.tagsFolderId) if (grandparentId == this.tagsFolderId)
return false; return false;
return true; return true;
}, this); }, this);
@@ -977,18 +989,21 @@ var PlacesUtils = {
for (var i = 0; i < bmkIds.length; i++) { for (var i = 0; i < bmkIds.length; i++) {
// Find the first folder which isn't a tag container // Find the first folder which isn't a tag container
var bk = bmkIds[i]; var bk = bmkIds[i];
var parent = this.bookmarks.getFolderIdForItem(bk); var parentId = this.bookmarks.getFolderIdForItem(bk);
if (parent == this.unfiledBookmarksFolderId) if (parentId == this.unfiledBookmarksFolderId)
return bk; return bk;
var grandparent = this.bookmarks.getFolderIdForItem(parent); var grandparentId = this.bookmarks.getFolderIdForItem(parentId);
if (grandparent != this.tagsFolderId && if (grandparentId != this.tagsFolderId &&
!this.annotations.itemHasAnnotation(parent, LMANNO_FEEDURI)) !this.itemIsLivemark(parentId))
return bk; return bk;
} }
return -1; return -1;
}, },
/**
* TODO: this should use the livemark service's cache of folder ids (bug 492884).
*/
getMostRecentFolderForFeedURI: getMostRecentFolderForFeedURI:
function PU_getMostRecentFolderForFeedURI(aURI) { function PU_getMostRecentFolderForFeedURI(aURI) {
var feedSpec = aURI.spec var feedSpec = aURI.spec