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

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

Issue 1687873002: Revert of Refactor Chromoting JNI code to use jni/Client (Java changes only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | remoting/android/java/src/org/chromium/chromoting/Chromoting.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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; 5 package org.chromium.chromoting;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.text.TextUtils; 8 import android.text.TextUtils;
9 9
10 import org.chromium.base.Log; 10 import org.chromium.base.Log;
11 11
12 import java.util.ArrayList; 12 import java.util.ArrayList;
13 import java.util.Arrays; 13 import java.util.Arrays;
14 import java.util.List; 14 import java.util.List;
15 15
16 /** 16 /**
17 * A manager for the capabilities of the Android client. Based on the negotiated set of 17 * A manager for the capabilities of the Android client. Based on the negotiated set of
18 * capabilities, it creates the associated ClientExtensions, and enables their c ommunication with 18 * capabilities, it creates the associated ClientExtensions, and enables their c ommunication with
19 * the Chromoting host by dispatching extension messages appropriately. 19 * the Chromoting host by dispatching extension messages appropriately.
20 * 20 *
21 * The CapabilityManager mirrors how the Chromoting host handles extension messa ges. For each 21 * The CapabilityManager mirrors how the Chromoting host handles extension messa ges. For each
22 * incoming extension message, runs through a list of HostExtensionSession objec ts, giving each one 22 * incoming extension message, runs through a list of HostExtensionSession objec ts, giving each one
23 * a chance to handle the message. 23 * a chance to handle the message.
24 *
25 * The CapabilityManager is a singleton class so we can manage client extensions on an application
26 * level. The singleton object may be used from multiple Activities, thus allowi ng it to support
27 * different capabilities at different stages of the application.
24 */ 28 */
25 public class CapabilityManager { 29 public class CapabilityManager {
26 /** Used to allow objects to receive notifications when the host capabilites are received. */ 30 /** Used to allow objects to receive notifications when the host capabilites are received. */
27 public interface CapabilitiesChangedListener { 31 public interface CapabilitiesChangedListener {
28 void onCapabilitiesChanged(List<String> newCapabilities); 32 void onCapabilitiesChanged(List<String> newCapabilities);
29 } 33 }
30 34
31 /** Tracks whether the remote host supports a capability. */ 35 /** Tracks whether the remote host supports a capability. */
32 public enum HostCapability { 36 public enum HostCapability {
33 UNKNOWN, 37 UNKNOWN,
34 SUPPORTED, 38 SUPPORTED,
35 UNSUPPORTED; 39 UNSUPPORTED;
36 40
37 public boolean isSet() { 41 public boolean isSet() {
38 return this != UNKNOWN; 42 return this != UNKNOWN;
39 } 43 }
40 44
41 public boolean isSupported() { 45 public boolean isSupported() {
42 assert isSet(); 46 assert isSet();
43 return this == SUPPORTED; 47 return this == SUPPORTED;
44 } 48 }
45 } 49 }
46 50
47 private static final String TAG = "Chromoting"; 51 private static final String TAG = "Chromoting";
48 52
53 /** Lazily-initialized singleton object that can be used from different Acti vities. */
54 private static CapabilityManager sInstance;
55
56 /** Protects access to |sInstance|. */
57 private static final Object sInstanceLock = new Object();
58
49 /** List of all capabilities that are supported by the application. */ 59 /** List of all capabilities that are supported by the application. */
50 private List<String> mLocalCapabilities; 60 private List<String> mLocalCapabilities;
51 61
52 /** List of negotiated capabilities received from the host. */ 62 /** List of negotiated capabilities received from the host. */
53 private List<String> mNegotiatedCapabilities; 63 private List<String> mNegotiatedCapabilities;
54 64
55 /** List of extensions to the client based on capabilities negotiated with t he host. */ 65 /** List of extensions to the client based on capabilities negotiated with t he host. */
56 private List<ClientExtension> mClientExtensions; 66 private List<ClientExtension> mClientExtensions;
57 67
58 /** Maintains a list of listeners to notify when host capabilities are recei ved. */ 68 /** Maintains a list of listeners to notify when host capabilities are recei ved. */
59 private List<CapabilitiesChangedListener> mCapabilitiesChangedListeners; 69 private List<CapabilitiesChangedListener> mCapabilitiesChangedListeners;
60 70
61 public CapabilityManager() { 71 private CapabilityManager() {
62 mLocalCapabilities = new ArrayList<String>(); 72 mLocalCapabilities = new ArrayList<String>();
63 mClientExtensions = new ArrayList<ClientExtension>(); 73 mClientExtensions = new ArrayList<ClientExtension>();
64 74
65 mLocalCapabilities.add(Capabilities.CAST_CAPABILITY); 75 mLocalCapabilities.add(Capabilities.CAST_CAPABILITY);
66 mLocalCapabilities.add(Capabilities.TOUCH_CAPABILITY); 76 mLocalCapabilities.add(Capabilities.TOUCH_CAPABILITY);
67 77
68 mCapabilitiesChangedListeners = new ArrayList<CapabilitiesChangedListene r>(); 78 mCapabilitiesChangedListeners = new ArrayList<CapabilitiesChangedListene r>();
69 } 79 }
70 80
71 /** 81 /**
82 * Returns the singleton object. Thread-safe.
83 */
84 public static CapabilityManager getInstance() {
85 synchronized (sInstanceLock) {
86 if (sInstance == null) {
87 sInstance = new CapabilityManager();
88 }
89 return sInstance;
90 }
91 }
92
93 /**
72 * Cleans up host specific state when the connection has been terminated. 94 * Cleans up host specific state when the connection has been terminated.
73 */ 95 */
74 public void onHostDisconnect() { 96 public void onHostDisconnect() {
75 mNegotiatedCapabilities = null; 97 mNegotiatedCapabilities = null;
76 } 98 }
77 99
78 /** 100 /**
79 * Returns a space-separated list (required by host) of the capabilities sup ported by 101 * Returns a space-separated list (required by host) of the capabilities sup ported by
80 * this client. 102 * this client.
81 */ 103 */
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 return new DummyClientExtension(); 214 return new DummyClientExtension();
193 } catch (InstantiationException e) { 215 } catch (InstantiationException e) {
194 Log.w(TAG, "Failed to create CastExtensionHandler."); 216 Log.w(TAG, "Failed to create CastExtensionHandler.");
195 return new DummyClientExtension(); 217 return new DummyClientExtension();
196 } catch (IllegalAccessException e) { 218 } catch (IllegalAccessException e) {
197 Log.w(TAG, "Failed to create CastExtensionHandler."); 219 Log.w(TAG, "Failed to create CastExtensionHandler.");
198 return new DummyClientExtension(); 220 return new DummyClientExtension();
199 } 221 }
200 } 222 }
201 } 223 }
OLDNEW
« no previous file with comments | « no previous file | remoting/android/java/src/org/chromium/chromoting/Chromoting.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698