OLD | NEW |
---|---|
1 // Copyright 2013 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 #ifndef REMOTING_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_H_ | 5 #ifndef REMOTING_IOS_BRIDGE_CLIENT_BRIDGE_H_ |
6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_H_ | 6 #define REMOTING_IOS_BRIDGE_CLIENT_BRDIGE_H_ |
7 | 7 |
8 #include <jni.h> | |
9 #include <string> | 8 #include <string> |
10 | 9 |
11 #include "base/android/scoped_java_ref.h" | 10 #include "base/memory/ref_counted.h" |
12 #include "base/at_exit.h" | 11 #include "base/message_loop/message_loop.h" |
13 #include "net/url_request/url_request_context_getter.h" | 12 #include "net/url_request/url_request_context_getter.h" |
14 #include "remoting/base/auto_thread.h" | 13 #include "remoting/base/auto_thread.h" |
15 #include "remoting/client/jni/chromoting_jni_instance.h" | |
16 #include "remoting/protocol/connection_to_host.h" | 14 #include "remoting/protocol/connection_to_host.h" |
15 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | |
17 | 16 |
18 template<typename T> struct DefaultSingletonTraits; | 17 #include "remoting/ios/bridge/client_instance.h" |
18 #include "remoting/ios/bridge/frame_consumer_bridge_callback.h" | |
19 | |
20 #if defined(__OBJC__) | |
21 @class ClientController; | |
22 #else // __OBJC__ | |
23 class ClientController; | |
24 #endif // __OBJC__ | |
19 | 25 |
20 namespace remoting { | 26 namespace remoting { |
21 | 27 |
22 bool RegisterJni(JNIEnv* env); | 28 // Houses the global resources on which the Chromoting components run |
29 // (e.g. message loops and task runners). Proxies outgoing OBJ_C calls from its | |
30 // ClientInstance member to C++. All its methods should be invoked | |
31 // exclusively from the UI thread unless otherwise noted. | |
32 class ClientBridge : public base::RefCounted<ClientBridge> { | |
dcaiafa
2014/03/19 01:14:15
Does it really need to be ref-counted? I would pre
aboone
2014/03/21 16:42:07
Changed to a SupportWeakPtr<>
| |
33 public: | |
34 ClientBridge(); | |
23 | 35 |
24 // Houses the global resources on which the Chromoting components run | 36 // Forces a DisconnectFromHost() in case there is any active or failed |
25 // (e.g. message loops and task runners). Proxies outgoing JNI calls from its | 37 // connection, then proceeds to tear down the Chromium dependencies on which |
26 // ChromotingJniInstance member to Java. All its methods should be invoked | 38 // all sessions depended. |
27 // exclusively from the UI thread unless otherwise noted. | 39 virtual ~ClientBridge(); |
dcaiafa
2014/03/19 01:14:15
Make destructor private, and friend base::RefCount
aboone
2014/03/21 16:42:07
Requirements after change to using a WeakPtr are d
| |
28 class ChromotingJniRuntime { | |
29 public: | |
30 // This class is instantiated at process initialization and persists until | |
31 // we close. Its components are reused across |ChromotingJniInstance|s. | |
32 static ChromotingJniRuntime* GetInstance(); | |
33 | 40 |
34 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { | 41 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { |
35 return ui_task_runner_; | 42 return ui_task_runner_; |
36 } | 43 } |
37 | 44 |
38 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { | 45 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { |
39 return network_task_runner_; | 46 return network_task_runner_; |
40 } | 47 } |
41 | 48 |
42 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { | |
43 return display_task_runner_; | |
44 } | |
45 | |
46 scoped_refptr<net::URLRequestContextGetter> url_requester() { | 49 scoped_refptr<net::URLRequestContextGetter> url_requester() { |
47 return url_requester_; | 50 return url_requester_; |
48 } | 51 } |
49 | 52 |
50 // Initiates a connection with the specified host. Only call when a host | 53 // Initiates a connection with the specified host. Only call when a host |
51 // connection is active (i.e. between a call to Connect() and the | 54 // connection is active (i.e. between a call to Connect() and the |
52 // corresponding call to Disconnect()). To skip the attempt at pair-based | 55 // corresponding call to Disconnect()). To skip the attempt at pair-based |
53 // authentication, leave |pairing_id| and |pairing_secret| as empty strings. | 56 // authentication, leave |pairing_id| and |pairing_secret| as empty strings. |
54 void ConnectToHost(const char* username, | 57 void ConnectToHost(const char* username, |
55 const char* auth_token, | 58 const char* auth_token, |
56 const char* host_jid, | 59 const char* host_jid, |
57 const char* host_id, | 60 const char* host_id, |
58 const char* host_pubkey, | 61 const char* host_pubkey, |
59 const char* pairing_id, | 62 const char* pairing_id, |
60 const char* pairing_secret); | 63 const char* pairing_secret, |
64 ClientController* controller); | |
61 | 65 |
62 // Terminates any ongoing connection attempt and cleans up by nullifying | 66 // Terminates any ongoing connection attempt and cleans up by nullifying |
63 // |session_|. This is a no-op unless |session| is currently non-null. | 67 // |session_|. This is a no-op unless |session| is currently non-null. |
64 void DisconnectFromHost(); | 68 void DisconnectFromHost(); |
65 | 69 |
66 // Returns the client for the currently-active session. Do not call if | 70 // Returns the client for the currently-active session. Do not call if |
67 // |session| is null. | 71 // |session| is null. |
68 scoped_refptr<ChromotingJniInstance> session() { | 72 scoped_refptr<ClientInstance> session() { |
69 DCHECK(session_); | 73 DCHECK(session_); |
70 return session_; | 74 return session_; |
71 } | 75 } |
72 | 76 |
73 // Notifies the user of the current connection status. Call on UI thread. | 77 // Notifies the user of the current connection status. Call on UI thread. |
74 void ReportConnectionStatus(protocol::ConnectionToHost::State state, | 78 void ReportConnectionStatus(protocol::ConnectionToHost::State state, |
75 protocol::ErrorCode error); | 79 protocol::ErrorCode error); |
76 | 80 |
77 // Pops up a dialog box asking the user to enter a PIN. Call on UI thread. | 81 // Pops up a dialog box asking the user to enter a PIN. Call on UI thread. |
78 void DisplayAuthenticationPrompt(bool pairing_supported); | 82 void DisplayAuthenticationPrompt(bool pairing_supported); |
79 | 83 |
80 // Saves new pairing credentials to permanent storage. Call on UI thread. | 84 // Saves new pairing credentials to permanent storage. Call on UI thread. |
81 void CommitPairingCredentials(const std::string& host, | 85 void CommitPairingCredentials(const std::string& host, |
82 const std::string& id, | 86 const std::string& id, |
83 const std::string& secret); | 87 const std::string& secret); |
84 | 88 |
85 // Creates a new Bitmap object to store a video frame. | |
86 base::android::ScopedJavaLocalRef<jobject> NewBitmap( | |
87 webrtc::DesktopSize size); | |
88 | |
89 // Updates video frame bitmap. |bitmap| must be an instance of | |
90 // android.graphics.Bitmap. Call on the display thread. | |
91 void UpdateFrameBitmap(jobject bitmap); | |
92 | |
93 // Updates cursor shape. Call on display thread. | 89 // Updates cursor shape. Call on display thread. |
dcaiafa
2014/03/19 01:14:15
nit: There doesn't seem to be a display thread lik
aboone
2014/03/21 16:42:07
Done.
| |
94 void UpdateCursorShape(const protocol::CursorShapeInfo& cursor_shape); | 90 void UpdateCursorShape(const protocol::CursorShapeInfo& cursor_shape); |
95 | 91 |
96 // Draws the latest image buffer onto the canvas. Call on the display thread. | 92 // Draws the latest image buffer onto the canvas. Call on the display thread. |
97 void RedrawCanvas(); | 93 void RedrawCanvas(const webrtc::DesktopSize& view_size, |
94 webrtc::DesktopFrame* buffer, | |
95 const webrtc::DesktopRegion& region); | |
96 | |
97 FrameConsumerBridgeCallback BindToFrameConsumerBridgeCallback(); | |
98 | 98 |
99 private: | 99 private: |
100 ChromotingJniRuntime(); | 100 // Detaches OBJ_C from the current thread, then signals. Doesn't own |waiter|. |
101 | |
102 // Forces a DisconnectFromHost() in case there is any active or failed | |
103 // connection, then proceeds to tear down the Chromium dependencies on which | |
104 // all sessions depended. Because destruction only occurs at application exit | |
105 // after all connections have terminated, it is safe to make unretained | |
106 // cross-thread calls on the class. | |
107 virtual ~ChromotingJniRuntime(); | |
108 | |
109 // Detaches JVM from the current thread, then signals. Doesn't own |waiter|. | |
110 void DetachFromVmAndSignal(base::WaitableEvent* waiter); | 101 void DetachFromVmAndSignal(base::WaitableEvent* waiter); |
111 | 102 |
112 // Used by the Chromium libraries to clean up the base and net libraries' JNI | 103 // Chromium code's connection to the OBJ_C message loop. |
113 // bindings. It must persist for the lifetime of the singleton. | |
114 scoped_ptr<base::AtExitManager> at_exit_manager_; | |
115 | |
116 // Chromium code's connection to the Java message loop. | |
117 scoped_ptr<base::MessageLoopForUI> ui_loop_; | 104 scoped_ptr<base::MessageLoopForUI> ui_loop_; |
118 | 105 |
119 // References to native threads. | 106 // References to native threads. |
120 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 107 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
121 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | 108 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
122 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; | |
123 | 109 |
124 scoped_refptr<net::URLRequestContextGetter> url_requester_; | 110 scoped_refptr<net::URLRequestContextGetter> url_requester_; |
125 | 111 |
126 // Contains all connection-specific state. | 112 // Contains connection-specific state. |
127 scoped_refptr<ChromotingJniInstance> session_; | 113 scoped_refptr<ClientInstance> session_; |
128 | 114 |
129 friend struct DefaultSingletonTraits<ChromotingJniRuntime>; | 115 // Ponter to the OBJ_C side of the bridge |
116 ClientController* controller_; | |
130 | 117 |
131 DISALLOW_COPY_AND_ASSIGN(ChromotingJniRuntime); | 118 DISALLOW_COPY_AND_ASSIGN(ClientBridge); |
132 }; | 119 }; |
133 | 120 |
134 } // namespace remoting | 121 } // namespace remoting |
135 | 122 |
136 #endif | 123 #endif // REMOTING_IOS_BRIDGE_CLIENT_BRDIGE_H_ |
OLD | NEW |