Java Code Examples for org.chromium.base.Callback#onResult()

The following examples show how to use org.chromium.base.Callback#onResult() . 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: SuggestionsSection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void dismissItem(int position, Callback<String> itemRemovedCallback) {
    checkIndex(position);
    SuggestionsSource suggestionsSource = mUiDelegate.getSuggestionsSource();
    if (suggestionsSource == null) {
        // It is possible for this method to be called after the NewTabPage has had
        // destroy() called. This can happen when
        // NewTabPageRecyclerView.dismissWithAnimation() is called and the animation ends
        // after the user has navigated away. In this case we cannot inform the native side
        // that the snippet has been dismissed (http://crbug.com/649299).
        return;
    }

    SnippetArticle suggestion = remove(position);
    suggestionsSource.dismissSuggestion(suggestion);
    itemRemovedCallback.onResult(suggestion.mTitle);
}
 
Example 2
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Takes the offline page item from selectPageForOnlineURL. If it exists, invokes
 * |prepareForSharing| with it.  Otherwise, saves a page for the online URL and invokes
 * |prepareForSharing| with the result when it's ready.
 * @param webContents Contents of the page to save.
 * @param offlinePageBridge A static copy of the offlinePageBridge.
 * @param prepareForSharing Callback of a single OfflinePageItem that is used to call
 *                          prepareForSharing
 * @return a callback of OfflinePageItem
 */
private static Callback<OfflinePageItem> selectPageForOnlineUrlCallback(
        final WebContents webContents, final OfflinePageBridge offlinePageBridge,
        final Callback<OfflinePageItem> prepareForSharing) {
    return new Callback<OfflinePageItem>() {
        @Override
        public void onResult(OfflinePageItem item) {
            if (item == null) {
                // If the page has no offline copy, save the page offline.
                ClientId clientId = ClientId.createGuidClientIdForNamespace(
                        OfflinePageBridge.SHARE_NAMESPACE);
                offlinePageBridge.savePage(webContents, clientId,
                        savePageCallback(prepareForSharing, offlinePageBridge));
                return;
            }
            // If the online page has offline copy associated with it, use the file directly.
            prepareForSharing.onResult(item);
        }
    };
}
 
Example 3
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Saves the web page loaded into web contents. If page saved successfully, get the offline
 * page item with the save page result and use it to invoke |prepareForSharing|. Otherwise,
 * invokes |prepareForSharing| with null.
 * @param prepareForSharing Callback of a single OfflinePageItem that is used to call
 *                          prepareForSharing
 * @param offlinePageBridge A static copy of the offlinePageBridge.
 * @return a call back of a list of OfflinePageItem
 */
private static OfflinePageBridge.SavePageCallback savePageCallback(
        final Callback<OfflinePageItem> prepareForSharing,
        final OfflinePageBridge offlinePageBridge) {
    return new OfflinePageBridge.SavePageCallback() {
        @Override
        public void onSavePageDone(int savePageResult, String url, long offlineId) {
            if (savePageResult != SavePageResult.SUCCESS) {
                Log.e(TAG, "Unable to save the page.");
                prepareForSharing.onResult(null);
                return;
            }

            offlinePageBridge.getPageByOfflineId(offlineId, prepareForSharing);
        }
    };
}
 
Example 4
Source File: OfflinePageUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Saves the web page loaded into web contents. If page saved successfully, get the offline
 * page item with the save page result and use it to invoke |prepareForSharing|. Otherwise,
 * invokes |prepareForSharing| with null.
 * @param prepareForSharing Callback of a single OfflinePageItem that is used to call
 *                          prepareForSharing
 * @param offlinePageBridge A static copy of the offlinePageBridge.
 * @return a call back of a list of OfflinePageItem
 */
private static OfflinePageBridge.SavePageCallback savePageCallback(
        final Callback<OfflinePageItem> prepareForSharing,
        final OfflinePageBridge offlinePageBridge) {
    return new OfflinePageBridge.SavePageCallback() {
        @Override
        public void onSavePageDone(int savePageResult, String url, long offlineId) {
            if (savePageResult != SavePageResult.SUCCESS) {
                Log.e(TAG, "Unable to save the page.");
                prepareForSharing.onResult(null);
                return;
            }

            offlinePageBridge.getPageByOfflineId(offlineId, prepareForSharing);
        }
    };
}
 
