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

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: Add some deps only for gn deps check script. 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..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);
}

Powered by Google App Engine
This is Rietveld 408576698