| 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/android/enhanced_bookmarks/enhanced_bookmarks_bridge.h" | 5 #include "chrome/browser/android/enhanced_bookmarks/enhanced_bookmarks_bridge.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 9 #include "chrome/browser/profiles/profile_android.h" |
| 8 #include "components/bookmarks/browser/bookmark_model.h" | 10 #include "components/bookmarks/browser/bookmark_model.h" |
| 9 #include "components/bookmarks/browser/bookmark_utils.h" | 11 #include "components/bookmarks/browser/bookmark_utils.h" |
| 10 #include "components/bookmarks/common/android/bookmark_type.h" | 12 #include "components/bookmarks/common/android/bookmark_type.h" |
| 11 #include "components/enhanced_bookmarks/metadata_accessor.h" | 13 #include "components/enhanced_bookmarks/metadata_accessor.h" |
| 12 #include "jni/EnhancedBookmarksBridge_jni.h" | 14 #include "jni/EnhancedBookmarksBridge_jni.h" |
| 13 | 15 |
| 14 using bookmarks::BookmarkType; | 16 using bookmarks::BookmarkType; |
| 15 | 17 |
| 16 namespace enhanced_bookmarks { | 18 namespace enhanced_bookmarks { |
| 17 namespace android { | 19 namespace android { |
| 18 | 20 |
| 19 EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env, | 21 EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env, |
| 20 jobject obj, | 22 jobject obj, |
| 21 jlong bookmark_model_ptr) { | 23 Profile* profile) { |
| 22 bookmark_model_ = reinterpret_cast<BookmarkModel*>(bookmark_model_ptr); | 24 profile_ = profile; |
| 25 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); |
| 23 } | 26 } |
| 24 | 27 |
| 25 void EnhancedBookmarksBridge::Destroy(JNIEnv*, jobject) { | 28 void EnhancedBookmarksBridge::Destroy(JNIEnv*, jobject) { |
| 26 delete this; | 29 delete this; |
| 27 } | 30 } |
| 28 | 31 |
| 29 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( | 32 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( |
| 30 JNIEnv* env, jobject obj, jlong id, jint type) { | 33 JNIEnv* env, jobject obj, jlong id, jint type) { |
| 31 DCHECK(bookmark_model_->loaded()); | 34 DCHECK(bookmark_model_->loaded()); |
| 32 DCHECK_EQ(type, BookmarkType::NORMAL); | 35 DCHECK_EQ(type, BookmarkType::NORMAL); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 49 DCHECK_EQ(type, BookmarkType::NORMAL); | 52 DCHECK_EQ(type, BookmarkType::NORMAL); |
| 50 | 53 |
| 51 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( | 54 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( |
| 52 bookmark_model_, static_cast<int64>(id)); | 55 bookmark_model_, static_cast<int64>(id)); |
| 53 | 56 |
| 54 enhanced_bookmarks::SetDescriptionForBookmark( | 57 enhanced_bookmarks::SetDescriptionForBookmark( |
| 55 bookmark_model_, node, | 58 bookmark_model_, node, |
| 56 base::android::ConvertJavaStringToUTF8(env, description)); | 59 base::android::ConvertJavaStringToUTF8(env, description)); |
| 57 } | 60 } |
| 58 | 61 |
| 59 static jlong Init(JNIEnv* env, jobject obj, jlong bookmark_model_ptr) { | 62 static jlong Init(JNIEnv* env, jobject obj, jobject j_profile) { |
| 60 return reinterpret_cast<jlong>( | 63 return reinterpret_cast<jlong>(new EnhancedBookmarksBridge( |
| 61 new EnhancedBookmarksBridge(env, obj, bookmark_model_ptr)); | 64 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); |
| 62 } | 65 } |
| 63 | 66 |
| 64 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { | 67 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { |
| 65 return RegisterNativesImpl(env); | 68 return RegisterNativesImpl(env); |
| 66 } | 69 } |
| 67 | 70 |
| 68 } // namespace android | 71 } // namespace android |
| 69 } // namespace enhanced_bookmarks | 72 } // namespace enhanced_bookmarks |
| OLD | NEW |