Example 5
Source File: ChildAccountService.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Checks for the presence of child accounts on the device.
 *
 * @param callback A callback which will be called with the result.
 */
public static void checkHasChildAccount(Context context, final Callback<Boolean> callback) {
    ThreadUtils.assertOnUiThread();
    if (!nativeIsChildAccountDetectionEnabled()) {
        callback.onResult(false);
        return;
    }
    final AccountManagerHelper helper = AccountManagerHelper.get(context);
    helper.getGoogleAccounts(new Callback<Account[]>() {
        @Override
        public void onResult(Account[] accounts) {
            if (accounts.length != 1) {
                callback.onResult(false);
            } else {
                helper.checkChildAccount(accounts[0], callback);
            }
        }
    });
}
 
Example 6
Source File: OfflinePageUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Takes the offline page item from selectPageForOnlineURL. If it exists, invokes
 * |prepareForSharing| with it.  Otherwise, saves a page for the online URL and invokes
 * |prepareForSharing| with the result when it's ready.
 * @param webContents Contents of the page to save.
 * @param offlinePageBridge A static copy of the offlinePageBridge.
 * @param prepareForSharing Callback of a single OfflinePageItem that is used to call
 *                          prepareForSharing
 * @return a callback of OfflinePageItem
 */
private static Callback<OfflinePageItem> selectPageForOnlineUrlCallback(
        final WebContents webContents, final OfflinePageBridge offlinePageBridge,
        final Callback<OfflinePageItem> prepareForSharing) {
    return new Callback<OfflinePageItem>() {
        @Override
        public void onResult(OfflinePageItem item) {
            if (item == null) {
                // If the page has no offline copy, save the page offline.
                ClientId clientId = ClientId.createGuidClientIdForNamespace(
                        OfflinePageBridge.SHARE_NAMESPACE);
                offlinePageBridge.savePage(webContents, clientId,
                        savePageCallback(prepareForSharing, offlinePageBridge));
                return;
            }
            // If the online page has offline copy associated with it, use the file directly.
            prepareForSharing.onResult(item);
        }
    };
}
 
Example 7
Source File: MediaDrmStorageBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Remove persistent information related |emeId|.
 */
void clearInfo(byte[] emeId, Callback<Boolean> cb) {
    if (isNativeMediaDrmStorageValid()) {
        nativeOnClearInfo(mNativeMediaDrmStorageBridge, emeId, cb);
    } else {
        cb.onResult(true);
    }
}
 
Example 8
Source File: MediaDrmStorageBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called when device provisioning is finished.
 */
void onProvisioned(Callback<Boolean> cb) {
    if (isNativeMediaDrmStorageValid()) {
        nativeOnProvisioned(mNativeMediaDrmStorageBridge, cb);
    } else {
        cb.onResult(true);
    }
}
 
Example 9
Source File: MediaDrmStorageBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Load |emeId|'s storage into memory.
 */
void loadInfo(byte[] emeId, Callback<PersistentInfo> cb) {
    if (isNativeMediaDrmStorageValid()) {
        nativeOnLoadInfo(mNativeMediaDrmStorageBridge, emeId, cb);
    } else {
        cb.onResult(null);
    }
}
 
Example 10
Source File: SignInPromo.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Hides the sign in promo and sets a preference to make sure it is not shown again. */
@Override
public void dismiss(Callback<String> itemRemovedCallback) {
    mDismissed = true;
    setVisible(false);

    ChromePreferenceManager.getInstance().setNewTabPageSigninPromoDismissed(true);
    mObserver.unregister();
    itemRemovedCallback.onResult(ContextUtils.getApplicationContext().getString(getHeader()));
}
 
Example 11
Source File: SigninManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Performs an asynchronous check to see if the user is a managed user.
 * @param callback A callback to be called with true if the user is a managed user and false
 *         otherwise. May be called synchronously from this function.
 */
public static void isUserManaged(String email, final Callback<Boolean> callback) {
    if (nativeShouldLoadPolicyForUser(email)) {
        nativeIsUserManaged(email, callback);
    } else {
        callback.onResult(false);
    }
}
 
Example 12
Source File: OfflinePageBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes offline pages based on the list of offline IDs. Calls the callback
 * when operation is complete. Note that offline IDs are not intended to be saved across
 * restarts of Chrome; they should be obtained by querying the model for the appropriate client
 * ID.
 *
 * @param offlineIds A list of offline IDs of pages that will be deleted.
 * @param callback A callback that will be called once operation is completed, called with the
 *     DeletePageResult of the operation..
 */
public void deletePagesByOfflineId(List<Long> offlineIdList, Callback<Integer> callback) {
    if (offlineIdList == null) {
        callback.onResult(Integer.valueOf(DeletePageResult.SUCCESS));
        return;
    }

    long[] offlineIds = new long[offlineIdList.size()];
    for (int i = 0; i < offlineIdList.size(); i++) {
        offlineIds[i] = offlineIdList.get(i).longValue();
    }
    nativeDeletePagesByOfflineId(mNativeOfflinePageBridge, offlineIds, callback);
}
 
Example 13
Source File: ContextMenuHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the thumbnail of the current image that triggered the context menu.
 * @param callback Called once the the thumbnail is received.
 */
private void getThumbnail(final Callback<Bitmap> callback) {
    if (mNativeContextMenuHelper == 0) return;
    int maxSizePx = mActivity.getResources().getDimensionPixelSize(
            R.dimen.context_menu_header_image_max_size);
    Callback<byte[]> rawDataCallback = new Callback<byte[]>() {
        @Override
        public void onResult(byte[] result) {
            // TODO(tedchoc): Decode in separate process before launch.
            Bitmap bitmap = BitmapFactory.decodeByteArray(result, 0, result.length);
            callback.onResult(bitmap);
        }
    };
    nativeRetrieveImage(mNativeContextMenuHelper, rawDataCallback, maxSizePx);
}
 
Example 14
Source File: MediaDrmStorageBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Save persistent information. Override the existing value.
 */
void saveInfo(PersistentInfo info, Callback<Boolean> cb) {
    if (isNativeMediaDrmStorageValid()) {
        nativeOnSaveInfo(mNativeMediaDrmStorageBridge, info, cb);
    } else {
        cb.onResult(false);
    }
}
 
Example 15
Source File: BackgroundOfflinerTask.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Triggers processing of background offlining requests.
 */
// TODO(petewil): Change back to private when UMA works in the test, and test
// startBackgroundRequests instead of this method.
@VisibleForTesting
public void processBackgroundRequests(
        Bundle bundle, DeviceConditions deviceConditions,
        final ChromeBackgroundServiceWaiter waiter) {
    // TODO(petewil): Nothing is holding the Wake Lock.  We need some solution to
    // keep hold of it.  Options discussed so far are having a fresh set of functions
    // to grab and release a countdown latch, or holding onto the wake lock ourselves,
    // or grabbing the wake lock and then starting chrome and running startProcessing
    // on the UI thread.

    // TODO(petewil): Decode the TriggerConditions from the bundle.

    Callback<Boolean> callback = new Callback<Boolean>() {
        /**
         * Callback function which indicates completion of background work.
         * @param result - true if work was actually done (used for UMA).
         */
        @Override
        public void onResult(Boolean result) {
            // Release the wake lock.
            Log.d(TAG, "onProcessingDone");
            waiter.onWaitDone();
        }
    };

    // Pass the activation on to the bridge to the C++ RequestCoordinator.
    if (!mBridge.startProcessing(deviceConditions, callback)) {
        // Processing not started currently. Let callback know.
        callback.onResult(false);
    }
}
 
Example 16
Source File: FakeSuggestionsSource.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void fetchSuggestionImage(SnippetArticle suggestion, Callback<Bitmap> callback) {
    if (mThumbnails.containsKey(suggestion.mIdWithinCategory)) {
        callback.onResult(mThumbnails.get(suggestion.mIdWithinCategory));
    }
}
 
