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