Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Unified Diff: chrome/browser/bookmarks/bookmark_model.cc

Issue 242693003: Introduce BookmarkClient interface to abstract embedder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing reviewer comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/bookmarks/bookmark_model.cc
diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc
index cdd91f5a973a1d0d8e0ba2b28e3f0da935a5f4b3..5f63e645f2a8e5bd053a381e0f6f0653b0462ba2 100644
--- a/chrome/browser/bookmarks/bookmark_model.cc
+++ b/chrome/browser/bookmarks/bookmark_model.cc
@@ -22,11 +22,13 @@
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
+#include "chrome/browser/history/url_database.h"
#include "chrome/browser/profiles/profile.h"
#include "components/bookmarks/core/browser/bookmark_title_match.h"
#include "components/favicon_base/favicon_types.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
+#include "content/public/browser/user_metrics.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/favicon_size.h"
@@ -108,7 +110,8 @@ void BookmarkModel::Shutdown() {
}
void BookmarkModel::Load(
- const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
+ const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
+ const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner) {
if (store_.get()) {
// If the store is non-null, it means Load was already invoked. Load should
// only be invoked once.
@@ -125,8 +128,8 @@ void BookmarkModel::Load(
content::Source<Profile>(profile_));
// Load the bookmarks. BookmarkStorage notifies us when done.
- store_ = new BookmarkStorage(profile_, this, task_runner.get());
- store_->LoadBookmarks(CreateLoadDetails());
+ store_ = new BookmarkStorage(this, profile_->GetPath(), io_task_runner.get());
+ store_->LoadBookmarks(CreateLoadDetails(), ui_task_runner);
}
const BookmarkNode* BookmarkModel::GetParentForNewNodes() {
@@ -621,7 +624,7 @@ void BookmarkModel::GetBookmarksWithTitlesMatching(
if (!loaded_)
return;
- index_->GetBookmarksWithTitlesMatching(text, max_count, matches);
+ index_->GetBookmarksWithTitlesMatching(this, text, max_count, matches);
}
void BookmarkModel::ClearStore() {
@@ -887,19 +890,15 @@ void BookmarkModel::LoadFavicon(BookmarkNode* node) {
return;
DCHECK(node->url().is_valid());
- FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
- profile_, Profile::EXPLICIT_ACCESS);
- if (!favicon_service)
- return;
- base::CancelableTaskTracker::TaskId taskId =
- favicon_service->GetFaviconImageForURL(
- FaviconService::FaviconForURLParams(
- node->url(), favicon_base::FAVICON, gfx::kFaviconSize),
- base::Bind(&BookmarkModel::OnFaviconDataAvailable,
- base::Unretained(this),
- node),
- &cancelable_task_tracker_);
- node->set_favicon_load_task_id(taskId);
+ base::CancelableTaskTracker::TaskId taskId = GetFaviconImageForURL(
+ node->url(),
+ favicon_base::FAVICON,
+ gfx::kFaviconSize,
+ base::Bind(
+ &BookmarkModel::OnFaviconDataAvailable, base::Unretained(this), node),
+ &cancelable_task_tracker_);
+ if (taskId != base::CancelableTaskTracker::kBadTaskId)
+ node->set_favicon_load_task_id(taskId);
}
void BookmarkModel::FaviconLoaded(const BookmarkNode* node) {
@@ -963,7 +962,49 @@ BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() {
CreatePermanentNode(BookmarkNode::OTHER_NODE);
BookmarkPermanentNode* mobile_node =
CreatePermanentNode(BookmarkNode::MOBILE);
- return new BookmarkLoadDetails(bb_node, other_node, mobile_node,
- new BookmarkIndex(profile_),
- next_node_id_);
+ return new BookmarkLoadDetails(
+ bb_node, other_node, mobile_node, new BookmarkIndex(), next_node_id_);
+}
+
+base::CancelableTaskTracker::TaskId BookmarkModel::GetFaviconImageForURL(
sky 2014/04/18 17:05:04 Style guide says declaration order and definition
sdefresne 2014/04/18 22:25:49 Done.
+ const GURL& page_url,
+ int icon_types,
+ int desired_size_in_dip,
+ const FaviconImageCallback& callback,
+ base::CancelableTaskTracker* tracker) {
+ FaviconService* favicon_service =
+ FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ if (!favicon_service)
+ return base::CancelableTaskTracker::kBadTaskId;
+ return favicon_service->GetFaviconImageForURL(
+ FaviconService::FaviconForURLParams(
+ page_url, icon_types, desired_size_in_dip),
+ callback,
+ tracker);
+}
+
+void BookmarkModel::GetTypedCountForNodes(
+ const NodeSet& nodes,
+ NodeTypedCountPairs* node_typed_count_pairs) {
+ HistoryService* history_service =
+ HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
+ history::URLDatabase* url_db =
+ history_service ? history_service->InMemoryDatabase() : NULL;
+ for (NodeSet::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
+ int typed_count = 0;
+
+ // If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but
+ // it guarantees to contain those with |typed_count| > 0. Thus, if we cannot
+ // fetch the URLRow, it is safe to assume that its |typed_count| is 0.
+ history::URLRow url;
+ if (url_db && url_db->GetRowForURL((*i)->url(), &url))
+ typed_count = url.typed_count();
+
+ NodeTypedCountPair pair(*i, typed_count);
+ node_typed_count_pairs->push_back(pair);
+ }
+}
+
+void BookmarkModel::RecordAction(const base::UserMetricsAction& action) {
+ content::RecordAction(action);
}

Powered by Google App Engine
This is Rietveld 408576698