// TODO(lazzzis): remove log after bookmark sync is fixed, crbug.com/986978
static BookmarkId addBookmarkInternal(Context context, BookmarkModel bookmarkModel,
            String title, GURL url, WebContents webContents, @Nullable BookmarkId parent,
            @BookmarkType int bookmarkType) {
        parent = parent == null ? getLastUsedParent(context, bookmarkModel) : parent;
        BookmarkItem parentItem = null;
        if (parent != null) {
            parentItem = bookmarkModel.getBookmarkById(parent);
        }
        if (parent == null || parentItem == null || parentItem.isManaged()
                || !parentItem.isFolder()) {
            parent = bookmarkModel.getDefaultFolder();
        }
        // Reading list items will be added when either one of the 2 conditions is met:
        // 1. The bookmark type explicitly specifies READING_LIST.
        // 2. The last used parent implicitly specifies READING_LIST.
        if (ReadingListFeatures.isReadingListEnabled()
                && (bookmarkType == BookmarkType.READING_LIST
                        || parent.getType() == BookmarkType.READING_LIST)) {
            return bookmarkModel.addToReadingList(title, url);
        }
        BookmarkId bookmarkId = null;
        // Use "New tab" as title for both incognito and regular NTP.
        if (url.getSpec().equals(UrlConstants.NTP_URL)) {
            title = context.getResources().getString(R.string.new_tab_title);
        }
        // The shopping list experiment saves extra metadata along with the bookmark.
        if (ChromeFeatureList.isInitialized()
                && ChromeFeatureList.isEnabled(ChromeFeatureList.SHOPPING_LIST)) {
            bookmarkId = bookmarkModel.addPowerBookmark(
                    webContents, parent, bookmarkModel.getChildCount(parent), title, url);
        } else {
            bookmarkId = bookmarkModel.addBookmark(
                    parent, bookmarkModel.getChildCount(parent), title, url);
        }
        // TODO(lazzzis): remove log after bookmark sync is fixed, crbug.com/986978
        if (bookmarkId == null) {
            Log.e(TAG,
                    "Failed to add bookmarks: parentTypeAndId %s, defaultFolderTypeAndId %s, "
                            + "mobileFolderTypeAndId %s, parentEditable Managed isFolder %s,",
                    parent, bookmarkModel.getDefaultFolder(), bookmarkModel.getMobileFolderId(),
                    parentItem == null ? "null"
                                       : (parentItem.isEditable() + " " + parentItem.isManaged()
                                               + " " + parentItem.isFolder()));
            setLastUsedParent(context, bookmarkModel.getDefaultFolder());
        }
        return bookmarkId;
    }
parent, bookmarkModel.getChildCount(parent), title, url);
}
// TODO(lazzzis): remove log after bookmark sync is fixed, crbug.com/986978
if (bookmarkId == null) {
Log.e(TAG,
}
// The shopping list experiment saves extra metadata along with the bookmark.
if (ChromeFeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.SHOPPING_LIST)) {
bookmarkId = bookmarkModel.addPowerBookmark(
webContents, parent, bookmarkModel.getChildCount(parent), title, url);
} else {
bookmarkId = bookmarkModel.addBookmark(
parent, bookmarkModel.getChildCount(parent), title, url);
}
// TODO(lazzzis): remove log after bookmark sync is fixed, crbug.com/986978
if (bookmarkId == null) {
Log.e(TAG,
"Failed to add bookmarks: parentTypeAndId %s, defaultFolderTypeAndId %s, "
+ "mobileFolderTypeAndId %s, parentEditable Managed isFolder %s,",
parent, bookmarkModel.getDefaultFolder(), bookmarkModel.getMobileFolderId(),
parentItem == null ? "null"
: (parentItem.isEditable() + " " + parentItem.isManaged()
+ " " + parentItem.isFolder()));
setLastUsedParent(context, bookmarkModel.getDefaultFolder());
}
// 2. The last used parent implicitly specifies READING_LIST.
if (ReadingListFeatures.isReadingListEnabled()
&& (bookmarkType == BookmarkType.READING_LIST
|| parent.getType() == BookmarkType.READING_LIST)) {
return bookmarkModel.addToReadingList(title, url);
}
BookmarkId bookmarkId = null;
// Use "New tab" as title for both incognito and regular NTP.
if (url.getSpec().equals(UrlConstants.NTP_URL)) {
title = context.getResources().getString(R.string.new_tab_title);
}
// The shopping list experiment saves extra metadata along with the bookmark.
if (ChromeFeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.SHOPPING_LIST)) {
bookmarkId = bookmarkModel.addPowerBookmark(
webContents, parent, bookmarkModel.getChildCount(parent), title, url);
} else {
bookmarkId = bookmarkModel.addBookmark(
parent, bookmarkModel.getChildCount(parent), title, url);
}
// TODO(lazzzis): remove log after bookmark sync is fixed, crbug.com/986978
if (bookmarkId == null) {
Log.e(TAG,
"Failed to add bookmarks: parentTypeAndId %s, defaultFolderTypeAndId %s, "
+ "mobileFolderTypeAndId %s, parentEditable Managed isFolder %s,",
parent, bookmarkModel.getDefaultFolder(), bookmarkModel.getMobileFolderId(),
parentItem == null ? "null"
: (parentItem.isEditable() + " " + parentItem.isManaged()
+ " " + parentItem.isFolder()));
setLastUsedParent(context, bookmarkModel.getDefaultFolder());
}
return bookmarkId;
}