Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / enhanced_bookmarks / android / enhanced_bookmarks_bridge.cc
blob445f746c41cae96a8c61d92d5f61314a17428849
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
3 // found in the LICENSE file.
5 #include "components/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h"
7 #include "base/android/jni_string.h"
8 #include "components/bookmarks/browser/bookmark_model.h"
9 #include "components/bookmarks/browser/bookmark_utils.h"
10 #include "components/bookmarks/common/android/bookmark_type.h"
11 #include "components/enhanced_bookmarks/metadata_accessor.h"
12 #include "jni/EnhancedBookmarksBridge_jni.h"
14 using bookmarks::BookmarkType;
16 namespace enhanced_bookmarks {
17 namespace android {
19 EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env,
20 jobject obj,
21 jlong bookmark_model_ptr) {
22 bookmark_model_ = reinterpret_cast<BookmarkModel*>(bookmark_model_ptr);
25 void EnhancedBookmarksBridge::Destroy(JNIEnv*, jobject) {
26 delete this;
29 ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription(
30 JNIEnv* env, jobject obj, jlong id, jint type) {
31 DCHECK(bookmark_model_->loaded());
32 DCHECK_EQ(type, BookmarkType::NORMAL);
34 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID(
35 bookmark_model_, static_cast<int64>(id));
37 return node ?
38 base::android::ConvertUTF8ToJavaString(
39 env, enhanced_bookmarks::DescriptionFromBookmark(node)) :
40 ScopedJavaLocalRef<jstring>();
43 void EnhancedBookmarksBridge::SetBookmarkDescription(JNIEnv* env,
44 jobject obj,
45 jlong id,
46 jint type,
47 jstring description) {
48 DCHECK(bookmark_model_->loaded());
49 DCHECK_EQ(type, BookmarkType::NORMAL);
51 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID(
52 bookmark_model_, static_cast<int64>(id));
54 enhanced_bookmarks::SetDescriptionForBookmark(
55 bookmark_model_, node,
56 base::android::ConvertJavaStringToUTF8(env, description));
59 static jlong Init(JNIEnv* env, jobject obj, jlong bookmark_model_ptr) {
60 return reinterpret_cast<jlong>(
61 new EnhancedBookmarksBridge(env, obj, bookmark_model_ptr));
64 bool RegisterEnhancedBookmarksBridge(JNIEnv* env) {
65 return RegisterNativesImpl(env);
68 } // namespace android
69 } // namespace enhanced_bookmarks