Search in sources :

Example 1 with BookmarkModel

use of org.chromium.chrome.browser.bookmarks.BookmarkModel in project AndroidChromium by JackyAndroid.

the class ChromeActivity method addOrEditBookmark.

/**
     * Add the specified tab to bookmarks or allows to edit the bookmark if the specified tab is
     * already bookmarked. If a new bookmark is added, a snackbar will be shown.
     * @param tabToBookmark The tab that needs to be bookmarked.
     */
public void addOrEditBookmark(final Tab tabToBookmark) {
    if (tabToBookmark == null || tabToBookmark.isFrozen()) {
        return;
    }
    // Defense in depth against the UI being erroneously enabled.
    if (!mToolbarManager.getBookmarkBridge().isEditBookmarksEnabled()) {
        assert false;
        return;
    }
    // Note the use of getUserBookmarkId() over getBookmarkId() here: Managed bookmarks can't be
    // edited. If the current URL is only bookmarked by managed bookmarks, this will return
    // INVALID_BOOKMARK_ID, so the code below will fall back on adding a new bookmark instead.
    // TODO(bauerb): This does not take partner bookmarks into account.
    final long bookmarkId = tabToBookmark.getUserBookmarkId();
    final BookmarkModel bookmarkModel = new BookmarkModel();
    bookmarkModel.runAfterBookmarkModelLoaded(new Runnable() {

        @Override
        public void run() {
            // Gives up the bookmarking if the tab is being destroyed.
            if (!tabToBookmark.isClosing() && tabToBookmark.isInitialized()) {
                // The BookmarkModel will be destroyed by BookmarkUtils#addOrEditBookmark() when
                // done.
                BookmarkId newBookmarkId = BookmarkUtils.addOrEditBookmark(bookmarkId, bookmarkModel, tabToBookmark, getSnackbarManager(), ChromeActivity.this);
                // If a new bookmark was created, try to save an offline page for it.
                if (newBookmarkId != null && newBookmarkId.getId() != bookmarkId) {
                    OfflinePageUtils.saveBookmarkOffline(newBookmarkId, tabToBookmark);
                }
            } else {
                bookmarkModel.destroy();
            }
        }
    });
}
Also used : BookmarkId(org.chromium.components.bookmarks.BookmarkId) BookmarkModel(org.chromium.chrome.browser.bookmarks.BookmarkModel)

Example 2 with BookmarkModel

use of org.chromium.chrome.browser.bookmarks.BookmarkModel in project AndroidChromium by JackyAndroid.

the class SyncUserDataWiper method wipeSyncUserData.

/**
     * Wipes the user's bookmarks and sync data.
     * @return A promise which will be fulfilled once the data is wiped.
     */
public static Promise<Void> wipeSyncUserData() {
    final Promise<Void> promise = new Promise<>();
    final BookmarkModel model = new BookmarkModel();
    model.runAfterBookmarkModelLoaded(new Runnable() {

        @Override
        public void run() {
            model.removeAllUserBookmarks();
            model.destroy();
            PrefServiceBridge.getInstance().clearBrowsingData(new OnClearBrowsingDataListener() {

                @Override
                public void onBrowsingDataCleared() {
                    promise.fulfill(null);
                }
            }, SYNC_DATA_TYPES, TimePeriod.ALL_TIME);
        }
    });
    return promise;
}
Also used : Promise(org.chromium.base.Promise) OnClearBrowsingDataListener(org.chromium.chrome.browser.preferences.PrefServiceBridge.OnClearBrowsingDataListener) BookmarkModel(org.chromium.chrome.browser.bookmarks.BookmarkModel)

Aggregations

BookmarkModel (org.chromium.chrome.browser.bookmarks.BookmarkModel)2 Promise (org.chromium.base.Promise)1 OnClearBrowsingDataListener (org.chromium.chrome.browser.preferences.PrefServiceBridge.OnClearBrowsingDataListener)1 BookmarkId (org.chromium.components.bookmarks.BookmarkId)1