BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / bookmarks / chrome_bookmark_client.cc
blob068aa2c6ea77def93dac572685a7001432b82752
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
7 #include "base/logging.h"
8 #include "chrome/browser/favicon/favicon_service_factory.h"
9 #include "chrome/browser/history/history_service_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/bookmarks/browser/bookmark_node.h"
12 #include "components/bookmarks/browser/bookmark_storage.h"
13 #include "components/bookmarks/managed/managed_bookmark_service.h"
14 #include "components/bookmarks/managed/managed_bookmark_util.h"
15 #include "components/favicon/core/favicon_util.h"
16 #include "components/history/core/browser/history_service.h"
17 #include "components/history/core/browser/url_database.h"
18 #include "content/public/browser/user_metrics.h"
19 #include "ui/base/l10n/l10n_util.h"
21 ChromeBookmarkClient::ChromeBookmarkClient(
22 Profile* profile,
23 bookmarks::ManagedBookmarkService* managed_bookmark_service)
24 : profile_(profile), managed_bookmark_service_(managed_bookmark_service) {}
26 ChromeBookmarkClient::~ChromeBookmarkClient() {
29 void ChromeBookmarkClient::Init(bookmarks::BookmarkModel* model) {
30 if (managed_bookmark_service_)
31 managed_bookmark_service_->BookmarkModelCreated(model);
34 void ChromeBookmarkClient::Shutdown() {
35 managed_bookmark_service_ = nullptr;
36 BookmarkClient::Shutdown();
39 bool ChromeBookmarkClient::PreferTouchIcon() {
40 return false;
43 base::CancelableTaskTracker::TaskId
44 ChromeBookmarkClient::GetFaviconImageForPageURL(
45 const GURL& page_url,
46 favicon_base::IconType type,
47 const favicon_base::FaviconImageCallback& callback,
48 base::CancelableTaskTracker* tracker) {
49 return favicon::GetFaviconImageForPageURL(
50 FaviconServiceFactory::GetForProfile(profile_,
51 ServiceAccessType::EXPLICIT_ACCESS),
52 page_url, type, callback, tracker);
55 bool ChromeBookmarkClient::SupportsTypedCountForNodes() {
56 return true;
59 void ChromeBookmarkClient::GetTypedCountForNodes(
60 const NodeSet& nodes,
61 NodeTypedCountPairs* node_typed_count_pairs) {
62 history::HistoryService* history_service =
63 HistoryServiceFactory::GetForProfileIfExists(
64 profile_, ServiceAccessType::EXPLICIT_ACCESS);
65 history::URLDatabase* url_db =
66 history_service ? history_service->InMemoryDatabase() : nullptr;
67 for (NodeSet::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
68 int typed_count = 0;
70 // If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but
71 // it guarantees to contain those with |typed_count| > 0. Thus, if we cannot
72 // fetch the URLRow, it is safe to assume that its |typed_count| is 0.
73 history::URLRow url;
74 if (url_db && url_db->GetRowForURL((*i)->url(), &url))
75 typed_count = url.typed_count();
77 NodeTypedCountPair pair(*i, typed_count);
78 node_typed_count_pairs->push_back(pair);
82 bool ChromeBookmarkClient::IsPermanentNodeVisible(
83 const bookmarks::BookmarkPermanentNode* node) {
84 DCHECK(bookmarks::IsPermanentNode(node, managed_bookmark_service_));
85 if (bookmarks::IsManagedNode(node, managed_bookmark_service_))
86 return false;
87 #if defined(OS_ANDROID)
88 return node->type() == bookmarks::BookmarkNode::MOBILE;
89 #else
90 return node->type() != bookmarks::BookmarkNode::MOBILE;
91 #endif
94 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) {
95 content::RecordAction(action);
98 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() {
99 if (!managed_bookmark_service_)
100 return bookmarks::LoadExtraCallback();
102 return managed_bookmark_service_->GetLoadExtraNodesCallback();
105 bool ChromeBookmarkClient::CanSetPermanentNodeTitle(
106 const bookmarks::BookmarkNode* permanent_node) {
107 return !managed_bookmark_service_
108 ? true
109 : managed_bookmark_service_->CanSetPermanentNodeTitle(
110 permanent_node);
113 bool ChromeBookmarkClient::CanSyncNode(const bookmarks::BookmarkNode* node) {
114 return !managed_bookmark_service_
115 ? true
116 : managed_bookmark_service_->CanSyncNode(node);
119 bool ChromeBookmarkClient::CanBeEditedByUser(
120 const bookmarks::BookmarkNode* node) {
121 return !managed_bookmark_service_
122 ? true
123 : managed_bookmark_service_->CanBeEditedByUser(node);