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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java

Issue 2204223005: Blimp OAuth2 token retreival on application start up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build config. Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java
index 21a005710765507f2012be9d9786a235f3c293d2..8c2f281121591c8b7a212ddb7c1c4a793cfd644d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java
@@ -4,9 +4,12 @@
package org.chromium.chrome.browser.blimp;
+import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
+import org.chromium.blimp_public.BlimpClientContext;
import org.chromium.blimp_public.BlimpClientContextDelegate;
import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.chrome.browser.signin.AccountTrackerService;
/**
* The ChromeBlimpClientContextDelegate for //chrome which provides the necessary functionality
@@ -17,7 +20,12 @@ import org.chromium.chrome.browser.profiles.Profile;
* it, call {@link ChromeBlimpClientContextDelegate#createAndSetDelegateForContext(Profile)}.
* When the delegate should be deleted, a call to {@link #destroy} is required.
*/
-public class ChromeBlimpClientContextDelegate implements BlimpClientContextDelegate {
+public class ChromeBlimpClientContextDelegate implements BlimpClientContextDelegate,
+ AccountTrackerService.OnSystemAccountsSeededListener {
+
+ // Blimp client context reference associated with this delegate.
+ private BlimpClientContext mBlimpClientContext;
+
/**
* Creates a new ChromeBlimpClientContextDelegate that is owned by the caller. It automatically
* attaches itself as the sole delegate for the BlimpClientContext attached to the given
@@ -34,6 +42,28 @@ public class ChromeBlimpClientContextDelegate implements BlimpClientContextDeleg
}
/**
+ * @return {@link BlimpClientContext} object this delegate belongs to.
+ */
+ public BlimpClientContext getBlimpClientContext() {
+ return mBlimpClientContext;
+ }
+
+ @Override
+ public void onSystemAccountsSeedingComplete() {
+ AccountTrackerService.get(ContextUtils.getApplicationContext())
+ .removeSystemAccountsSeededListener(this);
+
+ // Start authentication.
+ // Must request OAuth2 token after account seeded, or native ProfileOAuth2TokenService might
+ // revoke the refresh token during request, making token retrieval flaky.
+ mBlimpClientContext.connect();
+ }
+
+ @Override
+ public void onSystemAccountsChanged() {
+ }
+
+ /**
* The pointer to the ChromeBlimpClientContextDelegateAndroid JNI bridge.
*/
private long mNativeChromeBlimpClientContextDelegateAndroid;
@@ -42,8 +72,15 @@ public class ChromeBlimpClientContextDelegate implements BlimpClientContextDeleg
// Create native delegate object.
mNativeChromeBlimpClientContextDelegateAndroid = nativeInit(profile);
+ BlimpClientContext context = BlimpClientContextFactory
+ .getBlimpClientContextForProfile(profile);
+ mBlimpClientContext = context;
+
// Set ourselves as the Java delegate object.
- BlimpClientContextFactory.getBlimpClientContextForProfile(profile).setDelegate(this);
+ mBlimpClientContext.setDelegate(this);
+
+ AccountTrackerService.get(ContextUtils.getApplicationContext())
+ .addSystemAccountsSeededListener(this);
nyquist 2016/08/10 01:20:34 If this class is instantiated late (after accounts
xingliu 2016/08/10 21:03:15 Yes, I think so. It has state check, and will dire
}
@CalledByNative
@@ -53,6 +90,10 @@ public class ChromeBlimpClientContextDelegate implements BlimpClientContextDeleg
public void destroy() {
assert mNativeChromeBlimpClientContextDelegateAndroid != 0;
+
+ AccountTrackerService.get(ContextUtils.getApplicationContext())
+ .removeSystemAccountsSeededListener(this);
+
nativeDestroy(mNativeChromeBlimpClientContextDelegateAndroid);
}

Powered by Google App Engine
This is Rietveld 408576698