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.Preconditions; |
| 13 import org.chromium.chromoting.RenderStub; | |
| 18 import org.chromium.chromoting.SessionAuthenticator; | 14 import org.chromium.chromoting.SessionAuthenticator; |
| 19 | 15 |
| 20 /** | 16 /** |
| 21 * Class to manage a client connection to the host. This class controls the life time of the | 17 * 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 | 18 * 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 | 19 * each connection to the host, so that notifications from a connection are alwa ys sent to the |
| 24 * right object. | 20 * right object. |
| 25 * This class is used entirely on the UI thread. | 21 * This class is used entirely on the UI thread. |
| 26 */ | 22 */ |
| 27 @JNINamespace("remoting") | 23 @JNINamespace("remoting") |
| 28 public class Client implements InputStub { | 24 public class Client implements InputStub { |
| 29 // Pointer to the C++ object, cast to a |long|. | 25 // Pointer to the C++ object, cast to a |long|. |
| 30 private long mNativeJniClient; | 26 private final long mNativeJniClient; |
| 31 | 27 |
| 32 // The factory to create implementation-dependent desktop view. | 28 private RenderStub mRenderStub; |
| 33 private DesktopViewFactory mDesktopViewFactory; | |
| 34 | 29 |
| 35 // The global Client instance (may be null). This needs to be a global singl eton so that the | 30 // 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. | 31 // Client can be passed between Activities. |
| 37 private static Client sClient; | 32 private static Client sClient; |
| 38 | 33 |
| 39 public Client() { | 34 public Client() { |
| 40 if (sClient != null) { | 35 if (sClient != null) { |
| 41 throw new RuntimeException("Client instance already created."); | 36 throw new RuntimeException("Client instance already created."); |
| 42 } | 37 } |
| 43 | 38 |
| 44 sClient = this; | 39 sClient = this; |
| 45 mNativeJniClient = nativeInit(); | 40 mNativeJniClient = nativeInit(); |
| 46 } | 41 } |
| 47 | 42 |
| 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. | 43 // Suppress FindBugs warning, since |sClient| is only used on the UI thread. |
| 66 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") | 44 @SuppressFBWarnings("LI_LAZY_INIT_STATIC") |
| 67 public void destroy() { | 45 public void destroy() { |
| 68 if (sClient != null) { | 46 if (sClient != null) { |
| 69 disconnectFromHost(); | 47 disconnectFromHost(); |
| 70 nativeDestroy(mNativeJniClient); | 48 nativeDestroy(mNativeJniClient); |
| 71 sClient = null; | 49 sClient = null; |
| 72 } | 50 } |
| 73 } | 51 } |
| 74 | 52 |
| 53 public void setRenderStub(RenderStub stub) { | |
| 54 Preconditions.isNull(mRenderStub); | |
| 55 Preconditions.notNull(stub); | |
| 56 mRenderStub = stub; | |
| 57 } | |
| 58 | |
| 59 public RenderStub getRenderStub() { | |
| 60 Preconditions.notNull(mRenderStub); | |
|
joedow
2016/09/12 19:55:08
Is this precondition needed? I'm wondering if som
Yuwei
2016/09/12 22:17:58
Removed.
| |
| 61 return mRenderStub; | |
| 62 } | |
| 63 | |
| 75 /** Returns the current Client instance, or null. */ | 64 /** Returns the current Client instance, or null. */ |
| 76 public static Client getInstance() { | 65 public static Client getInstance() { |
| 77 return sClient; | 66 return sClient; |
| 78 } | 67 } |
| 79 | 68 |
| 80 /** Used for authentication-related UX during connection. */ | 69 /** Used for authentication-related UX during connection. */ |
| 81 private SessionAuthenticator mAuthenticator; | 70 private SessionAuthenticator mAuthenticator; |
| 82 | 71 |
| 83 /** Whether the native code is attempting a connection. */ | 72 /** Whether the native code is attempting a connection. */ |
| 84 private boolean mConnected; | 73 private boolean mConnected; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 /** Passes touch event information to the native handling code. */ | 327 /** Passes touch event information to the native handling code. */ |
| 339 private native void nativeSendTouchEvent( | 328 private native void nativeSendTouchEvent( |
| 340 long nativeJniClient, int eventType, TouchEventData[] data); | 329 long nativeJniClient, int eventType, TouchEventData[] data); |
| 341 | 330 |
| 342 /** Native implementation of Client.enableVideoChannel() */ | 331 /** Native implementation of Client.enableVideoChannel() */ |
| 343 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e nable); | 332 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e nable); |
| 344 | 333 |
| 345 /** Passes extension message to the native code. */ | 334 /** Passes extension message to the native code. */ |
| 346 private native void nativeSendExtensionMessage(long nativeJniClient, String type, String data); | 335 private native void nativeSendExtensionMessage(long nativeJniClient, String type, String data); |
| 347 } | 336 } |
| OLD | NEW |