org.chromium.components.invalidation.PendingInvalidation Java Examples
The following examples show how to use
org.chromium.components.invalidation.PendingInvalidation.
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: ChromeBrowserSyncAdapter.java From delion with Apache License 2.0 | 6 votes |
private BrowserParts getBrowserParts(final Context context, final String account, final PendingInvalidation invalidation, final SyncResult syncResult, final Semaphore semaphore) { return new EmptyBrowserParts() { @Override public void finishNativeInitialization() { // Startup succeeded, so we can notify the invalidation. notifyInvalidation(invalidation.mObjectSource, invalidation.mObjectId, invalidation.mVersion, invalidation.mPayload); semaphore.release(); } @Override public void onStartupFailure() { // The startup failed, so we defer the invalidation. DelayedInvalidationsController.getInstance().addPendingInvalidation( context, account, invalidation); // Using numIoExceptions so Android will treat this as a soft error. syncResult.stats.numIoExceptions++; semaphore.release(); } }; }
Example #2
Source File: DelayedInvalidationsController.java From delion with Apache License 2.0 | 6 votes |
/** * Stores preferences to indicate that an invalidation has arrived, but dropped on the floor. */ @VisibleForTesting void addPendingInvalidation(Context context, String account, PendingInvalidation invalidation) { SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); String oldAccount = prefs.getString(DELAYED_ACCOUNT_NAME, null); // Make sure to construct a new set so it can be modified safely. See crbug.com/568369. Set<String> invals = new HashSet<String>( prefs.getStringSet(DELAYED_INVALIDATIONS, new HashSet<String>(1))); assert invals.isEmpty() || oldAccount != null; if (oldAccount != null && !oldAccount.equals(account)) { invals.clear(); } SharedPreferences.Editor editor = prefs.edit(); editor.putString(DELAYED_ACCOUNT_NAME, account); if (invalidation.mObjectSource == 0 || (oldAccount != null && invals.isEmpty())) { editor.putStringSet(DELAYED_INVALIDATIONS, null); } else { invals.add(invalidation.encodeToString()); editor.putStringSet(DELAYED_INVALIDATIONS, invals); } editor.apply(); }
Example #3
Source File: ChromeBrowserSyncAdapter.java From AndroidChromium with Apache License 2.0 | 6 votes |
private BrowserParts getBrowserParts(final Context context, final String account, final PendingInvalidation invalidation, final SyncResult syncResult, final Semaphore semaphore) { return new EmptyBrowserParts() { @Override public void finishNativeInitialization() { // Startup succeeded, so we can notify the invalidation. notifyInvalidation(invalidation.mObjectSource, invalidation.mObjectId, invalidation.mVersion, invalidation.mPayload); semaphore.release(); } @Override public void onStartupFailure() { // The startup failed, so we defer the invalidation. DelayedInvalidationsController.getInstance().addPendingInvalidation( context, account, invalidation); // Using numIoExceptions so Android will treat this as a soft error. syncResult.stats.numIoExceptions++; semaphore.release(); } }; }
Example #4
Source File: DelayedInvalidationsController.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Stores preferences to indicate that an invalidation has arrived, but dropped on the floor. */ @VisibleForTesting void addPendingInvalidation(Context context, String account, PendingInvalidation invalidation) { SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); String oldAccount = prefs.getString(DELAYED_ACCOUNT_NAME, null); // Make sure to construct a new set so it can be modified safely. See crbug.com/568369. Set<String> invals = new HashSet<String>( prefs.getStringSet(DELAYED_INVALIDATIONS, new HashSet<String>(1))); assert invals.isEmpty() || oldAccount != null; if (oldAccount != null && !oldAccount.equals(account)) { invals.clear(); } SharedPreferences.Editor editor = prefs.edit(); editor.putString(DELAYED_ACCOUNT_NAME, account); if (invalidation.mObjectSource == 0 || (oldAccount != null && invals.isEmpty())) { editor.putStringSet(DELAYED_INVALIDATIONS, null); } else { invals.add(invalidation.encodeToString()); editor.putStringSet(DELAYED_INVALIDATIONS, invals); } editor.apply(); }
Example #5
Source File: ChromeBrowserSyncAdapter.java From 365browser with Apache License 2.0 | 6 votes |
private BrowserParts getBrowserParts(final Context context, final String account, final PendingInvalidation invalidation, final SyncResult syncResult, final Semaphore semaphore) { return new EmptyBrowserParts() { @Override public void finishNativeInitialization() { // Startup succeeded, so we can notify the invalidation. notifyInvalidation(invalidation.mObjectSource, invalidation.mObjectId, invalidation.mVersion, invalidation.mPayload); semaphore.release(); } @Override public void onStartupFailure() { // The startup failed, so we defer the invalidation. DelayedInvalidationsController.getInstance().addPendingInvalidation( context, account, invalidation); // Using numIoExceptions so Android will treat this as a soft error. syncResult.stats.numIoExceptions++; semaphore.release(); } }; }
Example #6
Source File: DelayedInvalidationsController.java From 365browser with Apache License 2.0 | 6 votes |
/** * Adds newInvalidation into set of encoded invalidations. Invalidations with the same id/source * and lower version are removed from the set. If invalidation with same or higher version is * is present, then new invalidation is discarded. * @return true if update is successful, false when decoding invalidation from string fails. */ private boolean addInvalidationToSet( PendingInvalidation newInvalidation, Set<String> invalidations) { for (Iterator<String> iter = invalidations.iterator(); iter.hasNext();) { String encodedInvalidation = iter.next(); PendingInvalidation invalidation = PendingInvalidation.decodeToPendingInvalidation(encodedInvalidation); if (invalidation == null) return false; if (ApiCompatibilityUtils.objectEquals( invalidation.mObjectId, newInvalidation.mObjectId) && invalidation.mObjectSource == newInvalidation.mObjectSource) { if (invalidation.mVersion >= newInvalidation.mVersion) return true; iter.remove(); } } invalidations.add(newInvalidation.encodeToString()); return true; }
Example #7
Source File: DelayedInvalidationsController.java From 365browser with Apache License 2.0 | 5 votes |
/** * Stores preferences to indicate that an invalidation has arrived, but dropped on the floor. */ @VisibleForTesting void addPendingInvalidation(Context context, String account, PendingInvalidation invalidation) { SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); String oldAccount = prefs.getString(DELAYED_ACCOUNT_NAME, null); // Make sure to construct a new set so it can be modified safely. See crbug.com/568369. Set<String> invals = new HashSet<String>( prefs.getStringSet(DELAYED_INVALIDATIONS, Collections.<String>emptySet())); assert invals.isEmpty() || oldAccount != null; boolean invalidateAllTypes = false; // We invalidate all types if: // - the account has changed // - we were in "invalidate all types" mode already // - new invalidation indicates to invalidate all types by setting source to 0 // - adding invalidation to the current set failed if (oldAccount != null && !oldAccount.equals(account)) invalidateAllTypes = true; if (oldAccount != null && invals.isEmpty()) invalidateAllTypes = true; if (invalidation.mObjectSource == 0) invalidateAllTypes = true; if (!invalidateAllTypes && !addInvalidationToSet(invalidation, invals)) { invalidateAllTypes = true; } SharedPreferences.Editor editor = prefs.edit(); editor.putString(DELAYED_ACCOUNT_NAME, account); if (invalidateAllTypes) { editor.remove(DELAYED_INVALIDATIONS); } else { editor.putStringSet(DELAYED_INVALIDATIONS, invals); } editor.apply(); }
Example #8
Source File: ChromeBrowserSyncAdapter.java From delion with Apache License 2.0 | 4 votes |
@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 { // This code is only synchronously calling a single native method // 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++; } }
Example #9
Source File: ChromeBrowserSyncAdapter.java From AndroidChromium with Apache License 2.0 | 4 votes |
@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 { // This code is only synchronously calling a single native method // 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++; } }
Example #10
Source File: ChromeBrowserSyncAdapter.java From 365browser with Apache License 2.0 | 4 votes |
@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().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 { // This code is only synchronously calling a single native method // 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++; } }