Commit f05f85bf authored by Aidan's avatar Aidan Committed by Commit Bot

Add histogram to collect number of bookmarks

When profile is loaded, parse the bookmark tree to find the total count.
Adds and tests new bookmark stat, which saves to a new histogram. The
collection method is run in the profile manager class, after it has been
initialized.

Bug: 245392
Change-Id: I6a72549e2cbc197e92de4edbcf7b362212ff2c39
Reviewed-on: https://chromium-review.googlesource.com/1238901Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Ilya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594540}
parent 621dca55
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/json/json_string_value_serializer.h" #include "base/json/json_string_value_serializer.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/bookmarks/browser/bookmark_codec.h" #include "components/bookmarks/browser/bookmark_codec.h"
...@@ -115,6 +116,10 @@ void LoadBookmarks(const base::FilePath& path, BookmarkLoadDetails* details) { ...@@ -115,6 +116,10 @@ void LoadBookmarks(const base::FilePath& path, BookmarkLoadDetails* details) {
} }
details->CreateUrlIndex(); details->CreateUrlIndex();
UMA_HISTOGRAM_COUNTS_100000(
"Bookmarks.Count.OnProfileLoad",
base::saturated_cast<int>(details->url_index()->UrlCount()));
} }
// BookmarkLoadDetails --------------------------------------------------------- // BookmarkLoadDetails ---------------------------------------------------------
......
...@@ -71,11 +71,16 @@ void UrlIndex::GetNodesByUrl(const GURL& url, ...@@ -71,11 +71,16 @@ void UrlIndex::GetNodesByUrl(const GURL& url,
} }
} }
bool UrlIndex::HasBookmarks() { bool UrlIndex::HasBookmarks() const {
base::AutoLock url_lock(url_lock_); base::AutoLock url_lock(url_lock_);
return !nodes_ordered_by_url_set_.empty(); return !nodes_ordered_by_url_set_.empty();
} }
size_t UrlIndex::UrlCount() const {
base::AutoLock url_lock(url_lock_);
return nodes_ordered_by_url_set_.size();
}
bool UrlIndex::IsBookmarked(const GURL& url) { bool UrlIndex::IsBookmarked(const GURL& url) {
base::AutoLock url_lock(url_lock_); base::AutoLock url_lock(url_lock_);
return IsBookmarkedNoLock(url); return IsBookmarkedNoLock(url);
......
...@@ -56,7 +56,10 @@ class UrlIndex : public HistoryBookmarkModel { ...@@ -56,7 +56,10 @@ class UrlIndex : public HistoryBookmarkModel {
void GetNodesByUrl(const GURL& url, std::vector<const BookmarkNode*>* nodes); void GetNodesByUrl(const GURL& url, std::vector<const BookmarkNode*>* nodes);
// Returns true if there is at least one bookmark. // Returns true if there is at least one bookmark.
bool HasBookmarks(); bool HasBookmarks() const;
// Returns the number of URL bookmarks stored.
size_t UrlCount() const;
// HistoryBookmarkModel: // HistoryBookmarkModel:
bool IsBookmarked(const GURL& url) override; bool IsBookmarked(const GURL& url) override;
...@@ -88,7 +91,7 @@ class UrlIndex : public HistoryBookmarkModel { ...@@ -88,7 +91,7 @@ class UrlIndex : public HistoryBookmarkModel {
// such, be sure and wrap all usage of it around |url_lock_|. // such, be sure and wrap all usage of it around |url_lock_|.
using NodesOrderedByUrlSet = std::multiset<BookmarkNode*, NodeUrlComparator>; using NodesOrderedByUrlSet = std::multiset<BookmarkNode*, NodeUrlComparator>;
NodesOrderedByUrlSet nodes_ordered_by_url_set_; NodesOrderedByUrlSet nodes_ordered_by_url_set_;
base::Lock url_lock_; mutable base::Lock url_lock_;
DISALLOW_COPY_AND_ASSIGN(UrlIndex); DISALLOW_COPY_AND_ASSIGN(UrlIndex);
}; };
......
...@@ -10797,6 +10797,19 @@ uploading your change for review. ...@@ -10797,6 +10797,19 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Bookmarks.Count.OnProfileLoad" units="bookmarks"
expires_after="2019-03-24">
<owner>supertri@chromium.org</owner>
<owner>isherman@chromium.org</owner>
<owner>aidanday@google.com</owner>
<summary>
The total number of bookmarks a user has saved. Recorded when a profile is
opened - precisely, when bookmarks are loaded into storage from disk. The
count includes all bookmarks both in the &quot;Bookmarks Bar&quot; and also
under &quot;Other Bookmarks&quot;.
</summary>
</histogram>
<histogram name="Bookmarks.EntryPoint" enum="BookmarksEntryPoint"> <histogram name="Bookmarks.EntryPoint" enum="BookmarksEntryPoint">
<owner>ianwen@chromium.org</owner> <owner>ianwen@chromium.org</owner>
<summary>How users add a new bookmark.</summary> <summary>How users add a new bookmark.</summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment