Search in sources :

Example 1 with PendingInvalidation

use of org.chromium.components.invalidation.PendingInvalidation in project AndroidChromium by JackyAndroid.

the class ChromeBrowserSyncAdapter method onPerformSync.

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE)) {
        Account signedInAccount = ChromeSigninController.get(getContext()).getSignedInUser();
        if (account.equals(signedInAccount)) {
            ContentResolver.setIsSyncable(account, authority, 1);
        } else {
            ContentResolver.setIsSyncable(account, authority, 0);
        }
        return;
    }
    PendingInvalidation invalidation = new PendingInvalidation(extras);
    DelayedInvalidationsController controller = DelayedInvalidationsController.getInstance();
    if (!controller.shouldNotifyInvalidation(extras)) {
        controller.addPendingInvalidation(getContext(), account.name, invalidation);
        return;
    }
    // Browser startup is asynchronous, so we will need to wait for startup to finish.
    Semaphore semaphore = new Semaphore(0);
    // Configure the BrowserParts with all the data it needs.
    BrowserParts parts = getBrowserParts(mApplication, account.name, invalidation, syncResult, semaphore);
    startBrowserProcess(parts, syncResult, semaphore);
    try {
        // to trigger and asynchronous sync cycle, so 5 minutes is generous.
        if (!semaphore.tryAcquire(5, TimeUnit.MINUTES)) {
            Log.w(TAG, "Sync request timed out!");
            syncResult.stats.numIoExceptions++;
        }
    } catch (InterruptedException e) {
        Log.w(TAG, "Got InterruptedException when trying to request an invalidation.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
    }
}
Also used : Account(android.accounts.Account) Semaphore(java.util.concurrent.Semaphore) PendingInvalidation(org.chromium.components.invalidation.PendingInvalidation) BrowserParts(org.chromium.chrome.browser.init.BrowserParts) EmptyBrowserParts(org.chromium.chrome.browser.init.EmptyBrowserParts)

Aggregations

Account (android.accounts.Account)1 Semaphore (java.util.concurrent.Semaphore)1 BrowserParts (org.chromium.chrome.browser.init.BrowserParts)1 EmptyBrowserParts (org.chromium.chrome.browser.init.EmptyBrowserParts)1 PendingInvalidation (org.chromium.components.invalidation.PendingInvalidation)1