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;
    }
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();
        }
       
       
       
        if (ReadingListFeatures.isReadingListEnabled()
                && (bookmarkType == BookmarkType.READING_LIST
                        || parent.getType() == BookmarkType.READING_LIST)) {
            return bookmarkModel.addToReadingList(title, url);
        }
        BookmarkId bookmarkId = null;
       
        if (url.getSpec().equals(UrlConstants.NTP_URL)) {
            title = context.getResources().getString(R.string.new_tab_title);
        }
       
        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);
        }
       
        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;
    }
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(); } if (readinglistfeatures.isreadinglistenabled() && (bookmarktype == bookmarktype.reading_list || parent.gettype() == bookmarktype.reading_list)) { return bookmarkmodel.addtoreadinglist(title, url); } bookmarkid bookmarkid = null; if (url.getspec().equals(urlconstants.ntp_url)) { title = context.getresources().getstring(r.string.new_tab_title); } 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); } 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; }