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..7aa971b094ff8a3fe673877773c017b3c9cfe1f4 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. |
nyquist
2016/08/12 05:47:05
Could you use JavaDoc comment standard?
And maybe
xingliu
2016/08/12 21:11:18
Done.
|
+ 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,27 @@ 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 +71,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()) |
nyquist
2016/08/12 05:47:05
Could you add a comment that explains that the lis
xingliu
2016/08/12 21:11:18
Done.
|
+ .addSystemAccountsSeededListener(this); |
} |
@CalledByNative |
@@ -53,6 +89,10 @@ public class ChromeBlimpClientContextDelegate implements BlimpClientContextDeleg |
public void destroy() { |
assert mNativeChromeBlimpClientContextDelegateAndroid != 0; |
+ |
+ AccountTrackerService.get(ContextUtils.getApplicationContext()) |
+ .removeSystemAccountsSeededListener(this); |
+ |
nativeDestroy(mNativeChromeBlimpClientContextDelegateAndroid); |
} |