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

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: Add deps file. 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.annotations.CalledByNative; 7 import org.chromium.base.annotations.CalledByNative;
8 import org.chromium.blimp_public.BlimpClientContext;
8 import org.chromium.blimp_public.BlimpClientContextDelegate; 9 import org.chromium.blimp_public.BlimpClientContextDelegate;
9 import org.chromium.chrome.browser.profiles.Profile; 10 import org.chromium.chrome.browser.profiles.Profile;
10 11
11 /** 12 /**
12 * The ChromeBlimpClientContextDelegate for //chrome which provides the necessar y functionality 13 * The ChromeBlimpClientContextDelegate for //chrome which provides the necessar y functionality
13 * required to run Blimp. This is the Java counterparty to the C++ 14 * required to run Blimp. This is the Java counterparty to the C++
14 * ChromeBlimpClientContextDelegateAndroid. 15 * ChromeBlimpClientContextDelegateAndroid.
15 * 16 *
16 * There can only be a single delegate for any given BlimpClientContext. To crea te one and attach 17 * 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)}. 18 * it, call {@link ChromeBlimpClientContextDelegate#createAndSetDelegateForConte xt(Profile)}.
18 * When the delegate should be deleted, a call to {@link #destroy} is required. 19 * When the delegate should be deleted, a call to {@link #destroy} is required.
19 */ 20 */
20 public class ChromeBlimpClientContextDelegate implements BlimpClientContextDeleg ate { 21 public class ChromeBlimpClientContextDelegate implements BlimpClientContextDeleg ate {
22 // Blimp client context reference associated with this delegate.
23 private BlimpClientContext mBlimpClientContext;
24
21 /** 25 /**
22 * Creates a new ChromeBlimpClientContextDelegate that is owned by the calle r. It automatically 26 * 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 27 * 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 28 * 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 29 * {@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 30 * {@link #destroy()} also removes the delegate from the BlimpClientContext by clearing the
27 * pointer for the delegate by calling BlimpClientContext::SetDelegate(nullp tr). 31 * pointer for the delegate by calling BlimpClientContext::SetDelegate(nullp tr).
28 * 32 *
29 * @param profile The profile to use to look for the BlimpClientContext. 33 * @param profile The profile to use to look for the BlimpClientContext.
30 * @return The newly created delegate, owned by the caller. 34 * @return The newly created delegate, owned by the caller.
31 */ 35 */
32 public static ChromeBlimpClientContextDelegate createAndSetDelegateForContex t(Profile profile) { 36 public static ChromeBlimpClientContextDelegate createAndSetDelegateForContex t(Profile profile) {
33 return new ChromeBlimpClientContextDelegate(profile); 37 return new ChromeBlimpClientContextDelegate(profile);
34 } 38 }
35 39
36 /** 40 /**
41 * @return {@link BlimpClientContext} object this delegate belongs to.
42 */
43 public BlimpClientContext getBlimpClientContext() {
44 return mBlimpClientContext;
45 }
46
47 /**
37 * The pointer to the ChromeBlimpClientContextDelegateAndroid JNI bridge. 48 * The pointer to the ChromeBlimpClientContextDelegateAndroid JNI bridge.
38 */ 49 */
39 private long mNativeChromeBlimpClientContextDelegateAndroid; 50 private long mNativeChromeBlimpClientContextDelegateAndroid;
40 51
41 private ChromeBlimpClientContextDelegate(Profile profile) { 52 private ChromeBlimpClientContextDelegate(Profile profile) {
42 // Create native delegate object. 53 // Create native delegate object.
43 mNativeChromeBlimpClientContextDelegateAndroid = nativeInit(profile); 54 mNativeChromeBlimpClientContextDelegateAndroid = nativeInit(profile);
44 55
56 BlimpClientContext context = BlimpClientContextFactory
57 .getBlimpClientContextForProfile(profile);
58 mBlimpClientContext = context;
59
45 // Set ourselves as the Java delegate object. 60 // Set ourselves as the Java delegate object.
46 BlimpClientContextFactory.getBlimpClientContextForProfile(profile).setDe legate(this); 61 mBlimpClientContext.setDelegate(this);
47 } 62 }
48 63
49 @CalledByNative 64 @CalledByNative
50 private void clearNativePtr() { 65 private void clearNativePtr() {
51 mNativeChromeBlimpClientContextDelegateAndroid = 0; 66 mNativeChromeBlimpClientContextDelegateAndroid = 0;
52 } 67 }
53 68
54 public void destroy() { 69 public void destroy() {
55 assert mNativeChromeBlimpClientContextDelegateAndroid != 0; 70 assert mNativeChromeBlimpClientContextDelegateAndroid != 0;
56 nativeDestroy(mNativeChromeBlimpClientContextDelegateAndroid); 71 nativeDestroy(mNativeChromeBlimpClientContextDelegateAndroid);
57 } 72 }
58 73
59 private native long nativeInit(Profile profile); 74 private native long nativeInit(Profile profile);
60 private native void nativeDestroy(long nativeChromeBlimpClientContextDelegat eAndroid); 75 private native void nativeDestroy(long nativeChromeBlimpClientContextDelegat eAndroid);
61 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698