diff options
author | kkimlabs@chromium.org <kkimlabs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-14 20:59:22 +0000 |
---|---|---|
committer | kkimlabs@chromium.org <kkimlabs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-14 21:01:04 +0000 |
commit | f3266cc3604c956eed772815aa40dd3af8c708c4 (patch) | |
tree | 5c5121960a002df88d19990b9baba81585df8bf7 /components | |
parent | 4a9056a40a64ba10bff569512360ccfffaf6a775 (diff) | |
download | chromium_src-f3266cc3604c956eed772815aa40dd3af8c708c4.zip chromium_src-f3266cc3604c956eed772815aa40dd3af8c708c4.tar.gz chromium_src-f3266cc3604c956eed772815aa40dd3af8c708c4.tar.bz2 |
[Android] EnhancedBookmarksBridge for bookmark description read&write.
Also moved BookmarksBridge#BookmarkItem to bookmarks component.
BUG=386785
Review URL: https://codereview.chromium.org/459973004
Cr-Commit-Position: refs/heads/master@{#289695}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289695 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
19 files changed, 560 insertions, 0 deletions
diff --git a/components/bookmarks.gypi b/components/bookmarks.gypi index c88c26e5..9d70d33 100644 --- a/components/bookmarks.gypi +++ b/components/bookmarks.gypi @@ -57,6 +57,20 @@ 'bookmarks/browser/scoped_group_bookmark_actions.cc', 'bookmarks/browser/scoped_group_bookmark_actions.h', ], + 'conditions': [ + ['OS == "android"', { + 'dependencies': [ + 'bookmarks_jni_headers', + ], + 'sources' : [ + 'bookmarks/common/android/bookmark_id.cc', + 'bookmarks/common/android/bookmark_id.h', + 'bookmarks/common/android/bookmark_type_list.h', + 'bookmarks/common/android/component_jni_registrar.cc', + 'bookmarks/common/android/component_jni_registrar.h', + ], + }], + ], }, { 'target_name': 'bookmarks_common', @@ -104,4 +118,45 @@ ], }, ], + 'conditions' : [ + ['OS=="android"', { + 'targets': [ + { + 'target_name': 'bookmarks_java', + 'type': 'none', + 'dependencies': [ + '../base/base.gyp:base_java', + 'bookmark_type_java', + ], + 'variables': { + 'java_in_dir': 'bookmarks/common/android/java', + }, + 'includes': [ '../build/java.gypi' ], + }, + { + 'target_name': 'bookmarks_jni_headers', + 'type': 'none', + 'sources': [ + 'bookmarks/common/android/java/src/org/chromium/components/bookmarks/BookmarkId.java', + ], + 'variables': { + 'jni_gen_package': 'components/bookmarks', + }, + 'includes': [ '../build/jni_generator.gypi' ], + }, + { + 'target_name': 'bookmark_type_java', + 'type': 'none', + 'sources': [ + 'bookmarks/common/android/java/src/org/chromium/components/bookmarks/BookmarkType.template', + ], + 'variables': { + 'package_name': 'org/chromium/components/bookmarks', + 'template_deps': ['bookmarks/common/android/bookmark_type_list.h'], + }, + 'includes': [ '../build/android/java_cpp_template.gypi' ], + }, + ], + }] + ], } diff --git a/components/bookmarks/DEPS b/components/bookmarks/DEPS index f5adbc8..4aefd68 100644 --- a/components/bookmarks/DEPS +++ b/components/bookmarks/DEPS @@ -5,6 +5,7 @@ include_rules = [ "+components/query_parser", "+components/startup_metric_utils", "+grit/components_strings.h", + "+jni", "+net/base", "+ui", ] diff --git a/components/bookmarks/common/android/OWNERS b/components/bookmarks/common/android/OWNERS new file mode 100644 index 0000000..3df886e --- /dev/null +++ b/components/bookmarks/common/android/OWNERS @@ -0,0 +1,3 @@ +yfriedman@chromium.org +tedchoc@chromium.org +kkimlabs@chromium.org diff --git a/components/bookmarks/common/android/bookmark_id.cc b/components/bookmarks/common/android/bookmark_id.cc new file mode 100644 index 0000000..b3c5a9b4 --- /dev/null +++ b/components/bookmarks/common/android/bookmark_id.cc @@ -0,0 +1,25 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/bookmarks/common/android/bookmark_id.h" + +#include "jni/BookmarkId_jni.h" + +namespace bookmarks { +namespace android { + +long JavaBookmarkIdGetId(JNIEnv* env, jobject obj) { + return Java_BookmarkId_getId(env, obj); +} + +int JavaBookmarkIdGetType(JNIEnv* env, jobject obj) { + return Java_BookmarkId_getType(env, obj); +} + +bool RegisterBookmarkId(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +} // namespace android +} // namespace bookmarks diff --git a/components/bookmarks/common/android/bookmark_id.h b/components/bookmarks/common/android/bookmark_id.h new file mode 100644 index 0000000..61fd7a8 --- /dev/null +++ b/components/bookmarks/common/android/bookmark_id.h @@ -0,0 +1,24 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_BOOKMARKS_COMMON_ANDROID_BOOKMARK_ID_H_ +#define COMPONENTS_BOOKMARKS_COMMON_ANDROID_BOOKMARK_ID_H_ + +#include <jni.h> + +namespace bookmarks { +namespace android { + +// See BookmarkId#getId +long JavaBookmarkIdGetId(JNIEnv* env, jobject obj); + +// See BookmarkId#getType +int JavaBookmarkIdGetType(JNIEnv* env, jobject obj); + +bool RegisterBookmarkId(JNIEnv* env); + +} // namespace android +} // namespace bookmarks + +#endif // COMPONENTS_BOOKMARKS_COMMON_ANDROID_BOOKMARK_ID_H_ diff --git a/components/bookmarks/common/android/bookmark_type.h b/components/bookmarks/common/android/bookmark_type.h new file mode 100644 index 0000000..0c4c3e2 --- /dev/null +++ b/components/bookmarks/common/android/bookmark_type.h @@ -0,0 +1,18 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_BOOKMARKS_COMMON_ANDROID_BOOKMARK_TYPE_H_ +#define COMPONENTS_BOOKMARKS_COMMON_ANDROID_BOOKMARK_TYPE_H_ + +namespace bookmarks { + +enum BookmarkType { +#define DEFINE_BOOKMARK_TYPE(name, value) name = value, +#include "components/bookmarks/common/android/bookmark_type_list.h" +#undef DEFINE_BOOKMARK_TYPE +}; + +} + +#endif // COMPONENTS_BOOKMARKS_COMMON_ANDROID_BOOKMARK_TYPE_H_ diff --git a/components/bookmarks/common/android/bookmark_type_list.h b/components/bookmarks/common/android/bookmark_type_list.h new file mode 100644 index 0000000..e0a6594 --- /dev/null +++ b/components/bookmarks/common/android/bookmark_type_list.h @@ -0,0 +1,13 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file intentionally does not have header guards, it's included +// inside a macro to generate enum values. + +#ifndef DEFINE_BOOKMARK_TYPE +#error "DEFINE_BOOKMARK_TYPE should be defined before including this file" +#endif + +DEFINE_BOOKMARK_TYPE(NORMAL, 0) +DEFINE_BOOKMARK_TYPE(PARTNER, 1) diff --git a/components/bookmarks/common/android/component_jni_registrar.cc b/components/bookmarks/common/android/component_jni_registrar.cc new file mode 100644 index 0000000..56a924a --- /dev/null +++ b/components/bookmarks/common/android/component_jni_registrar.cc @@ -0,0 +1,26 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/bookmarks/common/android/component_jni_registrar.h" + +#include "base/android/jni_android.h" +#include "base/android/jni_registrar.h" +#include "components/bookmarks/common/android/bookmark_id.h" + +namespace bookmarks { +namespace android { + +static base::android::RegistrationMethod kBookmarksRegisteredMethods[] = { + {"BookmarkId", RegisterBookmarkId}, +}; + +bool RegisterBookmarks(JNIEnv* env) { + return base::android::RegisterNativeMethods( + env, + kBookmarksRegisteredMethods, + arraysize(kBookmarksRegisteredMethods)); +} + +} // namespace android +} // namespace bookmarks diff --git a/components/bookmarks/common/android/component_jni_registrar.h b/components/bookmarks/common/android/component_jni_registrar.h new file mode 100644 index 0000000..09b8060 --- /dev/null +++ b/components/bookmarks/common/android/component_jni_registrar.h @@ -0,0 +1,18 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_BOOKMARKS_COMMON_ANDROID_COMPONENT_JNI_REGISTRAR_H_ +#define COMPONENTS_BOOKMARKS_COMMON_ANDROID_COMPONENT_JNI_REGISTRAR_H_ + +#include <jni.h> + +namespace bookmarks { +namespace android { + +bool RegisterBookmarks(JNIEnv* env); + +} // namespace android +} // namespace bookmarks + +#endif // COMPONENTS_BOOKMARKS_COMMON_ANDROID_COMPONENT_JNI_REGISTRAR_H_ diff --git a/components/bookmarks/common/android/java/src/org/chromium/components/bookmarks/BookmarkId.java b/components/bookmarks/common/android/java/src/org/chromium/components/bookmarks/BookmarkId.java new file mode 100644 index 0000000..88764fe --- /dev/null +++ b/components/bookmarks/common/android/java/src/org/chromium/components/bookmarks/BookmarkId.java @@ -0,0 +1,117 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.components.bookmarks; + +import android.text.TextUtils; +import android.util.Log; + +import org.chromium.base.CalledByNative; + +/** + * Simple object representing the bookmark id. + */ +public class BookmarkId { + public static final int INVALID_FOLDER_ID = -2; + public static final int ROOT_FOLDER_ID = -1; + + private static final String LOG_TAG = "BookmarkId"; + private static final char TYPE_PARTNER = 'p'; + + private final long mId; + private final int mType; + + public BookmarkId(long id, int type) { + mId = id; + mType = type; + } + + /** + * @param c The char representing the type. + * @return The Bookmark type from a char representing the type. + */ + private static int getBookmarkTypeFromChar(char c) { + switch (c) { + case TYPE_PARTNER: + return BookmarkType.BOOKMARK_TYPE_PARTNER; + default: + return BookmarkType.BOOKMARK_TYPE_NORMAL; + } + } + + /** + * @param c The char representing the bookmark type. + * @return Whether the char representing the bookmark type is a valid type. + */ + private static boolean isValidBookmarkTypeFromChar(char c) { + return c == TYPE_PARTNER; + } + + /** + * @param s The bookmark id string (Eg: p1 for partner bookmark id 1). + * @return the Bookmark id from the string which is a concatenation of + * bookmark type and the bookmark id. + */ + public static BookmarkId getBookmarkIdFromString(String s) { + long id = ROOT_FOLDER_ID; + int type = BookmarkType.BOOKMARK_TYPE_NORMAL; + if (TextUtils.isEmpty(s)) + return new BookmarkId(id, type); + char folderTypeChar = s.charAt(0); + if (isValidBookmarkTypeFromChar(folderTypeChar)) { + type = getBookmarkTypeFromChar(folderTypeChar); + s = s.substring(1); + } + try { + id = Long.parseLong(s); + } catch (NumberFormatException exception) { + Log.e(LOG_TAG, "Error parsing url to extract the bookmark folder id.", exception); + } + return new BookmarkId(id, type); + } + + /** + * @return The id of the bookmark. + */ + @CalledByNative + public long getId() { + return mId; + } + + /** + * @return The bookmark type. + */ + @CalledByNative + public int getType() { + return mType; + } + + private String getBookmarkTypeString() { + switch (mType) { + case BookmarkType.BOOKMARK_TYPE_PARTNER: + return String.valueOf(TYPE_PARTNER); + case BookmarkType.BOOKMARK_TYPE_NORMAL: + default: + return ""; + } + } + + @Override + public String toString() { + return getBookmarkTypeString() + mId; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof BookmarkId)) + return false; + BookmarkId item = (BookmarkId) o; + return (item.mId == mId && item.mType == mType); + } + + @Override + public int hashCode() { + return toString().hashCode(); + } +} diff --git a/components/bookmarks/common/android/java/src/org/chromium/components/bookmarks/BookmarkType.template b/components/bookmarks/common/android/java/src/org/chromium/components/bookmarks/BookmarkType.template new file mode 100644 index 0000000..fd89154 --- /dev/null +++ b/components/bookmarks/common/android/java/src/org/chromium/components/bookmarks/BookmarkType.template @@ -0,0 +1,13 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.components.bookmarks; + +public class BookmarkType { + +#define DEFINE_BOOKMARK_TYPE(name, value) public static final int BOOKMARK_TYPE_##name = value; +#include "components/bookmarks/common/android/bookmark_type_list.h" +#undef DEFINE_BOOKMARK_TYPE + +} diff --git a/components/enhanced_bookmarks.gypi b/components/enhanced_bookmarks.gypi index 8f0be9e..a26cc60 100644 --- a/components/enhanced_bookmarks.gypi +++ b/components/enhanced_bookmarks.gypi @@ -32,6 +32,17 @@ 'enhanced_bookmarks/persistent_image_store.h', ], 'conditions': [ + ['OS=="android"', { + 'sources': [ + 'enhanced_bookmarks/android/component_jni_registrar.cc', + 'enhanced_bookmarks/android/component_jni_registrar.h', + 'enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc', + 'enhanced_bookmarks/android/enhanced_bookmarks_bridge.h', + ], + 'dependencies': [ + 'enhanced_bookmarks_jni_headers', + ], + }], ['OS=="ios"', { 'sources!': [ 'enhanced_bookmarks/image_store_util.cc', @@ -67,4 +78,32 @@ 'includes': [ '../build/protoc.gypi' ], }, ], + 'conditions' : [ + ['OS=="android"', { + 'targets': [ + { + 'target_name': 'enhanced_bookmarks_java', + 'type': 'none', + 'dependencies': [ + 'components.gyp:bookmarks_java' + ], + 'variables': { + 'java_in_dir': 'enhanced_bookmarks/android/java', + }, + 'includes': [ '../build/java.gypi' ], + }, + { + 'target_name': 'enhanced_bookmarks_jni_headers', + 'type': 'none', + 'sources': [ + 'enhanced_bookmarks/android/java/src/org/chromium/components/enhancedbookmarks/EnhancedBookmarksBridge.java', + ], + 'variables': { + 'jni_gen_package': 'enhanced_bookmarks', + }, + 'includes': [ '../build/jni_generator.gypi' ], + }, + ], + }] + ], } diff --git a/components/enhanced_bookmarks/DEPS b/components/enhanced_bookmarks/DEPS index b3cce48..de785ae 100644 --- a/components/enhanced_bookmarks/DEPS +++ b/components/enhanced_bookmarks/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+components/bookmarks", + "+jni", "+sql", "+ui", ] diff --git a/components/enhanced_bookmarks/android/OWNERS b/components/enhanced_bookmarks/android/OWNERS new file mode 100644 index 0000000..3df886e --- /dev/null +++ b/components/enhanced_bookmarks/android/OWNERS @@ -0,0 +1,3 @@ +yfriedman@chromium.org +tedchoc@chromium.org +kkimlabs@chromium.org diff --git a/components/enhanced_bookmarks/android/component_jni_registrar.cc b/components/enhanced_bookmarks/android/component_jni_registrar.cc new file mode 100644 index 0000000..ab4440d --- /dev/null +++ b/components/enhanced_bookmarks/android/component_jni_registrar.cc @@ -0,0 +1,29 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/enhanced_bookmarks/android/component_jni_registrar.h" + +#include "base/android/jni_android.h" +#include "base/android/jni_registrar.h" +#include "base/basictypes.h" +#include "components/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h" + +using base::android::RegistrationMethod; + +namespace enhanced_bookmarks { +namespace android { + +static RegistrationMethod kEnhancedBookmarksRegisteredMethods[] = { + {"EnhancedBookmarksBridge", RegisterEnhancedBookmarksBridge}, +}; + +bool RegisterEnhancedBookmarks(JNIEnv* env) { + return base::android::RegisterNativeMethods( + env, + kEnhancedBookmarksRegisteredMethods, + arraysize(kEnhancedBookmarksRegisteredMethods)); +} + +} // namespace android +} // namespace enhanced_bookmarks diff --git a/components/enhanced_bookmarks/android/component_jni_registrar.h b/components/enhanced_bookmarks/android/component_jni_registrar.h new file mode 100644 index 0000000..d02d626 --- /dev/null +++ b/components/enhanced_bookmarks/android/component_jni_registrar.h @@ -0,0 +1,18 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_ENHANCED_BOOKMARKS_ANDROID_COMPONENT_JNI_REGISTRAR_H_ +#define COMPONENTS_ENHANCED_BOOKMARKS_ANDROID_COMPONENT_JNI_REGISTRAR_H_ + +#include <jni.h> + +namespace enhanced_bookmarks { +namespace android { + +bool RegisterEnhancedBookmarks(JNIEnv* env); + +} // namespace android +} // namespace enhanced_bookmarks + +#endif // COMPONENTS_ENHANCED_BOOKMARKS_ANDROID_COMPONENT_JNI_REGISTRAR_H_ diff --git a/components/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc b/components/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc new file mode 100644 index 0000000..445f746 --- /dev/null +++ b/components/enhanced_bookmarks/android/enhanced_bookmarks_bridge.cc @@ -0,0 +1,69 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h" + +#include "base/android/jni_string.h" +#include "components/bookmarks/browser/bookmark_model.h" +#include "components/bookmarks/browser/bookmark_utils.h" +#include "components/bookmarks/common/android/bookmark_type.h" +#include "components/enhanced_bookmarks/metadata_accessor.h" +#include "jni/EnhancedBookmarksBridge_jni.h" + +using bookmarks::BookmarkType; + +namespace enhanced_bookmarks { +namespace android { + +EnhancedBookmarksBridge::EnhancedBookmarksBridge(JNIEnv* env, + jobject obj, + jlong bookmark_model_ptr) { + bookmark_model_ = reinterpret_cast<BookmarkModel*>(bookmark_model_ptr); +} + +void EnhancedBookmarksBridge::Destroy(JNIEnv*, jobject) { + delete this; +} + +ScopedJavaLocalRef<jstring> EnhancedBookmarksBridge::GetBookmarkDescription( + JNIEnv* env, jobject obj, jlong id, jint type) { + DCHECK(bookmark_model_->loaded()); + DCHECK_EQ(type, BookmarkType::NORMAL); + + const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( + bookmark_model_, static_cast<int64>(id)); + + return node ? + base::android::ConvertUTF8ToJavaString( + env, enhanced_bookmarks::DescriptionFromBookmark(node)) : + ScopedJavaLocalRef<jstring>(); +} + +void EnhancedBookmarksBridge::SetBookmarkDescription(JNIEnv* env, + jobject obj, + jlong id, + jint type, + jstring description) { + DCHECK(bookmark_model_->loaded()); + DCHECK_EQ(type, BookmarkType::NORMAL); + + const BookmarkNode* node = bookmarks::GetBookmarkNodeByID( + bookmark_model_, static_cast<int64>(id)); + + enhanced_bookmarks::SetDescriptionForBookmark( + bookmark_model_, node, + base::android::ConvertJavaStringToUTF8(env, description)); +} + +static jlong Init(JNIEnv* env, jobject obj, jlong bookmark_model_ptr) { + return reinterpret_cast<jlong>( + new EnhancedBookmarksBridge(env, obj, bookmark_model_ptr)); +} + +bool RegisterEnhancedBookmarksBridge(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +} // namespace android +} // namespace enhanced_bookmarks diff --git a/components/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h b/components/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h new file mode 100644 index 0000000..13196869 --- /dev/null +++ b/components/enhanced_bookmarks/android/enhanced_bookmarks_bridge.h @@ -0,0 +1,43 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_ENHANCED_BOOKMARKS_ANDROID_ENHANCED_BOOKMARKS_BRIDGE_H_ +#define COMPONENTS_ENHANCED_BOOKMARKS_ANDROID_ENHANCED_BOOKMARKS_BRIDGE_H_ + +#include "base/android/jni_android.h" + +class BookmarkModel; + +namespace enhanced_bookmarks { +namespace android { + +class EnhancedBookmarksBridge { + public: + EnhancedBookmarksBridge(JNIEnv* env, jobject obj, jlong bookmark_model_ptr); + void Destroy(JNIEnv*, jobject); + + base::android::ScopedJavaLocalRef<jstring> GetBookmarkDescription( + JNIEnv* env, + jobject obj, + jlong id, + jint type); + + void SetBookmarkDescription(JNIEnv* env, + jobject obj, + jlong id, + jint type, + jstring description); + + private: + BookmarkModel* bookmark_model_; // weak + + DISALLOW_COPY_AND_ASSIGN(EnhancedBookmarksBridge); +}; + +bool RegisterEnhancedBookmarksBridge(JNIEnv* env); + +} // namespace android +} // namespace enhanced_bookmarks + +#endif // COMPONENTS_ENHANCED_BOOKMARKS_ANDROID_ENHANCED_BOOKMARKS_BRIDGE_H_ diff --git a/components/enhanced_bookmarks/android/java/src/org/chromium/components/enhancedbookmarks/EnhancedBookmarksBridge.java b/components/enhanced_bookmarks/android/java/src/org/chromium/components/enhancedbookmarks/EnhancedBookmarksBridge.java new file mode 100644 index 0000000..c244cb5 --- /dev/null +++ b/components/enhanced_bookmarks/android/java/src/org/chromium/components/enhancedbookmarks/EnhancedBookmarksBridge.java @@ -0,0 +1,45 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.components.enhancedbookmarks; + +import org.chromium.base.JNINamespace; +import org.chromium.components.bookmarks.BookmarkId; + +/** + * Access gate to C++ side enhanced bookmarks functionalities. + */ +@JNINamespace("enhanced_bookmarks::android") +public final class EnhancedBookmarksBridge { + private long mNativeEnhancedBookmarksBridge; + + public EnhancedBookmarksBridge(long nativeBookmarkModel) { + mNativeEnhancedBookmarksBridge = nativeInit(nativeBookmarkModel); + } + + public void destroy() { + assert mNativeEnhancedBookmarksBridge != 0; + nativeDestroy(mNativeEnhancedBookmarksBridge); + mNativeEnhancedBookmarksBridge = 0; + } + + public String getBookmarkDescription(BookmarkId id) { + return nativeGetBookmarkDescription(mNativeEnhancedBookmarksBridge, id.getId(), + id.getType()); + } + + public void setBookmarkDescription(BookmarkId id, String description) { + nativeSetBookmarkDescription(mNativeEnhancedBookmarksBridge, id.getId(), id.getType(), + description); + } + + private native long nativeInit(long bookmarkModelPointer); + + private native void nativeDestroy(long nativeEnhancedBookmarksBridge); + + private native String nativeGetBookmarkDescription(long nativeEnhancedBookmarksBridge, long id, + int type); + private native void nativeSetBookmarkDescription(long nativeEnhancedBookmarksBridge, long id, + int type, String description); +} |