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

Side by Side Diff: remoting/client/jni/chromoting_jni.h

Issue 19967007: Various improvements to the Chromoting Android app (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comments to clarify ChromotingJniRuntime pointer lifetimes Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « remoting/android/java/AndroidManifest.xml ('k') | remoting/client/jni/chromoting_jni.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef REMOTING_CLIENT_JNI_CHROMOTING_JNI_H_
6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_H_
7
8 #include <jni.h>
9
10 #include "base/at_exit.h"
11 #include "net/url_request/url_request_context_getter.h"
12 #include "remoting/base/auto_thread.h"
13 #include "remoting/client/jni/chromoting_jni_instance.h"
14 #include "remoting/protocol/connection_to_host.h"
15
16 template<typename T> struct DefaultSingletonTraits;
17
18 namespace remoting {
19
20 // Houses the global resources on which the Chromoting components run
21 // (e.g. message loops and task runners). Proxies outgoing JNI calls from its
22 // ChromotingJniInstance member to Java. All its methods should be invoked
23 // exclusively from the UI thread unless otherwise noted.
24 class ChromotingJni {
25 public:
26 // This class is instantiated at process initialization and persists until
27 // we close. Its components are reused across |ChromotingJniInstance|s.
28 static ChromotingJni* GetInstance();
29
30 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() {
31 return ui_task_runner_;
32 }
33
34 scoped_refptr<AutoThreadTaskRunner> network_task_runner() {
35 return network_task_runner_;
36 }
37
38 scoped_refptr<AutoThreadTaskRunner> display_task_runner() {
39 return display_task_runner_;
40 }
41
42 scoped_refptr<net::URLRequestContextGetter> url_requester() {
43 return url_requester_;
44 }
45
46 // Initiates a connection with the specified host. Only call when a host
47 // connection is active (i.e. between a call to Connect() and the
48 // corresponding call to Disconnect()).
49 void ConnectToHost(const char* username,
50 const char* auth_token,
51 const char* host_jid,
52 const char* host_id,
53 const char* host_pubkey);
54
55 // Terminates any ongoing connection attempt and cleans up by nullifying
56 // |session_|. This is a no-op unless |session| is currently non-null.
57 void DisconnectFromHost();
58
59 // Returns the client for the currently-active session. Do not call if
60 // |session| is null.
61 scoped_refptr<ChromotingJniInstance> session() {
62 DCHECK(session_);
63 return session_;
64 }
65
66 // Notifies the user that the connection status has changed.
67 void ReportConnectionStatus(protocol::ConnectionToHost::State state,
68 protocol::ErrorCode error);
69
70 // Pops up a dialog box asking the user to enter a PIN.
71 void DisplayAuthenticationPrompt();
72
73 // Updates image dimensions and canvas memory space. Call on display thread.
74 void UpdateImageBuffer(int width, int height, jobject buffer);
75
76 // Draws the latest image buffer onto the canvas. Call on the display thread.
77 void RedrawCanvas();
78
79 private:
80 ChromotingJni();
81
82 // Forces a DisconnectFromHost() in case there is any active or failed
83 // connection, then proceeds to tear down the Chromium dependencies on which
84 // all sessions depended. Because destruction only occurs at application exit
85 // after all connections have terminated, it is safe to make unretained
86 // cross-thread calls on the class.
87 virtual ~ChromotingJni();
88
89 // Reference to the Java class into which we make JNI calls.
90 jclass class_;
91
92 // Used by the Chromium libraries to clean up the base and net libraries' JNI
93 // bindings. It must persist for the lifetime of the singleton.
94 scoped_ptr<base::AtExitManager> at_exit_manager_;
95
96 // Chromium code's connection to the Java message loop.
97 scoped_ptr<base::MessageLoopForUI> ui_loop_;
98
99 // References to native threads.
100 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
101 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
102 scoped_refptr<AutoThreadTaskRunner> display_task_runner_;
103
104 scoped_refptr<net::URLRequestContextGetter> url_requester_;
105
106 // Contains all connection-specific state.
107 scoped_refptr<ChromotingJniInstance> session_;
108
109 friend struct DefaultSingletonTraits<ChromotingJni>;
110
111 DISALLOW_COPY_AND_ASSIGN(ChromotingJni);
112 };
113
114 } // namespace remoting
115
116 #endif
OLDNEW
« no previous file with comments | « remoting/android/java/AndroidManifest.xml ('k') | remoting/client/jni/chromoting_jni.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698