Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java

Issue 2784353002: Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Fix tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.components.invalidation; 5 package org.chromium.components.invalidation;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.app.PendingIntent; 8 import android.app.PendingIntent;
9 import android.content.ContentResolver; 9 import android.content.ContentResolver;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 public void reissueRegistrations(byte[] clientId) { 235 public void reissueRegistrations(byte[] clientId) {
236 Set<ObjectId> desiredRegistrations = readRegistrationsFromPrefs(); 236 Set<ObjectId> desiredRegistrations = readRegistrationsFromPrefs();
237 if (!desiredRegistrations.isEmpty()) { 237 if (!desiredRegistrations.isEmpty()) {
238 register(clientId, desiredRegistrations); 238 register(clientId, desiredRegistrations);
239 } 239 }
240 } 240 }
241 241
242 @Override 242 @Override
243 public void requestAuthToken(final PendingIntent pendingIntent, 243 public void requestAuthToken(final PendingIntent pendingIntent,
244 @Nullable String invalidAuthToken) { 244 @Nullable String invalidAuthToken) {
245 @Nullable Account account = ChromeSigninController.get(this).getSignedIn User(); 245 @Nullable
246 Account account = ChromeSigninController.get().getSignedInUser();
246 if (account == null) { 247 if (account == null) {
247 // This should never happen, because this code should only be run if a user is 248 // This should never happen, because this code should only be run if a user is
248 // signed-in. 249 // signed-in.
249 Log.w(TAG, "No signed-in user; cannot send message to data center"); 250 Log.w(TAG, "No signed-in user; cannot send message to data center");
250 return; 251 return;
251 } 252 }
252 253
253 // Attempt to retrieve a token for the user. This method will also inval idate 254 // Attempt to retrieve a token for the user. This method will also inval idate
254 // invalidAuthToken if it is non-null. 255 // invalidAuthToken if it is non-null.
255 AccountManagerHelper.get(this).getNewAuthToken(account, invalidAuthToken , 256 AccountManagerHelper.get().getNewAuthToken(account, invalidAuthToken,
256 getOAuth2ScopeWithType(), new AccountManagerHelper.GetAuthTokenC allback() { 257 getOAuth2ScopeWithType(), new AccountManagerHelper.GetAuthTokenC allback() {
257 @Override 258 @Override
258 public void tokenAvailable(String token) { 259 public void tokenAvailable(String token) {
259 setAuthToken(InvalidationClientService.this.getApplicati onContext(), 260 setAuthToken(InvalidationClientService.this.getApplicati onContext(),
260 pendingIntent, token, getOAuth2ScopeWithType()); 261 pendingIntent, token, getOAuth2ScopeWithType());
261 } 262 }
262 263
263 @Override 264 @Override
264 public void tokenUnavailable(boolean isTransientError) {} 265 public void tokenUnavailable(boolean isTransientError) {}
265 }); 266 });
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 */ 472 */
472 private void requestSync(@Nullable ObjectId objectId, long version, @Nullabl e String payload) { 473 private void requestSync(@Nullable ObjectId objectId, long version, @Nullabl e String payload) {
473 int objectSource = 0; 474 int objectSource = 0;
474 String objectName = null; 475 String objectName = null;
475 if (objectId != null) { 476 if (objectId != null) {
476 objectName = new String(objectId.getName()); 477 objectName = new String(objectId.getName());
477 objectSource = objectId.getSource(); 478 objectSource = objectId.getSource();
478 } 479 }
479 Bundle bundle = 480 Bundle bundle =
480 PendingInvalidation.createBundle(objectName, objectSource, versi on, payload); 481 PendingInvalidation.createBundle(objectName, objectSource, versi on, payload);
481 Account account = ChromeSigninController.get(this).getSignedInUser(); 482 Account account = ChromeSigninController.get().getSignedInUser();
482 String contractAuthority = AndroidSyncSettings.getContractAuthority(this ); 483 String contractAuthority = AndroidSyncSettings.getContractAuthority(this );
483 requestSyncFromContentResolver(bundle, account, contractAuthority); 484 requestSyncFromContentResolver(bundle, account, contractAuthority);
484 } 485 }
485 486
486 /** 487 /**
487 * Calls {@link ContentResolver#requestSync(Account, String, Bundle)} to tri gger a sync. Split 488 * Calls {@link ContentResolver#requestSync(Account, String, Bundle)} to tri gger a sync. Split
488 * into a separate method so that it can be overriden in tests. 489 * into a separate method so that it can be overriden in tests.
489 */ 490 */
490 @VisibleForTesting 491 @VisibleForTesting
491 void requestSyncFromContentResolver( 492 void requestSyncFromContentResolver(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 try { 550 try {
550 startService(intent); 551 startService(intent);
551 } catch (IllegalStateException exception) { 552 } catch (IllegalStateException exception) {
552 Log.e(TAG, "Failed to start service from exception: ", exception ); 553 Log.e(TAG, "Failed to start service from exception: ", exception );
553 } 554 }
554 } else { 555 } else {
555 startService(intent); 556 startService(intent);
556 } 557 }
557 } 558 }
558 } 559 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698