OLD | NEW |
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 Loading... |
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 | 245 @Nullable Account account = ChromeSigninController.get(this).getSignedIn
User(); |
246 Account account = ChromeSigninController.get().getSignedInUser(); | |
247 if (account == null) { | 246 if (account == null) { |
248 // This should never happen, because this code should only be run if
a user is | 247 // This should never happen, because this code should only be run if
a user is |
249 // signed-in. | 248 // signed-in. |
250 Log.w(TAG, "No signed-in user; cannot send message to data center"); | 249 Log.w(TAG, "No signed-in user; cannot send message to data center"); |
251 return; | 250 return; |
252 } | 251 } |
253 | 252 |
254 // Attempt to retrieve a token for the user. This method will also inval
idate | 253 // Attempt to retrieve a token for the user. This method will also inval
idate |
255 // invalidAuthToken if it is non-null. | 254 // invalidAuthToken if it is non-null. |
256 AccountManagerHelper.get().getNewAuthToken(account, invalidAuthToken, | 255 AccountManagerHelper.get(this).getNewAuthToken(account, invalidAuthToken
, |
257 getOAuth2ScopeWithType(), new AccountManagerHelper.GetAuthTokenC
allback() { | 256 getOAuth2ScopeWithType(), new AccountManagerHelper.GetAuthTokenC
allback() { |
258 @Override | 257 @Override |
259 public void tokenAvailable(String token) { | 258 public void tokenAvailable(String token) { |
260 setAuthToken(InvalidationClientService.this.getApplicati
onContext(), | 259 setAuthToken(InvalidationClientService.this.getApplicati
onContext(), |
261 pendingIntent, token, getOAuth2ScopeWithType()); | 260 pendingIntent, token, getOAuth2ScopeWithType()); |
262 } | 261 } |
263 | 262 |
264 @Override | 263 @Override |
265 public void tokenUnavailable(boolean isTransientError) {} | 264 public void tokenUnavailable(boolean isTransientError) {} |
266 }); | 265 }); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 */ | 471 */ |
473 private void requestSync(@Nullable ObjectId objectId, long version, @Nullabl
e String payload) { | 472 private void requestSync(@Nullable ObjectId objectId, long version, @Nullabl
e String payload) { |
474 int objectSource = 0; | 473 int objectSource = 0; |
475 String objectName = null; | 474 String objectName = null; |
476 if (objectId != null) { | 475 if (objectId != null) { |
477 objectName = new String(objectId.getName()); | 476 objectName = new String(objectId.getName()); |
478 objectSource = objectId.getSource(); | 477 objectSource = objectId.getSource(); |
479 } | 478 } |
480 Bundle bundle = | 479 Bundle bundle = |
481 PendingInvalidation.createBundle(objectName, objectSource, versi
on, payload); | 480 PendingInvalidation.createBundle(objectName, objectSource, versi
on, payload); |
482 Account account = ChromeSigninController.get().getSignedInUser(); | 481 Account account = ChromeSigninController.get(this).getSignedInUser(); |
483 String contractAuthority = AndroidSyncSettings.getContractAuthority(this
); | 482 String contractAuthority = AndroidSyncSettings.getContractAuthority(this
); |
484 requestSyncFromContentResolver(bundle, account, contractAuthority); | 483 requestSyncFromContentResolver(bundle, account, contractAuthority); |
485 } | 484 } |
486 | 485 |
487 /** | 486 /** |
488 * Calls {@link ContentResolver#requestSync(Account, String, Bundle)} to tri
gger a sync. Split | 487 * Calls {@link ContentResolver#requestSync(Account, String, Bundle)} to tri
gger a sync. Split |
489 * into a separate method so that it can be overriden in tests. | 488 * into a separate method so that it can be overriden in tests. |
490 */ | 489 */ |
491 @VisibleForTesting | 490 @VisibleForTesting |
492 void requestSyncFromContentResolver( | 491 void requestSyncFromContentResolver( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 try { | 549 try { |
551 startService(intent); | 550 startService(intent); |
552 } catch (IllegalStateException exception) { | 551 } catch (IllegalStateException exception) { |
553 Log.e(TAG, "Failed to start service from exception: ", exception
); | 552 Log.e(TAG, "Failed to start service from exception: ", exception
); |
554 } | 553 } |
555 } else { | 554 } else { |
556 startService(intent); | 555 startService(intent); |
557 } | 556 } |
558 } | 557 } |
559 } | 558 } |
OLD | NEW |