From 07907def97317efe303b00f4f1f22455a1fbc9ef Mon Sep 17 00:00:00 2001 From: "pete@mozdevgroup.com" Date: Tue, 27 Nov 2007 09:58:52 -0800 Subject: [PATCH] b=393881 update metrics extension to use places r=Jan.Varga Landing patch so metrics extension works on trunk. --pete --- extensions/metrics/install.rdf | 2 +- extensions/metrics/src/nsProfileCollector.cpp | 189 ++---------------- extensions/metrics/src/nsProfileCollector.h | 10 - .../metrics/src/nsUICommandCollector.cpp | 95 --------- 4 files changed, 13 insertions(+), 283 deletions(-) diff --git a/extensions/metrics/install.rdf b/extensions/metrics/install.rdf index c04ac7a9375e..bc78950bfee3 100644 --- a/extensions/metrics/install.rdf +++ b/extensions/metrics/install.rdf @@ -12,7 +12,7 @@ {ec8030f7-c20a-464f-9b0e-13a3a9e97384} - 1.5.0 + 3.0a1 @FIREFOX_VERSION@ diff --git a/extensions/metrics/src/nsProfileCollector.cpp b/extensions/metrics/src/nsProfileCollector.cpp index 26b36bce1b95..abec3a25ea52 100644 --- a/extensions/metrics/src/nsProfileCollector.cpp +++ b/extensions/metrics/src/nsProfileCollector.cpp @@ -54,15 +54,10 @@ #include "nsDirectoryServiceUtils.h" #include "nsAutoPtr.h" #include "nsTArray.h" -#ifdef MOZ_PLACES_BOOKMARKS #include "nsINavBookmarksService.h" #include "nsINavHistoryService.h" #include "nsILivemarkService.h" #include "nsToolkitCompsCID.h" -#else -#include "nsIBookmarksService.h" -#include "nsIRDFContainer.h" -#endif // We need to suppress inclusion of nsString.h #define nsString_h___ @@ -130,33 +125,13 @@ class nsProfileCollector::BookmarkCounter // Fills in |count| with the number of children of each BookmarkType. // If |deep| is true, then the count will include children of all subfolders. -#ifdef MOZ_PLACES_BOOKMARKS void CountChildren(PRInt64 root, PRBool deep, nsTArray &count); -#else - void CountChildren(nsIRDFResource *root, - PRBool deep, nsTArray &count); -#endif private: -#ifdef MOZ_PLACES_BOOKMARKS void CountRecursive(nsINavHistoryContainerResultNode *root, PRBool deep, nsTArray &count); -#else - void CountRecursive(nsIRDFResource *root, PRBool deep, - nsTArray &count); -#endif -#ifdef MOZ_PLACES_BOOKMARKS nsCOMPtr mLivemarkService; -#else - nsCOMPtr mDataSource; - - nsCOMPtr mRDFType; - nsCOMPtr mNCBookmark; - nsCOMPtr mNCFolder; - nsCOMPtr mNCLivemark; - nsCOMPtr mNCSeparator; -#endif }; nsProfileCollector::nsProfileCollector() @@ -442,7 +417,6 @@ nsProfileCollector::LogBookmarks(nsIMetricsEventItem *profile) getter_AddRefs(bookmarksItem)); NS_ENSURE_STATE(bookmarksItem); -#ifdef MOZ_PLACES_BOOKMARKS nsCOMPtr bmSvc = do_GetService(NS_NAVBOOKMARKSSERVICE_CONTRACTID); NS_ENSURE_STATE(bmSvc); @@ -470,41 +444,6 @@ nsProfileCollector::LogBookmarks(nsIMetricsEventItem *profile) LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("toolbar"), &counter, root, PR_FALSE); -#else - nsCOMPtr bmSvc = - do_GetService(NS_BOOKMARKS_SERVICE_CONTRACTID); - NS_ENSURE_STATE(bmSvc); - - // This just ensures that the bookmarks are loaded, it doesn't - // read them again if they've already been read. - PRBool loaded; - bmSvc->ReadBookmarks(&loaded); - - nsCOMPtr rdfSvc = - do_GetService("@mozilla.org/rdf/rdf-service;1"); - NS_ENSURE_STATE(rdfSvc); - - nsCOMPtr root; - rdfSvc->GetResource(NS_LITERAL_CSTRING("NC:BookmarksRoot"), - getter_AddRefs(root)); - NS_ENSURE_STATE(root); - - BookmarkCounter counter; - rv = counter.Init(); - NS_ENSURE_SUCCESS(rv, rv); - - LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("full-tree"), - &counter, root, PR_TRUE); - LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("root"), - &counter, root, PR_FALSE); - - bmSvc->GetBookmarksToolbarFolder(getter_AddRefs(root)); - if (root) { - LogBookmarkLocation(bookmarksItem, NS_LITERAL_CSTRING("toolbar"), - &counter, root, PR_FALSE); - } -#endif - rv = profile->AppendChild(bookmarksItem); NS_ENSURE_SUCCESS(rv, rv); @@ -515,11 +454,7 @@ void nsProfileCollector::LogBookmarkLocation(nsIMetricsEventItem *bookmarksItem, const nsACString &location, BookmarkCounter *counter, -#ifdef MOZ_PLACES_BOOKMARKS PRInt64 root, -#else - nsIRDFResource *root, -#endif PRBool deep) { nsTArray count; @@ -749,8 +684,6 @@ nsProfileCollector::ExtensionEnumerator::CreateExtensionItem( return item; } - -#ifdef MOZ_PLACES_BOOKMARKS nsresult nsProfileCollector::BookmarkCounter::Init() { @@ -790,7 +723,7 @@ nsProfileCollector::BookmarkCounter::CountChildren(PRInt64 root, PRBool deep, return; } - const PRUint32 groupMode = nsINavHistoryQueryOptions::GROUP_BY_FOLDER; + const PRUint16 groupMode = nsINavHistoryQueryOptions::GROUP_BY_FOLDER; options->SetGroupingMode(&groupMode, 1); nsCOMPtr result; @@ -799,7 +732,7 @@ nsProfileCollector::BookmarkCounter::CountChildren(PRInt64 root, PRBool deep, return; } - nsCOMPtr rootNode; + nsCOMPtr rootNode; result->GetRoot(getter_AddRefs(rootNode)); if (!rootNode) { return; @@ -827,17 +760,18 @@ nsProfileCollector::BookmarkCounter::CountRecursive( PRUint32 type = 0; child->GetType(&type); - if (type == nsINavHistoryResultNode::RESULT_TYPE_URI) { + if (type == nsINavHistoryResultNode::RESULT_TYPE_URI) + { ++count[ITEM]; - } else if (type == nsINavHistoryResultNode::RESULT_TYPE_FOLDER) { - nsCOMPtr folder = - do_QueryInterface(child); - if (!folder) { - continue; - } + } + else if (type == nsINavHistoryResultNode::RESULT_TYPE_FOLDER) + { + nsCOMPtr folder = do_QueryInterface(child); - PRInt64 folderID = 0; - folder->GetFolderId(&folderID); + if (!folder) continue; + + PRInt64 folderID; + child->GetItemId(&folderID); PRBool isLivemark = PR_FALSE; mLivemarkService->IsLivemark(folderID, &isLivemark); @@ -856,102 +790,3 @@ nsProfileCollector::BookmarkCounter::CountRecursive( root->SetContainerOpen(PR_FALSE); } - -#else - -nsresult -nsProfileCollector::BookmarkCounter::Init() -{ - mDataSource = do_GetService(NS_BOOKMARKS_DATASOURCE_CONTRACTID); - NS_ENSURE_STATE(mDataSource); - - nsCOMPtr rdfSvc = - do_GetService("@mozilla.org/rdf/rdf-service;1"); - NS_ENSURE_STATE(rdfSvc); - - rdfSvc->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"), - getter_AddRefs(mRDFType)); - NS_ENSURE_STATE(mRDFType); - - rdfSvc->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Bookmark"), - getter_AddRefs(mNCBookmark)); - NS_ENSURE_STATE(mNCBookmark); - - rdfSvc->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Folder"), - getter_AddRefs(mNCFolder)); - NS_ENSURE_STATE(mNCFolder); - - rdfSvc->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Livemark"), - getter_AddRefs(mNCLivemark)); - NS_ENSURE_STATE(mNCLivemark); - - rdfSvc->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "BookmarkSeparator"), - getter_AddRefs(mNCSeparator)); - NS_ENSURE_STATE(mNCSeparator); - - return NS_OK; -} - -void -nsProfileCollector::BookmarkCounter::CountChildren(nsIRDFResource *root, - PRBool deep, - nsTArray &count) -{ - count.SetLength(kLastBookmarkType); - for (PRUint32 i = 0; i < kLastBookmarkType; ++i) { - count[i] = 0; - } - CountRecursive(root, deep, count); -} - -void -nsProfileCollector::BookmarkCounter::CountRecursive(nsIRDFResource *root, - PRBool deep, - nsTArray &count) -{ - nsCOMPtr container = - do_CreateInstance("@mozilla.org/rdf/container;1"); - if (!container) { - return; - } - - nsresult rv = container->Init(mDataSource, root); - if (NS_FAILED(rv)) { - return; - } - - nsCOMPtr elements; - container->GetElements(getter_AddRefs(elements)); - if (!elements) { - return; - } - - nsCOMPtr item; - while (NS_SUCCEEDED(elements->GetNext(getter_AddRefs(item)))) { - nsCOMPtr child = do_QueryInterface(item); - if (!child) { - continue; - } - - // Figure out whether the child is a folder - nsCOMPtr typeNode; - mDataSource->GetTarget(child, mRDFType, PR_TRUE, getter_AddRefs(typeNode)); - if (!typeNode) { - continue; - } - - if (typeNode == mNCBookmark) { - ++count[ITEM]; - } else if (typeNode == mNCFolder) { - ++count[FOLDER]; - if (deep) { - CountRecursive(child, deep, count); - } - } else if (typeNode == mNCLivemark) { - ++count[LIVEMARK]; - } else if (typeNode == mNCSeparator) { - ++count[SEPARATOR]; - } - } -} -#endif diff --git a/extensions/metrics/src/nsProfileCollector.h b/extensions/metrics/src/nsProfileCollector.h index 0b229cb5abbd..1623578bab16 100644 --- a/extensions/metrics/src/nsProfileCollector.h +++ b/extensions/metrics/src/nsProfileCollector.h @@ -44,9 +44,6 @@ class nsISupports; class nsIMetricsEventItem; class nsIPropertyBag; -#ifndef MOZ_PLACES_BOOKMARKS -class nsIRDFResource; -#endif // This file defines the profile collector class, which generates // a profile event at application startup. The profile event logs @@ -77,17 +74,10 @@ class nsProfileCollector : public nsIMetricsCollector nsresult LogDisplay(nsIMetricsEventItem *profile); nsresult LogBookmarks(nsIMetricsEventItem *profile); -#ifdef MOZ_PLACES_BOOKMARKS void LogBookmarkLocation(nsIMetricsEventItem *bookmarksItem, const nsACString &location, BookmarkCounter *counter, PRInt64 root, PRBool deep); -#else - void LogBookmarkLocation(nsIMetricsEventItem *bookmarksItem, - const nsACString &location, - BookmarkCounter *counter, - nsIRDFResource *root, PRBool deep); -#endif // Track whether we've logged the profile yet this session. PRBool mLoggedProfile; diff --git a/extensions/metrics/src/nsUICommandCollector.cpp b/extensions/metrics/src/nsUICommandCollector.cpp index db8c89bde55a..7fc14019a6ad 100644 --- a/extensions/metrics/src/nsUICommandCollector.cpp +++ b/extensions/metrics/src/nsUICommandCollector.cpp @@ -49,14 +49,6 @@ #include "nsIDOMWindow.h" #include "nsDataHashtable.h" #include "nsMemory.h" -#ifndef MOZ_PLACES_BOOKMARKS -#include "nsIRDFService.h" -#include "nsIRDFResource.h" -#include "nsIRDFContainer.h" -#include "nsIBookmarksService.h" -#include "nsIArray.h" -#include "nsComponentManagerUtils.h" -#endif const nsUICommandCollector::EventHandler nsUICommandCollector::kEvents[] = { { "command", &nsUICommandCollector::HandleCommandEvent }, @@ -473,94 +465,7 @@ nsresult nsUICommandCollector::LogBookmarkInfo(const nsString& id, nsIMetricsEventItem* parentItem) { -#ifdef MOZ_PLACES_BOOKMARKS // TODO: write me! // see bug #356606 return NS_OK; - -#else - - // First check whether this is an anonymous RDF id. - // If it's not, we know it's not a bookmark id at all. - if (!StringHead(id, strlen("rdf:")).Equals(NS_LITERAL_STRING("rdf:"))) { - return NS_OK; - } - - nsCOMPtr rdfSvc = - do_GetService("@mozilla.org/rdf/rdf-service;1"); - NS_ENSURE_STATE(rdfSvc); - - nsCOMPtr targetResource; - rdfSvc->GetUnicodeResource(id, getter_AddRefs(targetResource)); - NS_ENSURE_STATE(targetResource); - - nsCOMPtr bmProps; - nsMetricsUtils::NewPropertyBag(getter_AddRefs(bmProps)); - NS_ENSURE_STATE(bmProps); - - nsCOMPtr bmSvc = - do_GetService(NS_BOOKMARKS_SERVICE_CONTRACTID); - NS_ENSURE_STATE(bmSvc); - - nsCOMPtr parentChain; - bmSvc->GetParentChain(targetResource, getter_AddRefs(parentChain)); - NS_ENSURE_STATE(parentChain); - - PRUint32 depth = 0; - parentChain->GetLength(&depth); - bmProps->SetPropertyAsInt32(NS_LITERAL_STRING("depth"), depth); - if (depth == 0) { - // Hm, an event on the bookmarks root? Not much to log in this case. - return NS_OK; - } - - nsCOMPtr bmDS = - do_GetService(NS_BOOKMARKS_DATASOURCE_CONTRACTID); - NS_ENSURE_STATE(bmDS); - - // Find the bookmark's position in its parent folder. - // do_QueryElementAt() isn't a frozen export :-( - nsCOMPtr parent; - parentChain->QueryElementAt(depth - 1, NS_GET_IID(nsIRDFResource), - getter_AddRefs(parent)); - NS_ENSURE_STATE(parent); - - nsCOMPtr container = - do_CreateInstance("@mozilla.org/rdf/container;1"); - NS_ENSURE_STATE(container); - - nsresult rv = container->Init(bmDS, parent); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 pos; - rv = container->IndexOf(targetResource, &pos); - NS_ENSURE_SUCCESS(rv, rv); - if (pos == -1) { - MS_LOG(("Bookmark not contained in its parent?")); - } else { - bmProps->SetPropertyAsInt32(NS_LITERAL_STRING("pos"), pos); - } - - // Determine whether the bookmark is under the toolbar folder - PRBool isToolbarBM = PR_FALSE; - nsCOMPtr toolbarFolder; - bmSvc->GetBookmarksToolbarFolder(getter_AddRefs(toolbarFolder)); - if (toolbarFolder) { - // Since the user can designate any folder as the toolbar folder, - // we must walk the entire parent chain looking for it. - for (PRUint32 i = 0; i < depth; ++i) { - nsCOMPtr item; - parentChain->QueryElementAt(i, NS_GET_IID(nsIRDFResource), - getter_AddRefs(item)); - if (toolbarFolder == item) { - isToolbarBM = PR_TRUE; - break; - } - } - } - bmProps->SetPropertyAsBool(NS_LITERAL_STRING("toolbar"), isToolbarBM); - - return nsMetricsUtils::AddChildItem(parentItem, - NS_LITERAL_STRING("bookmark"), bmProps); -#endif // MOZ_PLACES_BOOKMARKS }