| 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..1acbd838805d9b7241982eedab9bf4744a3a55cb 100644
|
| --- a/chrome/browser/bookmarks/bookmark_model.cc
|
| +++ b/chrome/browser/bookmarks/bookmark_model.cc
|
| @@ -22,11 +22,14 @@
|
| #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/browser_thread.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"
|
| @@ -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(), task_runner.get());
|
| + store_->LoadBookmarks(this, CreateLoadDetails());
|
| }
|
|
|
| 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,55 @@ 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(
|
| + 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::ExtractBookmarkNodePairs(
|
| + 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);
|
| +}
|
| +
|
| +bool BookmarkModel::PostTask(const tracked_objects::Location& from_here,
|
| + const base::Closure& task) {
|
| + return content::BrowserThread::PostTask(
|
| + content::BrowserThread::UI, from_here, task);
|
| }
|
|
|