OLD | NEW |
---|---|
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.chromoting.jni; | 5 package org.chromium.chromoting.jni; |
6 | 6 |
7 import android.content.Context; | |
8 | |
7 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
8 import org.chromium.base.annotations.JNINamespace; | 10 import org.chromium.base.annotations.JNINamespace; |
9 import org.chromium.base.annotations.SuppressFBWarnings; | 11 import org.chromium.base.annotations.SuppressFBWarnings; |
12 import org.chromium.chromoting.AbstractDesktopView; | |
10 import org.chromium.chromoting.CapabilityManager; | 13 import org.chromium.chromoting.CapabilityManager; |
14 import org.chromium.chromoting.DesktopViewFactory; | |
11 import org.chromium.chromoting.InputStub; | 15 import org.chromium.chromoting.InputStub; |
12 import org.chromium.chromoting.SessionAuthenticator; | 16 import org.chromium.chromoting.SessionAuthenticator; |
13 | 17 |
14 /** | 18 /** |
15 * Class to manage a client connection to the host. This class controls the life time of the | 19 * Class to manage a client connection to the host. This class controls the life time of the |
16 * corresponding C++ object which implements the connection. A new object should be created for | 20 * corresponding C++ object which implements the connection. A new object should be created for |
17 * each connection to the host, so that notifications from a connection are alwa ys sent to the | 21 * each connection to the host, so that notifications from a connection are alwa ys sent to the |
18 * right object. | 22 * right object. |
19 * This class is used entirely on the UI thread. | 23 * This class is used entirely on the UI thread. |
20 */ | 24 */ |
21 @JNINamespace("remoting") | 25 @JNINamespace("remoting") |
22 public class Client implements InputStub { | 26 public class Client implements InputStub { |
23 // Pointer to the C++ object, cast to a |long|. | 27 // Pointer to the C++ object, cast to a |long|. |
24 private long mNativeJniClient; | 28 private long mNativeJniClient; |
25 | 29 |
26 // Implementation-dependent display object used by the desktop view. | 30 // The factory to create implementation-dependent desktop view. |
27 private Object mDisplay; | 31 private DesktopViewFactory mDesktopViewFactory; |
28 | 32 |
29 // The global Client instance (may be null). This needs to be a global singl eton so that the | 33 // The global Client instance (may be null). This needs to be a global singl eton so that the |
30 // Client can be passed between Activities. | 34 // Client can be passed between Activities. |
31 private static Client sClient; | 35 private static Client sClient; |
32 | 36 |
33 public Client() { | 37 public Client() { |
34 if (sClient != null) { | 38 if (sClient != null) { |
35 throw new RuntimeException("Client instance already created."); | 39 throw new RuntimeException("Client instance already created."); |
36 } | 40 } |
37 | 41 |
38 sClient = this; | 42 sClient = this; |
39 mNativeJniClient = nativeInit(); | 43 mNativeJniClient = nativeInit(); |
40 } | 44 } |
41 | 45 |
42 /** | 46 /** |
43 * Sets the display object. Called by the native code when the connection st arts. | 47 * Sets the desktop view factory. Called by the native code when the connect ion starts. |
44 * @param display the implementation-dependent object used by the desktop vi ew. | 48 * @param factory the factory to create implementation-dependent desktop vie w. |
Lambros
2016/07/08 22:02:36
s/the/The/
Yuwei
2016/07/08 23:46:01
Done.
| |
45 */ | 49 */ |
46 @CalledByNative | 50 @CalledByNative |
47 private void setDisplay(Object display) { | 51 private void setDesktopViewFactory(DesktopViewFactory factory) { |
48 mDisplay = display; | 52 mDesktopViewFactory = factory; |
49 } | 53 } |
50 | 54 |
51 /** | 55 public AbstractDesktopView createDesktopView(Context context) { |
52 * Returns the display object. It will be null before calling connectToHost( ) or after calling | 56 if (mDesktopViewFactory == null) { |
Lambros
2016/07/08 22:02:36
Do we need a null-check here? Maybe use Preconditi
Yuwei
2016/07/08 23:46:01
Done.
| |
53 * disconnectFromHost(). | 57 return null; |
54 * @return the display object. | 58 } |
55 */ | 59 return mDesktopViewFactory.createDesktopView(context); |
56 public Object getDisplay() { | |
57 return mDisplay; | |
58 } | 60 } |
59 | 61 |
60 // Suppress FindBugs warning, since |sClient| is only used on the UI thread. | 62 // Suppress FindBugs warning, since |sClient| is only used on the UI thread. |
61 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") | 63 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") |
62 public void destroy() { | 64 public void destroy() { |
63 if (sClient != null) { | 65 if (sClient != null) { |
64 disconnectFromHost(); | 66 disconnectFromHost(); |
65 nativeDestroy(mNativeJniClient); | 67 nativeDestroy(mNativeJniClient); |
66 sClient = null; | 68 sClient = null; |
67 } | 69 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 /** Same as disconnectFromHost() but without notifying the ConnectionListene r. */ | 125 /** Same as disconnectFromHost() but without notifying the ConnectionListene r. */ |
124 private void disconnectFromHostWithoutNotification() { | 126 private void disconnectFromHostWithoutNotification() { |
125 if (!mConnected) { | 127 if (!mConnected) { |
126 return; | 128 return; |
127 } | 129 } |
128 | 130 |
129 nativeDisconnect(mNativeJniClient); | 131 nativeDisconnect(mNativeJniClient); |
130 mConnectionListener = null; | 132 mConnectionListener = null; |
131 mConnected = false; | 133 mConnected = false; |
132 mCapabilityManager.onHostDisconnect(); | 134 mCapabilityManager.onHostDisconnect(); |
133 | |
134 mDisplay = null; | |
135 } | 135 } |
136 | 136 |
137 /** Called whenever the connection status changes. */ | 137 /** Called whenever the connection status changes. */ |
138 @CalledByNative | 138 @CalledByNative |
139 void onConnectionState(int stateCode, int errorCode) { | 139 void onConnectionState(int stateCode, int errorCode) { |
140 ConnectionListener.State state = ConnectionListener.State.fromValue(stat eCode); | 140 ConnectionListener.State state = ConnectionListener.State.fromValue(stat eCode); |
141 ConnectionListener.Error error = ConnectionListener.Error.fromValue(erro rCode); | 141 ConnectionListener.Error error = ConnectionListener.Error.fromValue(erro rCode); |
142 mConnectionListener.onConnectionState(state, error); | 142 mConnectionListener.onConnectionState(state, error); |
143 if (state == ConnectionListener.State.FAILED || state == ConnectionListe ner.State.CLOSED) { | 143 if (state == ConnectionListener.State.FAILED || state == ConnectionListe ner.State.CLOSED) { |
144 // Disconnect from the host here, otherwise the next time connectToH ost() is called, | 144 // Disconnect from the host here, otherwise the next time connectToH ost() is called, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 /** Passes touch event information to the native handling code. */ | 335 /** Passes touch event information to the native handling code. */ |
336 private native void nativeSendTouchEvent( | 336 private native void nativeSendTouchEvent( |
337 long nativeJniClient, int eventType, TouchEventData[] data); | 337 long nativeJniClient, int eventType, TouchEventData[] data); |
338 | 338 |
339 /** Native implementation of Client.enableVideoChannel() */ | 339 /** Native implementation of Client.enableVideoChannel() */ |
340 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e nable); | 340 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e nable); |
341 | 341 |
342 /** Passes extension message to the native code. */ | 342 /** Passes extension message to the native code. */ |
343 private native void nativeSendExtensionMessage(long nativeJniClient, String type, String data); | 343 private native void nativeSendExtensionMessage(long nativeJniClient, String type, String data); |
344 } | 344 } |
OLD | NEW |