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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/jni/Client.java

Issue 2322623002: [Remoting Android] Refactor GlDesktopView (Closed)
Patch Set: Reviewer's Feedback Created 4 years, 3 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.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 return mRenderStub;
61 }
62
75 /** Returns the current Client instance, or null. */ 63 /** Returns the current Client instance, or null. */
76 public static Client getInstance() { 64 public static Client getInstance() {
77 return sClient; 65 return sClient;
78 } 66 }
79 67
80 /** Used for authentication-related UX during connection. */ 68 /** Used for authentication-related UX during connection. */
81 private SessionAuthenticator mAuthenticator; 69 private SessionAuthenticator mAuthenticator;
82 70
83 /** Whether the native code is attempting a connection. */ 71 /** Whether the native code is attempting a connection. */
84 private boolean mConnected; 72 private boolean mConnected;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 /** Passes touch event information to the native handling code. */ 326 /** Passes touch event information to the native handling code. */
339 private native void nativeSendTouchEvent( 327 private native void nativeSendTouchEvent(
340 long nativeJniClient, int eventType, TouchEventData[] data); 328 long nativeJniClient, int eventType, TouchEventData[] data);
341 329
342 /** Native implementation of Client.enableVideoChannel() */ 330 /** Native implementation of Client.enableVideoChannel() */
343 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e nable); 331 private native void nativeEnableVideoChannel(long nativeJniClient, boolean e nable);
344 332
345 /** Passes extension message to the native code. */ 333 /** Passes extension message to the native code. */
346 private native void nativeSendExtensionMessage(long nativeJniClient, String type, String data); 334 private native void nativeSendExtensionMessage(long nativeJniClient, String type, String data);
347 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698