Example 17
Source File: AccountSigninView.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Refresh the list of available system accounts asynchronously.
 *
 * @param callback Called once the accounts have been refreshed. Boolean indicates whether the
 *                 accounts haven been successfully updated.
 */
private void updateAccounts(final Callback<Boolean> callback) {
    if (mSignedIn || mProfileData == null) {
        callback.onResult(false);
        return;
    }

    if (!checkGooglePlayServicesAvailable()) {
        setUpSigninButton(false);
        callback.onResult(false);
        return;
    }

    final List<String> oldAccountNames = mAccountNames;
    final AlertDialog updatingGmsDialog;

    if (mIsGooglePlayServicesOutOfDate) {
        updatingGmsDialog = new AlertDialog.Builder(getContext())
                .setCancelable(false)
                .setView(R.layout.updating_gms_progress_view)
                .create();
        updatingGmsDialog.show();
    } else {
        updatingGmsDialog = null;
    }

    mAccountManagerHelper.getGoogleAccountNames(new Callback<List<String>>() {
        @Override
        public void onResult(List<String> result) {
            if (updatingGmsDialog != null) {
                updatingGmsDialog.dismiss();
            }
            mIsGooglePlayServicesOutOfDate = false;

            if (mSignedIn) {
                // If sign-in completed in the mean time, return in order to avoid showing the
                // wrong state in the UI.
                return;
            }

            mAccountNames = result;

            int accountToSelect = 0;
            if (isInForcedAccountMode()) {
                accountToSelect = mAccountNames.indexOf(mForcedAccountName);
                if (accountToSelect < 0) {
                    mListener.onFailedToSetForcedAccount(mForcedAccountName);
                    callback.onResult(false);
                    return;
                }
            } else {
                accountToSelect = getIndexOfNewElement(
                        oldAccountNames, mAccountNames,
                        mSigninChooseView.getSelectedAccountPosition());
            }

            int oldSelectedAccount = mSigninChooseView.getSelectedAccountPosition();
            mSigninChooseView.updateAccounts(mAccountNames, accountToSelect, mProfileData);
            if (mAccountNames.isEmpty()) {
                setUpSigninButton(false);
                callback.onResult(true);
                return;
            }
            setUpSigninButton(true);

            mProfileData.update();

            // Determine how the accounts have changed. Each list should only have unique
            // elements.
            if (oldAccountNames == null || oldAccountNames.isEmpty()) {
                callback.onResult(true);
                return;
            }

            if (!mAccountNames.get(accountToSelect).equals(
                    oldAccountNames.get(oldSelectedAccount))) {
                // Any dialogs that may have been showing are now invalid (they were created
                // for the previously selected account).
                ConfirmSyncDataStateMachine
                        .cancelAllDialogs(mDelegate.getFragmentManager());

                if (mAccountNames.containsAll(oldAccountNames)) {
                    // A new account has been added and no accounts have been deleted. We
                    // will have changed the account selection to the newly added account, so
                    // shortcut to the confirm signin page.
                    showConfirmSigninPageAccountTrackerServiceCheck();
                }
            }
            callback.onResult(true);
        }
    });
}
 
Example 18
Source File: LocationUtils.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Triggers a prompt to ask the user to turn on the system location setting on their device.
 *
 * <p>The prompt will be triggered within the specified window.
 *
 * <p>The callback is guaranteed to be called unless the user never replies to the prompt
 * dialog, which in practice happens very infrequently since the dialog is modal.
 */
public void promptToEnableSystemLocationSetting(
        @LocationSettingsDialogContext int promptContext, WindowAndroid window,
        @LocationSettingsDialogOutcome Callback<Integer> callback) {
    callback.onResult(LocationSettingsDialogOutcome.NO_PROMPT);
}
 
Example 19
Source File: VariationsSession.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Asynchronously returns the value of the "restrict" URL param that the variations service
 * should use for variation seed requests.
 */
protected void getRestrictMode(Context context, Callback<String> callback) {
    callback.onResult("");
}
 
Example 20
Source File: VariationsSession.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Asynchronously returns the value of the "restrict" URL param that the variations service
 * should use for variation seed requests.
 */
protected void getRestrictMode(Context context, Callback<String> callback) {
    callback.onResult("");
}