Chromium Code Reviews| OLD | NEW |
|---|---|
| (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"; | |
| 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, | |
|
garykac
2013/07/15 21:13:42
align args
solb
2013/07/15 21:49:42
Done.
| |
| 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 return session_; | |
| 66 } | |
| 67 | |
| 68 // Notifies the user that the connection status has changed. | |
| 69 void ReportConnectionStatus(protocol::ConnectionToHost::State state, | |
| 70 protocol::ErrorCode error); | |
| 71 | |
| 72 // Pops up a dialog box asking the user to enter a PIN. | |
| 73 void DisplayAuthenticationPrompt(); | |
| 74 | |
| 75 private: | |
| 76 ChromotingJNI(); | |
| 77 | |
| 78 // Forces a Disconnect() in case there is any active or failed connection, | |
| 79 // then proceeds to tear down the Chromium | |
| 80 // DisconnectFromHost() before this singleton is destroyed. Because | |
|
garykac
2013/07/15 21:13:42
Chromium DisconnectFromHost?
solb
2013/07/15 21:49:42
Find-and-replace fail. Thanks for finding it!
| |
| 81 // destruction only occurs at application exit after all connections have | |
| 82 // terminated, it is safe to make unretained cross-thread calls on the class. | |
| 83 virtual ~ChromotingJNI(); | |
| 84 | |
| 85 // Reference to the Java class into which we make JNI calls. | |
| 86 jclass class_; | |
| 87 | |
| 88 // Used by the Chromium libraries to clean up the base and net libraries' JNI | |
| 89 // bindings. It must persist for the lifetime of the singleton. | |
| 90 scoped_ptr<base::AtExitManager> collector_; | |
| 91 | |
| 92 // Chromium code's connection to the Java message loop. | |
| 93 scoped_ptr<base::MessageLoopForUI> ui_loop_; | |
| 94 | |
| 95 // Runners that allow posting tasks to the various native threads. | |
| 96 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | |
| 97 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | |
| 98 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; | |
| 99 | |
| 100 scoped_refptr<net::URLRequestContextGetter> url_requester_; | |
| 101 | |
| 102 // Contains all connection-specific state. | |
| 103 scoped_refptr<ChromotingJNIInstance> session_; | |
| 104 | |
| 105 friend struct DefaultSingletonTraits<ChromotingJNI>; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(ChromotingJNI); | |
| 108 }; | |
| 109 | |
| 110 } // namespace remoting | |
| 111 | |
| 112 #endif | |
| OLD | NEW |