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

Side by Side 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: Fixes for nits. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.chrome.browser.blimp; 5 package org.chromium.chrome.browser.blimp;
6 6
7 import org.chromium.base.ContextUtils;
7 import org.chromium.base.annotations.CalledByNative; 8 import org.chromium.base.annotations.CalledByNative;
9 import org.chromium.blimp_public.BlimpClientContext;
8 import org.chromium.blimp_public.BlimpClientContextDelegate; 10 import org.chromium.blimp_public.BlimpClientContextDelegate;
9 import org.chromium.chrome.browser.profiles.Profile; 11 import org.chromium.chrome.browser.profiles.Profile;
12 import org.chromium.chrome.browser.signin.AccountTrackerService;
10 13
11 /** 14 /**
12 * The ChromeBlimpClientContextDelegate for //chrome which provides the necessar y functionality 15 * The ChromeBlimpClientContextDelegate for //chrome which provides the necessar y functionality
13 * required to run Blimp. This is the Java counterparty to the C++ 16 * required to run Blimp. This is the Java counterparty to the C++
14 * ChromeBlimpClientContextDelegateAndroid. 17 * ChromeBlimpClientContextDelegateAndroid.
15 * 18 *
16 * There can only be a single delegate for any given BlimpClientContext. To crea te one and attach 19 * There can only be a single delegate for any given BlimpClientContext. To crea te one and attach
17 * it, call {@link ChromeBlimpClientContextDelegate#createAndSetDelegateForConte xt(Profile)}. 20 * it, call {@link ChromeBlimpClientContextDelegate#createAndSetDelegateForConte xt(Profile)}.
18 * When the delegate should be deleted, a call to {@link #destroy} is required. 21 * When the delegate should be deleted, a call to {@link #destroy} is required.
19 */ 22 */
20 public class ChromeBlimpClientContextDelegate implements BlimpClientContextDeleg ate { 23 public class ChromeBlimpClientContextDelegate
24 implements BlimpClientContextDelegate,
25 AccountTrackerService.OnSystemAccountsSeededListener {
26 /**
27 * {@link BlimpClientContext} associated with this delegate.
28 */
29 private BlimpClientContext mBlimpClientContext;
30
21 /** 31 /**
22 * Creates a new ChromeBlimpClientContextDelegate that is owned by the calle r. It automatically 32 * Creates a new ChromeBlimpClientContextDelegate that is owned by the calle r. It automatically
23 * attaches itself as the sole delegate for the BlimpClientContext attached to the given 33 * attaches itself as the sole delegate for the BlimpClientContext attached to the given
24 * profile. When the delegate should be deleted, the caller of this method m ust call 34 * profile. When the delegate should be deleted, the caller of this method m ust call
25 * {@link #destroy()} to ensure that the native counterparts are cleaned up. The call to 35 * {@link #destroy()} to ensure that the native counterparts are cleaned up. The call to
26 * {@link #destroy()} also removes the delegate from the BlimpClientContext by clearing the 36 * {@link #destroy()} also removes the delegate from the BlimpClientContext by clearing the
27 * pointer for the delegate by calling BlimpClientContext::SetDelegate(nullp tr). 37 * pointer for the delegate by calling BlimpClientContext::SetDelegate(nullp tr).
28 * 38 *
29 * @param profile The profile to use to look for the BlimpClientContext. 39 * @param profile The profile to use to look for the BlimpClientContext.
30 * @return The newly created delegate, owned by the caller. 40 * @return The newly created delegate, owned by the caller.
31 */ 41 */
32 public static ChromeBlimpClientContextDelegate createAndSetDelegateForContex t(Profile profile) { 42 public static ChromeBlimpClientContextDelegate createAndSetDelegateForContex t(Profile profile) {
33 return new ChromeBlimpClientContextDelegate(profile); 43 return new ChromeBlimpClientContextDelegate(profile);
34 } 44 }
35 45
36 /** 46 /**
47 * @return {@link BlimpClientContext} object this delegate belongs to.
48 */
49 public BlimpClientContext getBlimpClientContext() {
50 return mBlimpClientContext;
51 }
52
53 @Override
54 public void onSystemAccountsSeedingComplete() {
55 AccountTrackerService.get(ContextUtils.getApplicationContext())
56 .removeSystemAccountsSeededListener(this);
57
58 // Start authentication.
59 // Must request OAuth2 token after account seeded, or native ProfileOAut h2TokenService might
60 // revoke the refresh token during request, making token retrieval flaky .
61 mBlimpClientContext.connect();
62 }
63
64 @Override
65 public void onSystemAccountsChanged() {}
66
67 /**
37 * The pointer to the ChromeBlimpClientContextDelegateAndroid JNI bridge. 68 * The pointer to the ChromeBlimpClientContextDelegateAndroid JNI bridge.
38 */ 69 */
39 private long mNativeChromeBlimpClientContextDelegateAndroid; 70 private long mNativeChromeBlimpClientContextDelegateAndroid;
40 71
41 private ChromeBlimpClientContextDelegate(Profile profile) { 72 private ChromeBlimpClientContextDelegate(Profile profile) {
42 // Create native delegate object. 73 // Create native delegate object.
43 mNativeChromeBlimpClientContextDelegateAndroid = nativeInit(profile); 74 mNativeChromeBlimpClientContextDelegateAndroid = nativeInit(profile);
44 75
76 BlimpClientContext context =
77 BlimpClientContextFactory.getBlimpClientContextForProfile(profil e);
78 mBlimpClientContext = context;
79
45 // Set ourselves as the Java delegate object. 80 // Set ourselves as the Java delegate object.
46 BlimpClientContextFactory.getBlimpClientContextForProfile(profile).setDe legate(this); 81 mBlimpClientContext.setDelegate(this);
82
83 // Connect after account seeding finished, if account seeding is already done, listener will
84 // immediately get called.
85 AccountTrackerService.get(ContextUtils.getApplicationContext())
86 .addSystemAccountsSeededListener(this);
47 } 87 }
48 88
49 @CalledByNative 89 @CalledByNative
50 private void clearNativePtr() { 90 private void clearNativePtr() {
51 mNativeChromeBlimpClientContextDelegateAndroid = 0; 91 mNativeChromeBlimpClientContextDelegateAndroid = 0;
52 } 92 }
53 93
54 public void destroy() { 94 public void destroy() {
55 assert mNativeChromeBlimpClientContextDelegateAndroid != 0; 95 assert mNativeChromeBlimpClientContextDelegateAndroid != 0;
96
97 AccountTrackerService.get(ContextUtils.getApplicationContext())
98 .removeSystemAccountsSeededListener(this);
99
56 nativeDestroy(mNativeChromeBlimpClientContextDelegateAndroid); 100 nativeDestroy(mNativeChromeBlimpClientContextDelegateAndroid);
57 } 101 }
58 102
59 private native long nativeInit(Profile profile); 103 private native long nativeInit(Profile profile);
60 private native void nativeDestroy(long nativeChromeBlimpClientContextDelegat eAndroid); 104 private native void nativeDestroy(long nativeChromeBlimpClientContextDelegat eAndroid);
61 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698