| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_H_ |
| 6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_H_ | 6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "net/url_request/url_request_context_getter.h" | 13 #include "net/url_request/url_request_context_getter.h" |
| 14 #include "remoting/base/auto_thread.h" | 14 #include "remoting/base/auto_thread.h" |
| 15 #include "remoting/client/chromoting_client_runtime.h" | |
| 16 #include "remoting/client/jni/chromoting_jni_instance.h" | 15 #include "remoting/client/jni/chromoting_jni_instance.h" |
| 17 #include "remoting/protocol/connection_to_host.h" | 16 #include "remoting/protocol/connection_to_host.h" |
| 18 | 17 |
| 19 namespace base { | 18 namespace base { |
| 20 template<typename T> struct DefaultSingletonTraits; | 19 template<typename T> struct DefaultSingletonTraits; |
| 21 } | 20 } |
| 22 | 21 |
| 23 namespace remoting { | 22 namespace remoting { |
| 24 | 23 |
| 25 bool RegisterChromotingJniRuntime(JNIEnv* env); | 24 bool RegisterChromotingJniRuntime(JNIEnv* env); |
| 26 | 25 |
| 27 // Houses the global resources on which the Chromoting components run | 26 // Houses the global resources on which the Chromoting components run |
| 28 // (e.g. message loops and task runners). Proxies outgoing JNI calls from its | 27 // (e.g. message loops and task runners). Proxies outgoing JNI calls from its |
| 29 // ChromotingJniInstance member to Java. All its methods should be invoked | 28 // ChromotingJniInstance member to Java. All its methods should be invoked |
| 30 // exclusively from the UI thread unless otherwise noted. | 29 // exclusively from the UI thread unless otherwise noted. |
| 31 class ChromotingJniRuntime { | 30 class ChromotingJniRuntime { |
| 32 public: | 31 public: |
| 33 // This class is instantiated at process initialization and persists until | 32 // This class is instantiated at process initialization and persists until |
| 34 // we close. Its components are reused across |ChromotingJniInstance|s. | 33 // we close. Its components are reused across |ChromotingJniInstance|s. |
| 35 static ChromotingJniRuntime* GetInstance(); | 34 static ChromotingJniRuntime* GetInstance(); |
| 36 | 35 |
| 37 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { | 36 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { |
| 38 return runtime_->ui_task_runner(); | 37 return ui_task_runner_; |
| 39 } | 38 } |
| 40 | 39 |
| 41 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { | 40 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { |
| 42 return runtime_->network_task_runner(); | 41 return network_task_runner_; |
| 43 } | 42 } |
| 44 | 43 |
| 45 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { | 44 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { |
| 46 return runtime_->display_task_runner(); | 45 return display_task_runner_; |
| 47 } | 46 } |
| 48 | 47 |
| 49 scoped_refptr<net::URLRequestContextGetter> url_requester() { | 48 scoped_refptr<net::URLRequestContextGetter> url_requester() { |
| 50 return runtime_->url_requester(); | 49 return url_requester_; |
| 51 } | 50 } |
| 52 | 51 |
| 53 // Initiates a connection with the specified host. Only call when a host | 52 // Initiates a connection with the specified host. Only call when a host |
| 54 // connection is active (i.e. between a call to Connect() and the | 53 // connection is active (i.e. between a call to Connect() and the |
| 55 // corresponding call to Disconnect()). To skip the attempt at pair-based | 54 // corresponding call to Disconnect()). To skip the attempt at pair-based |
| 56 // authentication, leave |pairing_id| and |pairing_secret| as empty strings. | 55 // authentication, leave |pairing_id| and |pairing_secret| as empty strings. |
| 57 void ConnectToHost(const std::string& username, | 56 void ConnectToHost(const std::string& username, |
| 58 const std::string& auth_token, | 57 const std::string& auth_token, |
| 59 const std::string& host_jid, | 58 const std::string& host_jid, |
| 60 const std::string& host_id, | 59 const std::string& host_id, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // Forces a DisconnectFromHost() in case there is any active or failed | 119 // Forces a DisconnectFromHost() in case there is any active or failed |
| 121 // connection, then proceeds to tear down the Chromium dependencies on which | 120 // connection, then proceeds to tear down the Chromium dependencies on which |
| 122 // all sessions depended. Because destruction only occurs at application exit | 121 // all sessions depended. Because destruction only occurs at application exit |
| 123 // after all connections have terminated, it is safe to make unretained | 122 // after all connections have terminated, it is safe to make unretained |
| 124 // cross-thread calls on the class. | 123 // cross-thread calls on the class. |
| 125 virtual ~ChromotingJniRuntime(); | 124 virtual ~ChromotingJniRuntime(); |
| 126 | 125 |
| 127 // Detaches JVM from the current thread, then signals. Doesn't own |waiter|. | 126 // Detaches JVM from the current thread, then signals. Doesn't own |waiter|. |
| 128 void DetachFromVmAndSignal(base::WaitableEvent* waiter); | 127 void DetachFromVmAndSignal(base::WaitableEvent* waiter); |
| 129 | 128 |
| 130 // Chromium code's connection to the app message loop. Once created the | 129 // Chromium code's connection to the Java message loop. |
| 131 // MessageLoop will live for the life of the program. | |
| 132 scoped_ptr<base::MessageLoopForUI> ui_loop_; | 130 scoped_ptr<base::MessageLoopForUI> ui_loop_; |
| 133 | 131 |
| 134 // Contains threads. | 132 // References to native threads. |
| 135 // | 133 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
| 136 scoped_ptr<ChromotingClientRuntime> runtime_; | 134 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
| 135 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; |
| 136 |
| 137 scoped_refptr<net::URLRequestContextGetter> url_requester_; |
| 137 | 138 |
| 138 // Contains all connection-specific state. | 139 // Contains all connection-specific state. |
| 139 scoped_refptr<ChromotingJniInstance> session_; | 140 scoped_refptr<ChromotingJniInstance> session_; |
| 140 | 141 |
| 141 friend struct base::DefaultSingletonTraits<ChromotingJniRuntime>; | 142 friend struct base::DefaultSingletonTraits<ChromotingJniRuntime>; |
| 142 | 143 |
| 143 DISALLOW_COPY_AND_ASSIGN(ChromotingJniRuntime); | 144 DISALLOW_COPY_AND_ASSIGN(ChromotingJniRuntime); |
| 144 }; | 145 }; |
| 145 | 146 |
| 146 } // namespace remoting | 147 } // namespace remoting |
| 147 | 148 |
| 148 #endif | 149 #endif |
| OLD | NEW |