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

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: Add missing checks and fix class names' CamelCase 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
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 // Class and package name of the Java class supporting the methods we call.
21 const char* const JAVA_CLASS = "org/chromium/chromoting/jni/JNIInterface";
Wez 2013/07/16 13:46:56 Does this need to be in the header? Where else is
solb 2013/07/16 19:23:02 Done.
22
23 // Houses the global resources on which the Chromoting components run
24 // (e.g. message loops and task runners). Proxies outgoing JNI calls from its
25 // ChromotingJniInstance member to Java. All its methods should be invoked
26 // exclusively from the UI thread.
27 class ChromotingJni {
28 public:
29 // This class is instantiated at process initialization and persists until
30 // we close. Its components are reused across |ChromotingJniInstance|s.
31 static ChromotingJni* GetInstance();
32
33 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() {
34 return ui_task_runner_;
35 }
36
37 scoped_refptr<AutoThreadTaskRunner> network_task_runner() {
38 return network_task_runner_;
39 }
40
41 scoped_refptr<AutoThreadTaskRunner> display_task_runner() {
42 return display_task_runner_;
43 }
44
45 scoped_refptr<net::URLRequestContextGetter> url_requester() {
46 return url_requester_;
47 }
48
49 // Initiates a connection with the specified host. Must only be called when
50 // |session| is null (i.e. before any other call to Connect() or following
51 // a call to Disconnect()).
52 void ConnectToHost(const char* username,
53 const char* auth_token,
54 const char* host_jid,
55 const char* host_id,
56 const char* host_pubkey);
57
58 // Terminates any ongoing connection attempt and cleans up by nullifying
59 // |session|. This is a no-op unless |session| is currently non-null.
60 void DisconnectFromHost();
61
62 // Returns the client for the currently-active session, or null if no
63 // connection attempt has been initiated.
64 scoped_refptr<ChromotingJniInstance> session() {
65 DCHECK(session_);
Wez 2013/07/16 13:46:56 This will check if no connection attempt has been
solb 2013/07/16 19:23:02 Done.
66 return session_;
67 }
68
69 // Notifies the user that the connection status has changed.
70 void ReportConnectionStatus(protocol::ConnectionToHost::State state,
71 protocol::ErrorCode error);
72
73 // Pops up a dialog box asking the user to enter a PIN.
74 void DisplayAuthenticationPrompt();
75
76 private:
77 ChromotingJni();
78
79 // Forces a DisconnectFromHost() in case there is any active or failed
80 // connection, then proceeds to tear down the Chromium dependencies on which
81 // all sessions depended. Because destruction only occurs at application exit
82 // after all connections have terminated, it is safe to make unretained
83 // cross-thread calls on the class.
84 virtual ~ChromotingJni();
85
86 // Reference to the Java class into which we make JNI calls.
87 jclass class_;
88
89 // Used by the Chromium libraries to clean up the base and net libraries' JNI
90 // bindings. It must persist for the lifetime of the singleton.
91 scoped_ptr<base::AtExitManager> collector_;
Wez 2013/07/16 13:46:56 nit: at_exit_manager_
solb 2013/07/16 19:23:02 Done.
92
93 // Chromium code's connection to the Java message loop.
94 scoped_ptr<base::MessageLoopForUI> ui_loop_;
95
96 // Runners that allow posting tasks to the various native threads.
Wez 2013/07/16 13:46:56 nit: Suggest: "References to native threads."
solb 2013/07/16 19:23:02 Done.
97 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
98 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
99 scoped_refptr<AutoThreadTaskRunner> display_task_runner_;
100
101 scoped_refptr<net::URLRequestContextGetter> url_requester_;
102
103 // Contains all connection-specific state.
104 scoped_refptr<ChromotingJniInstance> session_;
Wez 2013/07/16 13:46:56 nit: session_ -> instance_
solb 2013/07/16 19:23:02 I believe this would make things less clear; |inst
105
106 friend struct DefaultSingletonTraits<ChromotingJni>;
107
108 DISALLOW_COPY_AND_ASSIGN(ChromotingJni);
109 };
110
111 } // namespace remoting
112
113 #endif
OLDNEW
« no previous file with comments | « no previous file | remoting/client/jni/chromoting_jni.cc » ('j') | remoting/client/jni/chromoting_jni.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698