Chromium Code Reviews| 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 | |
| 9 import org.chromium.base.annotations.CalledByNative; | 7 import org.chromium.base.annotations.CalledByNative; |
| 10 import org.chromium.base.annotations.JNINamespace; | 8 import org.chromium.base.annotations.JNINamespace; |
| 11 import org.chromium.base.annotations.SuppressFBWarnings; | 9 import org.chromium.base.annotations.SuppressFBWarnings; |
| 12 import org.chromium.chromoting.CapabilityManager; | 10 import org.chromium.chromoting.CapabilityManager; |
| 13 import org.chromium.chromoting.Desktop; | |
| 14 import org.chromium.chromoting.DesktopView; | |
| 15 import org.chromium.chromoting.DesktopViewFactory; | |
| 16 import org.chromium.chromoting.InputStub; | 11 import org.chromium.chromoting.InputStub; |
| 17 import org.chromium.chromoting.Preconditions; | 12 import org.chromium.chromoting.RenderStub; |
| 18 import org.chromium.chromoting.SessionAuthenticator; | 13 import org.chromium.chromoting.SessionAuthenticator; |
| 19 | 14 |
| 20 /** | 15 /** |
| 21 * Class to manage a client connection to the host. This class controls the life time of the | 16 * Class to manage a client connection to the host. This class controls the life time of the |
| 22 * corresponding C++ object which implements the connection. A new object should be created for | 17 * corresponding C++ object which implements the connection. A new object should be created for |
| 23 * each connection to the host, so that notifications from a connection are alwa ys sent to the | 18 * each connection to the host, so that notifications from a connection are alwa ys sent to the |
| 24 * right object. | 19 * right object. |
| 25 * This class is used entirely on the UI thread. | 20 * This class is used entirely on the UI thread. |
| 26 */ | 21 */ |
| 27 @JNINamespace("remoting") | 22 @JNINamespace("remoting") |
| 28 public class Client implements InputStub { | 23 public class Client implements InputStub { |
| 29 // Pointer to the C++ object, cast to a |long|. | 24 // Pointer to the C++ object, cast to a |long|. |
| 30 private long mNativeJniClient; | 25 private final long mNativeJniClient; |
| 31 | 26 |
| 32 // The factory to create implementation-dependent desktop view. | 27 private RenderStub mRenderStub; |
| 33 private DesktopViewFactory mDesktopViewFactory; | |
| 34 | 28 |
| 35 // The global Client instance (may be null). This needs to be a global singl eton so that the | 29 // The global Client instance (may be null). This needs to be a global singl eton so that the |
| 36 // Client can be passed between Activities. | 30 // Client can be passed between Activities. |
| 37 private static Client sClient; | 31 private static Client sClient; |
| 38 | 32 |
| 39 public Client() { | 33 public Client() { |
| 40 if (sClient != null) { | 34 if (sClient != null) { |
| 41 throw new RuntimeException("Client instance already created."); | 35 throw new RuntimeException("Client instance already created."); |
| 42 } | 36 } |
| 43 | 37 |
| 44 sClient = this; | 38 sClient = this; |
| 45 mNativeJniClient = nativeInit(); | 39 mNativeJniClient = nativeInit(); |
| 46 } | 40 } |
| 47 | 41 |
| 48 /** | |
| 49 * Sets the desktop view factory to be used by {@link Client#createDesktopVi ew(Context)}. | |
| 50 * @param factory The factory to create implementation-dependent desktop vie w. | |
| 51 */ | |
| 52 public void setDesktopViewFactory(DesktopViewFactory factory) { | |
| 53 mDesktopViewFactory = factory; | |
| 54 } | |
| 55 | |
| 56 /** | |
| 57 * Creates an implementation specific {@link DesktopView} using the | |
| 58 * {@link DesktopViewFactory} set by {@link Client#setDesktopViewFactory(Des ktopViewFactory)}. | |
| 59 */ | |
| 60 public DesktopView createDesktopView(Desktop desktop, Client client) { | |
| 61 Preconditions.notNull(mDesktopViewFactory); | |
| 62 return mDesktopViewFactory.createDesktopView(desktop, client); | |
| 63 } | |
| 64 | |
| 65 // Suppress FindBugs warning, since |sClient| is only used on the UI thread. | 42 // Suppress FindBugs warning, since |sClient| is only used on the UI thread. |
| 66 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") | 43 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") |
| 67 public void destroy() { | 44 public void destroy() { |
| 68 if (sClient != null) { | 45 if (sClient != null) { |
| 69 disconnectFromHost(); | 46 disconnectFromHost(); |
| 70 nativeDestroy(mNativeJniClient); | 47 nativeDestroy(mNativeJniClient); |
| 71 sClient = null; | 48 sClient = null; |
| 72 } | 49 } |
| 73 } | 50 } |
| 74 | 51 |
| 52 public void setRenderStub(RenderStub stub) { | |
| 53 mRenderStub = stub; | |
|
Hzj_jie
2016/09/10 02:06:32
Add Preconditions here. If I have made a mistake,
Yuwei
2016/09/12 18:56:14
Done.
BTW why is the Precondition implemented by
Hzj_jie
2016/09/12 21:28:04
In Java, assertions take effect only with -ea opti
Yuwei
2016/09/12 21:50:04
Acknowledged.
| |
| 54 } | |
| 55 | |
| 56 public RenderStub getRenderStub() { | |
|
Hzj_jie
2016/09/10 02:06:32
And here.
Yuwei
2016/09/12 18:56:14
Done.
| |
| 57 return mRenderStub; | |
| 58 } | |
| 59 | |
| 75 /** Returns the current Client instance, or null. */ | 60 /** Returns the current Client instance, or null. */ |
| 76 public static Client getInstance() { | 61 public static Client getInstance() { |
|
Hzj_jie
2016/09/10 02:06:32
Suggest to add a Preconditions.notNull here, and u
Yuwei
2016/09/12 18:56:13
I think it may make more sense to check it in Desk
Hzj_jie
2016/09/12 21:28:04
Yes, both OK.
| |
| 77 return sClient; | 62 return sClient; |
| 78 } | 63 } |
| 79 | 64 |
| 80 /** Used for authentication-related UX during connection. */ | 65 /** Used for authentication-related UX during connection. */ |
| 81 private SessionAuthenticator mAuthenticator; | 66 private SessionAuthenticator mAuthenticator; |
| 82 | 67 |
| 83 /** Whether the native code is attempting a connection. */ | 68 /** Whether the native code is attempting a connection. */ |
| 84 private boolean mConnected; | 69 private boolean mConnected; |
| 85 | 70 |
| 86 /** Notified upon successful connection or disconnection. */ | 71 /** Notified upon successful connection or disconnection. */ |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 /** Passes touch event information to the native handling code. */ | 323 /** Passes touch event information to the native handling code. */ |
| 339 private native void nativeSendTouchEvent( | 324 private native void nativeSendTouchEvent( |
| 340 long nativeJniClient, int eventType, TouchEventData[] data); | 325 long nativeJniClient, int eventType, TouchEventData[] data); |
| 341 | 326 |
| 342 /** Native implementation of Client.enableVideoChannel() */ | 327 /** Native implementation of Client.enableVideoChannel() */ |
| 343 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e nable); | 328 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e nable); |
| 344 | 329 |
| 345 /** Passes extension message to the native code. */ | 330 /** Passes extension message to the native code. */ |
| 346 private native void nativeSendExtensionMessage(long nativeJniClient, String type, String data); | 331 private native void nativeSendExtensionMessage(long nativeJniClient, String type, String data); |
| 347 } | 332 } |
| OLD | NEW |