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

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

Issue 19253003: Separate singleton out of ChromotingJNIInstance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move constants into anonymous namespaces 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 | « no previous file | 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/protocol/connection_to_host.h"
14
15 template<typename T> struct DefaultSingletonTraits;
16
17 namespace remoting {
18 class ChromotingJniInstance;
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.
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. Must only be called when
47 // |session_| is null (i.e. before any other call to Connect() or following
48 // a 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 private:
74 ChromotingJni();
75
76 // Forces a DisconnectFromHost() in case there is any active or failed
77 // connection, then proceeds to tear down the Chromium dependencies on which
78 // all sessions depended. Because destruction only occurs at application exit
79 // after all connections have terminated, it is safe to make unretained
80 // cross-thread calls on the class.
81 virtual ~ChromotingJni();
82
83 // Reference to the Java class into which we make JNI calls.
84 jclass class_;
85
86 // Used by the Chromium libraries to clean up the base and net libraries' JNI
87 // bindings. It must persist for the lifetime of the singleton.
88 scoped_ptr<base::AtExitManager> at_exit_manager_;
89
90 // Chromium code's connection to the Java message loop.
91 scoped_ptr<base::MessageLoopForUI> ui_loop_;
92
93 // References to native threads.
94 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
95 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
96 scoped_refptr<AutoThreadTaskRunner> display_task_runner_;
97
98 scoped_refptr<net::URLRequestContextGetter> url_requester_;
99
100 // Contains all connection-specific state.
101 scoped_refptr<ChromotingJniInstance> session_;
102
103 friend struct DefaultSingletonTraits<ChromotingJni>;
104
105 DISALLOW_COPY_AND_ASSIGN(ChromotingJni);
106 };
107
108 } // namespace remoting
109
110 #endif
OLDNEW
« no previous file with comments | « no previous file | remoting/client/jni/chromoting_jni.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698