This source file includes following definitions.
- bookmarkNodeExists
- createBookmarksFolderOnce
- getBookmarkFolderHierarchy
- removeAllBookmarks
- getBookmarkNode
- getDefaultBookmarkFolder
- getMobileBookmarksFolderId
- isBookmarkInMobileBookmarksBranch
- getPrivateProviderUri
- argsToBundle
- SuppressWarnings
- chromeBrowserProviderCall
package org.chromium.chrome.browser;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import org.chromium.chrome.browser.ChromeBrowserProvider.BookmarkNode;
import java.io.Serializable;
public class ChromeBrowserProviderClient {
private static final String TAG = "ChromeBrowserProviderClient";
public static final long INVALID_BOOKMARK_ID = ChromeBrowserProvider.INVALID_BOOKMARK_ID;
public static final int GET_NODE = 0x00000000;
public static final int GET_PARENT = 0x00000001;
public static final int GET_CHILDREN = 0x00000002;
public static final int GET_FAVICONS = 0x00000004;
public static final int GET_THUMBNAILS = 0x00000008;
public static boolean bookmarkNodeExists(Context context, long nodeId) {
Boolean result = chromeBrowserProviderCall(Boolean.class,
ChromeBrowserProvider.CLIENT_API_BOOKMARK_NODE_EXISTS,
context, argsToBundle(nodeId));
return result != null ? result.booleanValue() : false;
}
public static long createBookmarksFolderOnce(Context context, String title, long parentId) {
Long id = chromeBrowserProviderCall(Long.class,
ChromeBrowserProvider.CLIENT_API_CREATE_BOOKMARKS_FOLDER_ONCE, context,
argsToBundle(title, parentId));
return id != null ? id.longValue() : INVALID_BOOKMARK_ID;
}
public static BookmarkNode getBookmarkFolderHierarchy(Context context) {
return chromeBrowserProviderCall(BookmarkNode.class,
ChromeBrowserProvider.CLIENT_API_GET_BOOKMARK_FOLDER_HIERARCHY, context,
argsToBundle());
}
public static void removeAllBookmarks(Context context) {
chromeBrowserProviderCall(BookmarkNode.class,
ChromeBrowserProvider.CLIENT_API_DELETE_ALL_BOOKMARKS, context,
argsToBundle());
}
public static BookmarkNode getBookmarkNode(Context context, long nodeId, int flags) {
return chromeBrowserProviderCall(BookmarkNode.class,
ChromeBrowserProvider.CLIENT_API_GET_BOOKMARK_NODE, context,
argsToBundle(nodeId,
(flags & GET_PARENT) != 0,
(flags & GET_CHILDREN) != 0,
(flags & GET_FAVICONS) != 0,
(flags & GET_THUMBNAILS) != 0));
}
public static BookmarkNode getDefaultBookmarkFolder(Context context) {
return chromeBrowserProviderCall(BookmarkNode.class,
ChromeBrowserProvider.CLIENT_API_GET_DEFAULT_BOOKMARK_FOLDER, context,
argsToBundle());
}
public static long getMobileBookmarksFolderId(Context context) {
Long id = chromeBrowserProviderCall(Long.class,
ChromeBrowserProvider.CLIENT_API_GET_MOBILE_BOOKMARKS_FOLDER_ID, context,
argsToBundle());
return id != null ? id.longValue() : INVALID_BOOKMARK_ID;
}
public static boolean isBookmarkInMobileBookmarksBranch(Context context, long nodeId) {
Boolean result = chromeBrowserProviderCall(Boolean.class,
ChromeBrowserProvider.CLIENT_API_IS_BOOKMARK_IN_MOBILE_BOOKMARKS_BRANCH, context,
argsToBundle(nodeId));
return result != null ? result.booleanValue() : false;
}
private static Uri getPrivateProviderUri(Context context) {
return ChromeBrowserProvider.getBookmarksUri(context);
}
private static Bundle argsToBundle(Object ... args) {
Bundle methodArgs = new Bundle();
for (int i = 0; i < args.length; ++i) {
Class<? extends Object> argClass = args[i].getClass();
if (Parcelable.class.isAssignableFrom(argClass)) {
methodArgs.putParcelable(ChromeBrowserProvider.argKey(i), (Parcelable) args[i]);
} else if (Serializable.class.isAssignableFrom(argClass)) {
methodArgs.putSerializable(ChromeBrowserProvider.argKey(i), (Serializable) args[i]);
} else {
Log.e(TAG, "Argument implements neither Parcelable nor Serializable.");
return null;
}
}
return methodArgs;
}
@SuppressWarnings("unchecked")
private static <T extends Object> T chromeBrowserProviderCall(Class returnType, String name,
Context context, Bundle args) {
Bundle result = context.getContentResolver().call(getPrivateProviderUri(context),
name, null, args);
if (result == null)
return null;
if (Parcelable.class.isAssignableFrom(returnType)) {
return (T) result.getParcelable(ChromeBrowserProvider.CLIENT_API_RESULT_KEY);
} else {
return (T) result.get(ChromeBrowserProvider.CLIENT_API_RESULT_KEY);
}
}
}