| 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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 8 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 9 #include "base/containers/stack_container.h" | 12 #include "base/containers/stack_container.h" |
| 10 #include "base/i18n/string_compare.h" | 13 #include "base/i18n/string_compare.h" |
| 11 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 13 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 16 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 14 #include "chrome/browser/profiles/incognito_helpers.h" | 17 #include "chrome/browser/profiles/incognito_helpers.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_android.h" | 19 #include "chrome/browser/profiles/profile_android.h" |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 env, j_callback_obj, folder_id_obj.obj(), j_result_obj); | 585 env, j_callback_obj, folder_id_obj.obj(), j_result_obj); |
| 583 } | 586 } |
| 584 } | 587 } |
| 585 | 588 |
| 586 jboolean BookmarksBridge::IsFolderVisible(JNIEnv* env, | 589 jboolean BookmarksBridge::IsFolderVisible(JNIEnv* env, |
| 587 const JavaParamRef<jobject>& obj, | 590 const JavaParamRef<jobject>& obj, |
| 588 jlong id, | 591 jlong id, |
| 589 jint type) { | 592 jint type) { |
| 590 if (type == BookmarkType::BOOKMARK_TYPE_NORMAL) { | 593 if (type == BookmarkType::BOOKMARK_TYPE_NORMAL) { |
| 591 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( | 594 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( |
| 592 bookmark_model_, static_cast<int64>(id)); | 595 bookmark_model_, static_cast<int64_t>(id)); |
| 593 return node->IsVisible(); | 596 return node->IsVisible(); |
| 594 } else if (type == BookmarkType::BOOKMARK_TYPE_PARTNER) { | 597 } else if (type == BookmarkType::BOOKMARK_TYPE_PARTNER) { |
| 595 const BookmarkNode* node = partner_bookmarks_shim_->GetNodeByID( | 598 const BookmarkNode* node = partner_bookmarks_shim_->GetNodeByID( |
| 596 static_cast<long>(id)); | 599 static_cast<long>(id)); |
| 597 return partner_bookmarks_shim_->IsReachable(node); | 600 return partner_bookmarks_shim_->IsReachable(node); |
| 598 } | 601 } |
| 599 | 602 |
| 600 NOTREACHED(); | 603 NOTREACHED(); |
| 601 return false; | 604 return false; |
| 602 } | 605 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 } | 802 } |
| 800 | 803 |
| 801 return node->GetTitle(); | 804 return node->GetTitle(); |
| 802 } | 805 } |
| 803 | 806 |
| 804 ScopedJavaLocalRef<jobject> BookmarksBridge::CreateJavaBookmark( | 807 ScopedJavaLocalRef<jobject> BookmarksBridge::CreateJavaBookmark( |
| 805 const BookmarkNode* node) { | 808 const BookmarkNode* node) { |
| 806 JNIEnv* env = AttachCurrentThread(); | 809 JNIEnv* env = AttachCurrentThread(); |
| 807 | 810 |
| 808 const BookmarkNode* parent = GetParentNode(node); | 811 const BookmarkNode* parent = GetParentNode(node); |
| 809 int64 parent_id = parent ? parent->id() : -1; | 812 int64_t parent_id = parent ? parent->id() : -1; |
| 810 | 813 |
| 811 std::string url; | 814 std::string url; |
| 812 if (node->is_url()) | 815 if (node->is_url()) |
| 813 url = node->url().spec(); | 816 url = node->url().spec(); |
| 814 | 817 |
| 815 return Java_BookmarksBridge_createBookmarkItem( | 818 return Java_BookmarksBridge_createBookmarkItem( |
| 816 env, | 819 env, |
| 817 node->id(), | 820 node->id(), |
| 818 GetBookmarkType(node), | 821 GetBookmarkType(node), |
| 819 ConvertUTF16ToJavaString(env, GetTitle(node)).obj(), | 822 ConvertUTF16ToJavaString(env, GetTitle(node)).obj(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 830 JNIEnv* env = AttachCurrentThread(); | 833 JNIEnv* env = AttachCurrentThread(); |
| 831 if (!IsReachable(node)) | 834 if (!IsReachable(node)) |
| 832 return; | 835 return; |
| 833 Java_BookmarksBridge_addToList( | 836 Java_BookmarksBridge_addToList( |
| 834 env, j_result_obj, CreateJavaBookmark(node).obj()); | 837 env, j_result_obj, CreateJavaBookmark(node).obj()); |
| 835 } | 838 } |
| 836 | 839 |
| 837 const BookmarkNode* BookmarksBridge::GetNodeByID(long node_id, int type) { | 840 const BookmarkNode* BookmarksBridge::GetNodeByID(long node_id, int type) { |
| 838 const BookmarkNode* node; | 841 const BookmarkNode* node; |
| 839 if (type == BookmarkType::BOOKMARK_TYPE_PARTNER) { | 842 if (type == BookmarkType::BOOKMARK_TYPE_PARTNER) { |
| 840 node = partner_bookmarks_shim_->GetNodeByID( | 843 node = partner_bookmarks_shim_->GetNodeByID(static_cast<int64_t>(node_id)); |
| 841 static_cast<int64>(node_id)); | |
| 842 } else { | 844 } else { |
| 843 node = bookmarks::GetBookmarkNodeByID(bookmark_model_, | 845 node = bookmarks::GetBookmarkNodeByID(bookmark_model_, |
| 844 static_cast<int64>(node_id)); | 846 static_cast<int64_t>(node_id)); |
| 845 } | 847 } |
| 846 return node; | 848 return node; |
| 847 } | 849 } |
| 848 | 850 |
| 849 const BookmarkNode* BookmarksBridge::GetFolderWithFallback(long folder_id, | 851 const BookmarkNode* BookmarksBridge::GetFolderWithFallback(long folder_id, |
| 850 int type) { | 852 int type) { |
| 851 const BookmarkNode* folder = GetNodeByID(folder_id, type); | 853 const BookmarkNode* folder = GetNodeByID(folder_id, type); |
| 852 if (!folder || folder->type() == BookmarkNode::URL || | 854 if (!folder || folder->type() == BookmarkNode::URL || |
| 853 !IsFolderAvailable(folder)) { | 855 !IsFolderAvailable(folder)) { |
| 854 if (!managed_bookmark_service_->managed_node()->empty()) | 856 if (!managed_bookmark_service_->managed_node()->empty()) |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 BookmarkModelChanged(); | 1098 BookmarkModelChanged(); |
| 1097 } | 1099 } |
| 1098 | 1100 |
| 1099 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { | 1101 void BookmarksBridge::PartnerShimLoaded(PartnerBookmarksShim* shim) { |
| 1100 NotifyIfDoneLoading(); | 1102 NotifyIfDoneLoading(); |
| 1101 } | 1103 } |
| 1102 | 1104 |
| 1103 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { | 1105 void BookmarksBridge::ShimBeingDeleted(PartnerBookmarksShim* shim) { |
| 1104 partner_bookmarks_shim_ = NULL; | 1106 partner_bookmarks_shim_ = NULL; |
| 1105 } | 1107 } |
| OLD | NEW |