org.chromium.chrome.browser.offlinepages.ClientId Java Examples

The following examples show how to use org.chromium.chrome.browser.offlinepages.ClientId. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TabContextMenuItemDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onSavePageLater(String linkUrl) {
    OfflinePageBridge bridge = OfflinePageBridge.getForProfile(mTab.getProfile());
    Random random = new Random();
    long offline_id = random.nextLong();
    ClientId clientId = new ClientId("async_loading", Long.toString(offline_id));
    bridge.savePageLater(linkUrl, clientId);
}
 
Example #2
Source File: SuggestionsSection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void setupOfflinePageBridgeObserver(NewTabPageManager manager) {
    final OfflinePageBridge.OfflinePageModelObserver observer =
            new OfflinePageBridge.OfflinePageModelObserver() {
                @Override
                public void offlinePageModelLoaded() {
                    updateAllSnippetOfflineAvailability();
                }

                @Override
                public void offlinePageModelChanged() {
                    updateAllSnippetOfflineAvailability();
                }

                @Override
                public void offlinePageDeleted(long offlineId, ClientId clientId) {
                    for (SnippetArticle article : mSuggestionsList) {
                        if (article.requiresExactOfflinePage()) continue;
                        Long articleOfflineId = article.getOfflinePageOfflineId();
                        if (articleOfflineId == null) continue;
                        if (articleOfflineId.longValue() != offlineId) continue;
                        // The old value cannot be simply removed without a request to the
                        // model, because there may be an older offline page for the same
                        // URL.
                        updateSnippetOfflineAvailability(article);
                    }
                }
            };

    mOfflinePageBridge.addObserver(observer);

    manager.addDestructionObserver(new DestructionObserver() {
        @Override
        public void onDestroy() {
            mIsNtpDestroyed = true;
            mOfflinePageBridge.removeObserver(observer);
        }
    });
}
 
Example #3
Source File: SuggestionsOfflineModelObserver.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void offlinePageDeleted(long offlineId, ClientId clientId) {
    for (T suggestion : getOfflinableSuggestions()) {
        if (suggestion.requiresExactOfflinePage()) continue;

        Long suggestionOfflineId = suggestion.getOfflinePageOfflineId();
        if (suggestionOfflineId == null) continue;
        if (suggestionOfflineId != offlineId) continue;

        // The old value cannot be simply removed without a request to the
        // model, because there may be an older offline page for the same
        // URL.
        updateOfflinableSuggestionAvailability(suggestion);
    }
}
 
Example #4
Source File: OfflinePageEvaluationBridge.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Saves a url as offline page async.
 * @param url The url of the web page.
 * @param namespace The namespace to which the page belongs.
 * @param userRequest True if it's user-requested page.
 */
public void savePageLater(final String url, final String namespace, boolean userRequested) {
    ClientId clientId = ClientId.createGuidClientIdForNamespace(namespace);
    nativeSavePageLater(mNativeOfflinePageEvaluationBridge, url, namespace, clientId.getId(),
            userRequested);
}
 
Example #5
Source File: OfflinePageEvaluationBridge.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Saves a url as offline page async.
 * @param url The url of the web page.
 * @param namespace The namespace to which the page belongs.
 * @param userRequest True if it's user-requested page.
 */
public void savePageLater(final String url, final String namespace, boolean userRequested) {
    ClientId clientId = ClientId.createGuidClientIdForNamespace(namespace);
    nativeSavePageLater(mNativeOfflinePageEvaluationBridge, url, namespace, clientId.getId(),
            userRequested);
}