OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/android/bookmarks/bookmarks_bridge.h" | 5 #include "chrome/browser/android/bookmarks/bookmarks_bridge.h" |
6 | 6 |
7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/containers/stack_container.h" | 9 #include "base/containers/stack_container.h" |
10 #include "base/i18n/string_compare.h" | 10 #include "base/i18n/string_compare.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 jboolean get_normal, | 220 jboolean get_normal, |
221 jobject j_result_obj) { | 221 jobject j_result_obj) { |
222 DCHECK(IsLoaded()); | 222 DCHECK(IsLoaded()); |
223 std::vector<const BookmarkNode*> top_level_folders; | 223 std::vector<const BookmarkNode*> top_level_folders; |
224 | 224 |
225 if (get_special) { | 225 if (get_special) { |
226 if (client_->managed_node() && | 226 if (client_->managed_node() && |
227 client_->managed_node()->child_count() > 0) { | 227 client_->managed_node()->child_count() > 0) { |
228 top_level_folders.push_back(client_->managed_node()); | 228 top_level_folders.push_back(client_->managed_node()); |
229 } | 229 } |
| 230 if (client_->supervised_node() && |
| 231 client_->supervised_node()->child_count() > 0) { |
| 232 top_level_folders.push_back(client_->supervised_node()); |
| 233 } |
230 if (partner_bookmarks_shim_->HasPartnerBookmarks()) { | 234 if (partner_bookmarks_shim_->HasPartnerBookmarks()) { |
231 top_level_folders.push_back( | 235 top_level_folders.push_back( |
232 partner_bookmarks_shim_->GetPartnerBookmarksRoot()); | 236 partner_bookmarks_shim_->GetPartnerBookmarksRoot()); |
233 } | 237 } |
234 } | 238 } |
235 std::size_t special_count = top_level_folders.size(); | 239 std::size_t special_count = top_level_folders.size(); |
236 | 240 |
237 if (get_normal) { | 241 if (get_normal) { |
238 DCHECK_EQ(bookmark_model_->root_node()->child_count(), 4); | 242 DCHECK_EQ(bookmark_model_->root_node()->child_count(), 4); |
239 | 243 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 for (std::list<const BookmarkNode*>::iterator folder_iter = folders.begin(); | 429 for (std::list<const BookmarkNode*>::iterator folder_iter = folders.begin(); |
426 folder_iter != folders.end(); ++folder_iter) { | 430 folder_iter != folders.end(); ++folder_iter) { |
427 if (*folder_iter == NULL) | 431 if (*folder_iter == NULL) |
428 continue; | 432 continue; |
429 | 433 |
430 std::list<const BookmarkNode*>::iterator insert_iter = folder_iter; | 434 std::list<const BookmarkNode*>::iterator insert_iter = folder_iter; |
431 ++insert_iter; | 435 ++insert_iter; |
432 | 436 |
433 for (int i = 0; i < (*folder_iter)->child_count(); ++i) { | 437 for (int i = 0; i < (*folder_iter)->child_count(); ++i) { |
434 const BookmarkNode* child = (*folder_iter)->GetChild(i); | 438 const BookmarkNode* child = (*folder_iter)->GetChild(i); |
435 if (!IsReachable(child) || client_->IsDescendantOfManagedNode(child)) | 439 if (!IsReachable(child) || |
| 440 bookmarks::IsDescendantOf(child, client_->managed_node()) || |
| 441 bookmarks::IsDescendantOf(child, client_->supervised_node())) { |
436 continue; | 442 continue; |
| 443 } |
437 | 444 |
438 if (child->is_folder()) { | 445 if (child->is_folder()) { |
439 insert_iter = folders.insert(insert_iter, child); | 446 insert_iter = folders.insert(insert_iter, child); |
440 } else { | 447 } else { |
441 result.push_back(child); | 448 result.push_back(child); |
442 } | 449 } |
443 } | 450 } |
444 } | 451 } |
445 | 452 |
446 std::sort( | 453 std::sort( |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 return false; | 799 return false; |
793 } | 800 } |
794 if (!IsEditBookmarksEnabled()) | 801 if (!IsEditBookmarksEnabled()) |
795 return false; | 802 return false; |
796 if (partner_bookmarks_shim_->IsPartnerBookmark(node)) | 803 if (partner_bookmarks_shim_->IsPartnerBookmark(node)) |
797 return partner_bookmarks_shim_->IsEditable(node); | 804 return partner_bookmarks_shim_->IsEditable(node); |
798 return client_->CanBeEditedByUser(node); | 805 return client_->CanBeEditedByUser(node); |
799 } | 806 } |
800 | 807 |
801 bool BookmarksBridge::IsManaged(const BookmarkNode* node) const { | 808 bool BookmarksBridge::IsManaged(const BookmarkNode* node) const { |
802 return client_->IsDescendantOfManagedNode(node); | 809 return bookmarks::IsDescendantOf(node, client_->managed_node()); |
803 } | 810 } |
804 | 811 |
805 const BookmarkNode* BookmarksBridge::GetParentNode(const BookmarkNode* node) { | 812 const BookmarkNode* BookmarksBridge::GetParentNode(const BookmarkNode* node) { |
806 DCHECK(IsLoaded()); | 813 DCHECK(IsLoaded()); |
807 if (node == partner_bookmarks_shim_->GetPartnerBookmarksRoot()) { | 814 if (node == partner_bookmarks_shim_->GetPartnerBookmarksRoot()) { |
808 return bookmark_model_->mobile_node(); | 815 return bookmark_model_->mobile_node(); |
809 } else { | 816 } else { |
810 return node->parent(); | 817 return node->parent(); |
811 } | 818 } |
812 } | 819 } |
(...skipping 14 matching lines...) Expand all Loading... |
827 bool BookmarksBridge::IsLoaded() const { | 834 bool BookmarksBridge::IsLoaded() const { |
828 return (bookmark_model_->loaded() && partner_bookmarks_shim_->IsLoaded()); | 835 return (bookmark_model_->loaded() && partner_bookmarks_shim_->IsLoaded()); |
829 } | 836 } |
830 | 837 |
831 bool BookmarksBridge::IsFolderAvailable( | 838 bool BookmarksBridge::IsFolderAvailable( |
832 const BookmarkNode* folder) const { | 839 const BookmarkNode* folder) const { |
833 // The managed bookmarks folder is not shown if there are no bookmarks | 840 // The managed bookmarks folder is not shown if there are no bookmarks |
834 // configured via policy. | 841 // configured via policy. |
835 if (folder == client_->managed_node() && folder->empty()) | 842 if (folder == client_->managed_node() && folder->empty()) |
836 return false; | 843 return false; |
| 844 // Similarly, the supervised bookmarks folder is not shown if there are no |
| 845 // bookmarks configured by the custodian. |
| 846 if (folder == client_->supervised_node() && folder->empty()) |
| 847 return false; |
837 | 848 |
838 SigninManager* signin = SigninManagerFactory::GetForProfile( | 849 SigninManager* signin = SigninManagerFactory::GetForProfile( |
839 profile_->GetOriginalProfile()); | 850 profile_->GetOriginalProfile()); |
840 return (folder->type() != BookmarkNode::BOOKMARK_BAR && | 851 return (folder->type() != BookmarkNode::BOOKMARK_BAR && |
841 folder->type() != BookmarkNode::OTHER_NODE) || | 852 folder->type() != BookmarkNode::OTHER_NODE) || |
842 (signin && signin->IsAuthenticated()); | 853 (signin && signin->IsAuthenticated()); |
843 } | 854 } |
844 | 855 |
845 void BookmarksBridge::NotifyIfDoneLoading() { | 856 void BookmarksBridge::NotifyIfDoneLoading() { |
846 if (!IsLoaded()) | 857 if (!IsLoaded()) |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 BookmarkModelChanged(); | 1024 BookmarkModelChanged(); |
1014 } | 1025 } |
1015 | 1026 |
1016 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { | 1027 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { |
1017 NotifyIfDoneLoading(); | 1028 NotifyIfDoneLoading(); |
1018 } | 1029 } |
1019 | 1030 |
1020 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { | 1031 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { |
1021 partner_bookmarks_shim_ = NULL; | 1032 partner_bookmarks_shim_ = NULL; |
1022 } | 1033 } |
OLD | NEW |