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