OLD | NEW |
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/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/favicon/favicon_service_factory.h" | 11 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 12 #include "chrome/browser/history/history_service_factory.h" |
12 #include "chrome/browser/policy/profile_policy_connector.h" | 13 #include "chrome/browser/policy/profile_policy_connector.h" |
13 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 14 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
16 #include "components/bookmarks/browser/bookmark_node.h" | 17 #include "components/bookmarks/browser/bookmark_node.h" |
17 #include "components/bookmarks/browser/bookmark_utils.h" | 18 #include "components/bookmarks/browser/bookmark_utils.h" |
18 #include "components/bookmarks/managed/managed_bookmarks_tracker.h" | 19 #include "components/bookmarks/managed/managed_bookmarks_tracker.h" |
19 #include "components/favicon/core/favicon_service.h" | 20 #include "components/favicon/core/favicon_service.h" |
20 #include "components/history/core/browser/history_service.h" | 21 #include "components/history/core/browser/history_service.h" |
21 #include "components/history/core/browser/url_database.h" | 22 #include "components/history/core/browser/url_database.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 node->set_id(id); | 57 node->set_id(id); |
57 *next_node_id = ManagedBookmarksTracker::LoadInitial( | 58 *next_node_id = ManagedBookmarksTracker::LoadInitial( |
58 node, initial_bookmarks, id + 1); | 59 node, initial_bookmarks, id + 1); |
59 node->set_visible(!node->empty()); | 60 node->set_visible(!node->empty()); |
60 } | 61 } |
61 | 62 |
62 } // namespace | 63 } // namespace |
63 | 64 |
64 ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile) | 65 ChromeBookmarkClient::ChromeBookmarkClient(Profile* profile) |
65 : profile_(profile), | 66 : profile_(profile), |
66 history_service_(NULL), | 67 model_(nullptr), |
67 model_(NULL), | 68 managed_node_(nullptr), |
68 managed_node_(NULL), | 69 supervised_node_(nullptr) { |
69 supervised_node_(NULL) { | |
70 } | 70 } |
71 | 71 |
72 ChromeBookmarkClient::~ChromeBookmarkClient() { | 72 ChromeBookmarkClient::~ChromeBookmarkClient() { |
73 } | 73 } |
74 | 74 |
75 void ChromeBookmarkClient::Init(BookmarkModel* model) { | 75 void ChromeBookmarkClient::Init(BookmarkModel* model) { |
76 DCHECK(model); | 76 DCHECK(model); |
77 DCHECK(!model_); | 77 DCHECK(!model_); |
78 model_ = model; | 78 model_ = model; |
79 model_->AddObserver(this); | 79 model_->AddObserver(this); |
80 | 80 |
81 managed_bookmarks_tracker_.reset(new ManagedBookmarksTracker( | 81 managed_bookmarks_tracker_.reset(new ManagedBookmarksTracker( |
82 model_, | 82 model_, |
83 profile_->GetPrefs(), | 83 profile_->GetPrefs(), |
84 false, | 84 false, |
85 base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain, | 85 base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain, |
86 base::Unretained(this)))); | 86 base::Unretained(this)))); |
87 supervised_bookmarks_tracker_.reset(new ManagedBookmarksTracker( | 87 supervised_bookmarks_tracker_.reset(new ManagedBookmarksTracker( |
88 model_, | 88 model_, |
89 profile_->GetPrefs(), | 89 profile_->GetPrefs(), |
90 true, | 90 true, |
91 base::Callback<std::string()>())); | 91 base::Callback<std::string()>())); |
92 } | 92 } |
93 | 93 |
94 void ChromeBookmarkClient::Shutdown() { | 94 void ChromeBookmarkClient::Shutdown() { |
95 favicon_changed_subscription_.reset(); | |
96 if (model_) { | 95 if (model_) { |
97 model_->RemoveObserver(this); | 96 model_->RemoveObserver(this); |
98 model_ = NULL; | 97 model_ = nullptr; |
99 } | 98 } |
100 BookmarkClient::Shutdown(); | 99 BookmarkClient::Shutdown(); |
101 } | 100 } |
102 | 101 |
103 bool ChromeBookmarkClient::PreferTouchIcon() { | 102 bool ChromeBookmarkClient::PreferTouchIcon() { |
104 #if !defined(OS_IOS) | 103 #if !defined(OS_IOS) |
105 return false; | 104 return false; |
106 #else | 105 #else |
107 return true; | 106 return true; |
108 #endif | 107 #endif |
(...skipping 23 matching lines...) Expand all Loading... |
132 } | 131 } |
133 } | 132 } |
134 | 133 |
135 bool ChromeBookmarkClient::SupportsTypedCountForNodes() { | 134 bool ChromeBookmarkClient::SupportsTypedCountForNodes() { |
136 return true; | 135 return true; |
137 } | 136 } |
138 | 137 |
139 void ChromeBookmarkClient::GetTypedCountForNodes( | 138 void ChromeBookmarkClient::GetTypedCountForNodes( |
140 const NodeSet& nodes, | 139 const NodeSet& nodes, |
141 NodeTypedCountPairs* node_typed_count_pairs) { | 140 NodeTypedCountPairs* node_typed_count_pairs) { |
| 141 history::HistoryService* history_service = |
| 142 HistoryServiceFactory::GetForProfileIfExists( |
| 143 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
142 history::URLDatabase* url_db = | 144 history::URLDatabase* url_db = |
143 history_service_ ? history_service_->InMemoryDatabase() : NULL; | 145 history_service ? history_service->InMemoryDatabase() : nullptr; |
144 for (NodeSet::const_iterator i = nodes.begin(); i != nodes.end(); ++i) { | 146 for (NodeSet::const_iterator i = nodes.begin(); i != nodes.end(); ++i) { |
145 int typed_count = 0; | 147 int typed_count = 0; |
146 | 148 |
147 // If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but | 149 // If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but |
148 // it guarantees to contain those with |typed_count| > 0. Thus, if we cannot | 150 // it guarantees to contain those with |typed_count| > 0. Thus, if we cannot |
149 // fetch the URLRow, it is safe to assume that its |typed_count| is 0. | 151 // fetch the URLRow, it is safe to assume that its |typed_count| is 0. |
150 history::URLRow url; | 152 history::URLRow url; |
151 if (url_db && url_db->GetRowForURL((*i)->url(), &url)) | 153 if (url_db && url_db->GetRowForURL((*i)->url(), &url)) |
152 typed_count = url.typed_count(); | 154 typed_count = url.typed_count(); |
153 | 155 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 bool ChromeBookmarkClient::CanSyncNode(const BookmarkNode* node) { | 213 bool ChromeBookmarkClient::CanSyncNode(const BookmarkNode* node) { |
212 return !bookmarks::IsDescendantOf(node, managed_node_) && | 214 return !bookmarks::IsDescendantOf(node, managed_node_) && |
213 !bookmarks::IsDescendantOf(node, supervised_node_); | 215 !bookmarks::IsDescendantOf(node, supervised_node_); |
214 } | 216 } |
215 | 217 |
216 bool ChromeBookmarkClient::CanBeEditedByUser(const BookmarkNode* node) { | 218 bool ChromeBookmarkClient::CanBeEditedByUser(const BookmarkNode* node) { |
217 return !bookmarks::IsDescendantOf(node, managed_node_) && | 219 return !bookmarks::IsDescendantOf(node, managed_node_) && |
218 !bookmarks::IsDescendantOf(node, supervised_node_); | 220 !bookmarks::IsDescendantOf(node, supervised_node_); |
219 } | 221 } |
220 | 222 |
221 void ChromeBookmarkClient::SetHistoryService( | |
222 history::HistoryService* history_service) { | |
223 DCHECK(history_service); | |
224 history_service_ = history_service; | |
225 favicon_changed_subscription_ = history_service_->AddFaviconChangedCallback( | |
226 base::Bind(&BookmarkModel::OnFaviconChanged, base::Unretained(model_))); | |
227 } | |
228 | |
229 void ChromeBookmarkClient::BookmarkModelChanged() { | 223 void ChromeBookmarkClient::BookmarkModelChanged() { |
230 } | 224 } |
231 | 225 |
232 void ChromeBookmarkClient::BookmarkNodeRemoved( | |
233 BookmarkModel* model, | |
234 const BookmarkNode* parent, | |
235 int old_index, | |
236 const BookmarkNode* node, | |
237 const std::set<GURL>& removed_urls) { | |
238 if (history_service_) | |
239 history_service_->URLsNoLongerBookmarked(removed_urls); | |
240 } | |
241 | |
242 void ChromeBookmarkClient::BookmarkAllUserNodesRemoved( | |
243 BookmarkModel* model, | |
244 const std::set<GURL>& removed_urls) { | |
245 if (history_service_) | |
246 history_service_->URLsNoLongerBookmarked(removed_urls); | |
247 } | |
248 | |
249 void ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model, | 226 void ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model, |
250 bool ids_reassigned) { | 227 bool ids_reassigned) { |
| 228 BaseBookmarkModelObserver::BookmarkModelLoaded(model, ids_reassigned); |
251 // Start tracking the managed and supervised bookmarks. This will detect any | 229 // Start tracking the managed and supervised bookmarks. This will detect any |
252 // changes that may have occurred while the initial managed and supervised | 230 // changes that may have occurred while the initial managed and supervised |
253 // bookmarks were being loaded on the background. | 231 // bookmarks were being loaded on the background. |
254 managed_bookmarks_tracker_->Init(managed_node_); | 232 managed_bookmarks_tracker_->Init(managed_node_); |
255 supervised_bookmarks_tracker_->Init(supervised_node_); | 233 supervised_bookmarks_tracker_->Init(supervised_node_); |
256 } | 234 } |
257 | 235 |
258 // static | 236 // static |
259 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes( | 237 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes( |
260 scoped_ptr<BookmarkPermanentNode> managed_node, | 238 scoped_ptr<BookmarkPermanentNode> managed_node, |
(...skipping 19 matching lines...) Expand all Loading... |
280 return extra_nodes.Pass(); | 258 return extra_nodes.Pass(); |
281 } | 259 } |
282 | 260 |
283 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() { | 261 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() { |
284 policy::ProfilePolicyConnector* connector = | 262 policy::ProfilePolicyConnector* connector = |
285 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile_); | 263 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile_); |
286 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks)) | 264 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks)) |
287 return connector->GetManagementDomain(); | 265 return connector->GetManagementDomain(); |
288 return std::string(); | 266 return std::string(); |
289 } | 267 } |
OLD | NEW |