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

Side by Side Diff: blimp/client/app/android/java/src/org/chromium/blimp/session/BlimpClientSession.java

Issue 1687393002: Add assigner support to Blimp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix evil build break? Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.blimp.session; 5 package org.chromium.blimp.session;
6 6
7 import org.chromium.base.annotations.CalledByNative; 7 import org.chromium.base.annotations.CalledByNative;
8 import org.chromium.base.annotations.JNINamespace; 8 import org.chromium.base.annotations.JNINamespace;
9 import org.chromium.blimp.R;
10 import org.chromium.blimp.assignment.Result;
9 11
10 /** 12 /**
11 * The Java representation of a native BlimpClientSession. This is primarily us ed to provide access 13 * The Java representation of a native BlimpClientSession. This is primarily us ed to provide access
12 * to the native session methods and to facilitate passing a BlimpClientSession object between Java 14 * to the native session methods and to facilitate passing a BlimpClientSession object between Java
13 * classes with native counterparts. 15 * classes with native counterparts.
14 */ 16 */
15 @JNINamespace("blimp::client") 17 @JNINamespace("blimp::client")
16 public class BlimpClientSession { 18 public class BlimpClientSession {
19 /**
20 * A callback for when the session needs to notify the UI about the state of the Blimp session.
21 */
22 public interface Callback {
23 /**
24 * Called when an engine assignment has been successful or failed.
25 * @param result The result code of the assignment. See
26 * assignment_source.h for details. M aps to a value in
27 * {@link Result}.
28 * @param suggestedMessageResourceId A suggested resource id for a strin g to display to the
29 * user if necessary.
30 */
31 void onAssignmentReceived(int result, int suggestedMessageResourceId);
32 }
33
34 private final Callback mCallback;
17 private long mNativeBlimpClientSessionAndroidPtr; 35 private long mNativeBlimpClientSessionAndroidPtr;
18 36
19 public BlimpClientSession() { 37 public BlimpClientSession(Callback callback) {
38 mCallback = callback;
20 mNativeBlimpClientSessionAndroidPtr = nativeInit(); 39 mNativeBlimpClientSessionAndroidPtr = nativeInit();
21 } 40 }
22 41
23 /** 42 /**
24 * Retrieves an assignment and uses it to connect to the engine. 43 * Retrieves an assignment and uses it to connect to the engine.
44 * @param token A OAuth2 access token for the account requesting access.
25 */ 45 */
26 public void connect() { 46 public void connect(String token) {
27 nativeConnect(mNativeBlimpClientSessionAndroidPtr); 47 nativeConnect(mNativeBlimpClientSessionAndroidPtr, token);
28 } 48 }
29 49
30 /** 50 /**
31 * Destroys the native BlimpClientSession. This class should not be used af ter this is called. 51 * Destroys the native BlimpClientSession. This class should not be used af ter this is called.
32 */ 52 */
33 public void destroy() { 53 public void destroy() {
34 if (mNativeBlimpClientSessionAndroidPtr == 0) return; 54 if (mNativeBlimpClientSessionAndroidPtr == 0) return;
35 55
36 nativeDestroy(mNativeBlimpClientSessionAndroidPtr); 56 nativeDestroy(mNativeBlimpClientSessionAndroidPtr);
37 mNativeBlimpClientSessionAndroidPtr = 0; 57 mNativeBlimpClientSessionAndroidPtr = 0;
38 } 58 }
39 59
40 // Methods that are called by native via JNI. 60 // Methods that are called by native via JNI.
41 @CalledByNative 61 @CalledByNative
62 private void onAssignmentReceived(int result) {
63 if (mCallback == null) return;
64
65 int resultMessageResourceId = R.string.assignment_failure_unknown;
66 switch (result) {
67 case Result.OK:
68 resultMessageResourceId = R.string.assignment_success;
69 break;
70 case Result.BAD_REQUEST:
71 resultMessageResourceId = R.string.assignment_failure_bad_reques t;
72 break;
73 case Result.BAD_RESPONSE:
74 resultMessageResourceId = R.string.assignment_failure_bad_respon se;
75 break;
76 case Result.INVALID_PROTOCOL_VERSION:
77 resultMessageResourceId = R.string.assignment_failure_bad_versio n;
78 break;
79 case Result.EXPIRED_ACCESS_TOKEN:
80 resultMessageResourceId = R.string.assignment_failure_expired_to ken;
81 break;
82 case Result.USER_INVALID:
83 resultMessageResourceId = R.string.assignment_failure_user_inval id;
84 break;
85 case Result.OUT_OF_VMS:
86 resultMessageResourceId = R.string.assignment_failure_out_of_vms ;
87 break;
88 case Result.SERVER_ERROR:
89 resultMessageResourceId = R.string.assignment_failure_server_err or;
90 break;
91 case Result.SERVER_INTERRUPTED:
92 resultMessageResourceId = R.string.assignment_failure_server_int errupted;
93 break;
94 case Result.NETWORK_FAILURE:
95 resultMessageResourceId = R.string.assignment_failure_network;
96 break;
97 case Result.UNKNOWN:
98 default:
99 resultMessageResourceId = R.string.assignment_failure_unknown;
100 break;
101 }
102 mCallback.onAssignmentReceived(result, resultMessageResourceId);
103 }
104
105 @CalledByNative
42 private long getNativePtr() { 106 private long getNativePtr() {
43 assert mNativeBlimpClientSessionAndroidPtr != 0; 107 assert mNativeBlimpClientSessionAndroidPtr != 0;
44 return mNativeBlimpClientSessionAndroidPtr; 108 return mNativeBlimpClientSessionAndroidPtr;
45 } 109 }
46 110
47 private native long nativeInit(); 111 private native long nativeInit();
48 private native void nativeConnect(long nativeBlimpClientSessionAndroid); 112 private native void nativeConnect(long nativeBlimpClientSessionAndroid, Stri ng token);
49 private native void nativeDestroy(long nativeBlimpClientSessionAndroid); 113 private native void nativeDestroy(long nativeBlimpClientSessionAndroid);
50 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698