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

Side by Side Diff: chrome/browser/bookmarks/chrome_bookmark_client.cc

Issue 319543003: Create the managed_node at the ChromeBookmarkClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 5 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h"
9 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/favicon/favicon_changed_details.h" 12 #include "chrome/browser/favicon/favicon_changed_details.h"
11 #include "chrome/browser/favicon/favicon_service.h" 13 #include "chrome/browser/favicon/favicon_service.h"
12 #include "chrome/browser/favicon/favicon_service_factory.h" 14 #include "chrome/browser/favicon/favicon_service_factory.h"
13 #include "chrome/browser/history/history_service.h" 15 #include "chrome/browser/history/history_service.h"
14 #include "chrome/browser/history/history_service_factory.h" 16 #include "chrome/browser/history/history_service_factory.h"
15 #include "chrome/browser/history/url_database.h" 17 #include "chrome/browser/history/url_database.h"
18 #include "chrome/browser/policy/profile_policy_connector.h"
19 #include "chrome/browser/policy/profile_policy_connector_factory.h"
16 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/startup_task_runner_service.h"
22 #include "chrome/browser/profiles/startup_task_runner_service_factory.h"
17 #include "components/bookmarks/browser/bookmark_model.h" 23 #include "components/bookmarks/browser/bookmark_model.h"
18 #include "components/bookmarks/browser/bookmark_node.h" 24 #include "components/bookmarks/browser/bookmark_node.h"
25 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/user_metrics.h" 28 #include "content/public/browser/user_metrics.h"
29 #include "grit/components_strings.h"
30 #include "policy/policy_constants.h"
31 #include "ui/base/l10n/l10n_util.h"
22 32
23 namespace { 33 namespace {
24 34
25 void NotifyHistoryOfRemovedURLs(Profile* profile, 35 void NotifyHistoryOfRemovedURLs(Profile* profile,
26 const std::set<GURL>& removed_urls) { 36 const std::set<GURL>& removed_urls) {
27 HistoryService* history_service = 37 HistoryService* history_service =
28 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); 38 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);
29 if (history_service) 39 if (history_service)
30 history_service->URLsNoLongerBookmarked(removed_urls); 40 history_service->URLsNoLongerBookmarked(removed_urls);
31 } 41 }
32 42
33 } // namespace 43 } // namespace
34 44
35 ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile, bool index_urls) 45 ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile, bool index_urls)
36 : profile_(profile), 46 : profile_(profile),
37 model_(new BookmarkModel(this, index_urls)) { 47 model_(new BookmarkModel(this, index_urls)),
48 managed_bookmarks_tracker_(
49 model_.get(),
50 profile_->GetPrefs(),
51 base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain,
52 base::Unretained(this))),
53 managed_node_(NULL) {
38 model_->AddObserver(this); 54 model_->AddObserver(this);
39 // Listen for changes to favicons so that we can update the favicon of the 55 // Listen for changes to favicons so that we can update the favicon of the
40 // node appropriately. 56 // node appropriately.
41 registrar_.Add(this, 57 registrar_.Add(this,
42 chrome::NOTIFICATION_FAVICON_CHANGED, 58 chrome::NOTIFICATION_FAVICON_CHANGED,
43 content::Source<Profile>(profile_)); 59 content::Source<Profile>(profile_));
44 } 60 }
45 61
46 ChromeBookmarkClient::~ChromeBookmarkClient() { 62 ChromeBookmarkClient::~ChromeBookmarkClient() {
47 model_->RemoveObserver(this); 63 model_->RemoveObserver(this);
48 64
49 registrar_.RemoveAll(); 65 registrar_.RemoveAll();
50 } 66 }
51 67
68 bool ChromeBookmarkClient::IsDescendantOfManagedNode(const BookmarkNode* node) {
69 return node && node->HasAncestor(managed_node_);
70 }
71
52 bool ChromeBookmarkClient::PreferTouchIcon() { 72 bool ChromeBookmarkClient::PreferTouchIcon() {
53 #if !defined(OS_IOS) 73 #if !defined(OS_IOS)
54 return false; 74 return false;
55 #else 75 #else
56 return true; 76 return true;
57 #endif 77 #endif
58 } 78 }
59 79
60 base::CancelableTaskTracker::TaskId ChromeBookmarkClient::GetFaviconImageForURL( 80 base::CancelableTaskTracker::TaskId ChromeBookmarkClient::GetFaviconImageForURL(
61 const GURL& page_url, 81 const GURL& page_url,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 117
98 NodeTypedCountPair pair(*i, typed_count); 118 NodeTypedCountPair pair(*i, typed_count);
99 node_typed_count_pairs->push_back(pair); 119 node_typed_count_pairs->push_back(pair);
100 } 120 }
101 } 121 }
102 122
103 bool ChromeBookmarkClient::IsPermanentNodeVisible( 123 bool ChromeBookmarkClient::IsPermanentNodeVisible(
104 const BookmarkPermanentNode* node) { 124 const BookmarkPermanentNode* node) {
105 DCHECK(node->type() == BookmarkNode::BOOKMARK_BAR || 125 DCHECK(node->type() == BookmarkNode::BOOKMARK_BAR ||
106 node->type() == BookmarkNode::OTHER_NODE || 126 node->type() == BookmarkNode::OTHER_NODE ||
107 node->type() == BookmarkNode::MOBILE); 127 node->type() == BookmarkNode::MOBILE ||
128 node == managed_node_);
129 if (node == managed_node_)
130 return false;
108 #if !defined(OS_IOS) 131 #if !defined(OS_IOS)
109 return node->type() != BookmarkNode::MOBILE; 132 return node->type() != BookmarkNode::MOBILE;
110 #else 133 #else
111 return node->type() == BookmarkNode::MOBILE; 134 return node->type() == BookmarkNode::MOBILE;
112 #endif 135 #endif
113 } 136 }
114 137
115 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) { 138 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) {
116 content::RecordAction(action); 139 content::RecordAction(action);
117 } 140 }
118 141
119 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() { 142 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() {
120 return base::Bind(&ChromeBookmarkClient::LoadExtraNodes); 143 // Create the managed_node now; it will be populated in the LoadExtraNodes
144 // callback.
145 managed_node_ = new BookmarkPermanentNode(0);
146 return base::Bind(
147 &ChromeBookmarkClient::LoadExtraNodes,
148 StartupTaskRunnerServiceFactory::GetForProfile(profile_)
149 ->GetBookmarkTaskRunner(),
150 managed_node_,
151 base::Passed(managed_bookmarks_tracker_.GetInitialManagedBookmarks()));
121 } 152 }
122 153
123 bool ChromeBookmarkClient::CanRemovePermanentNodeChildren( 154 bool ChromeBookmarkClient::CanRemovePermanentNodeChildren(
124 const BookmarkNode* node) { 155 const BookmarkNode* node) {
125 return true; 156 return !IsDescendantOfManagedNode(node);
126 } 157 }
127 158
128 bool ChromeBookmarkClient::CanSetPermanentNodeTitle( 159 bool ChromeBookmarkClient::CanSetPermanentNodeTitle(
129 const BookmarkNode* permanent_node) { 160 const BookmarkNode* permanent_node) {
130 return false; 161 // The |managed_node_| can have its title updated if the user signs in or
162 // out.
163 return !IsDescendantOfManagedNode(permanent_node) ||
164 permanent_node == managed_node_;
131 } 165 }
132 166
133 bool ChromeBookmarkClient::CanSyncNode(const BookmarkNode* node) { 167 bool ChromeBookmarkClient::CanSyncNode(const BookmarkNode* node) {
134 return true; 168 return !IsDescendantOfManagedNode(node);
135 } 169 }
136 170
137 bool ChromeBookmarkClient::CanReorderChildren(const BookmarkNode* parent) { 171 bool ChromeBookmarkClient::CanReorderChildren(const BookmarkNode* parent) {
138 return true; 172 return !IsDescendantOfManagedNode(parent);
139 } 173 }
140 174
141 void ChromeBookmarkClient::Observe( 175 void ChromeBookmarkClient::Observe(
142 int type, 176 int type,
143 const content::NotificationSource& source, 177 const content::NotificationSource& source,
144 const content::NotificationDetails& details) { 178 const content::NotificationDetails& details) {
145 switch (type) { 179 switch (type) {
146 case chrome::NOTIFICATION_FAVICON_CHANGED: { 180 case chrome::NOTIFICATION_FAVICON_CHANGED: {
147 content::Details<FaviconChangedDetails> favicon_details(details); 181 content::Details<FaviconChangedDetails> favicon_details(details);
148 model_->OnFaviconChanged(favicon_details->urls); 182 model_->OnFaviconChanged(favicon_details->urls);
(...skipping 21 matching lines...) Expand all
170 const std::set<GURL>& removed_urls) { 204 const std::set<GURL>& removed_urls) {
171 NotifyHistoryOfRemovedURLs(profile_, removed_urls); 205 NotifyHistoryOfRemovedURLs(profile_, removed_urls);
172 } 206 }
173 207
174 void ChromeBookmarkClient::BookmarkAllNodesRemoved( 208 void ChromeBookmarkClient::BookmarkAllNodesRemoved(
175 BookmarkModel* model, 209 BookmarkModel* model,
176 const std::set<GURL>& removed_urls) { 210 const std::set<GURL>& removed_urls) {
177 NotifyHistoryOfRemovedURLs(profile_, removed_urls); 211 NotifyHistoryOfRemovedURLs(profile_, removed_urls);
178 } 212 }
179 213
214 void ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model,
215 bool ids_reassigned) {
216 // Start tracking the managed bookmarks. This will detect any changes that
217 // may have occurred while the initial managed bookmarks were being loaded
218 // on the background.
219 managed_bookmarks_tracker_.Init(managed_node_);
220 }
221
180 // static 222 // static
181 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes( 223 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes(
182 int64* next_id) { 224 const scoped_refptr<base::DeferredSequencedTaskRunner>& profile_io_runner,
183 // TODO(joaodasilva): load the managed node. http://crbug.com/49598 225 BookmarkPermanentNode* managed_node,
184 return bookmarks::BookmarkPermanentNodeList(); 226 scoped_ptr<base::ListValue> initial_managed_bookmarks,
227 int64* next_node_id) {
228 DCHECK(profile_io_runner->RunsTasksOnCurrentThread());
229 // Load the initial contents of the |managed_node| now, and assign it an
230 // unused ID.
231 int64 managed_id = *next_node_id;
232 managed_node->set_id(managed_id);
233 *next_node_id = policy::ManagedBookmarksTracker::LoadInitial(
234 managed_node, initial_managed_bookmarks.get(), managed_id + 1);
235 managed_node->set_visible(!managed_node->empty());
236 managed_node->SetTitle(
237 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME));
238
239 bookmarks::BookmarkPermanentNodeList extra_nodes;
240 extra_nodes.push_back(managed_node);
241 return extra_nodes.Pass();
185 } 242 }
243
244 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() {
245 policy::ProfilePolicyConnector* connector =
246 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_);
247 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks))
248 return connector->GetManagementDomain();
249 return std::string();
250 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/chrome_bookmark_client.h ('k') | chrome/browser/bookmarks/chrome_bookmark_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698