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_JNI_RUNTIME_DELEGATE_H_ |
| 6 #define REMOTING_CLIENT_JNI_JNI_RUNTIME_DELEGATE_H_ |
| 7 |
| 8 #include <jni.h> |
| 9 #include <string> |
| 10 |
| 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/macros.h" |
| 13 #include "net/url_request/url_request_context_getter.h" |
| 14 #include "remoting/base/auto_thread.h" |
| 15 #include "remoting/base/telemetry_log_writer.h" |
| 16 #include "remoting/client/chromoting_client_runtime.h" |
| 17 #include "remoting/client/jni/chromoting_jni_instance.h" |
| 18 #include "remoting/protocol/connection_to_host.h" |
| 19 |
| 20 namespace base { |
| 21 template <typename T> |
| 22 struct DefaultSingletonTraits; |
| 23 } |
| 24 |
| 25 namespace remoting { |
| 26 |
| 27 bool RegisterJniRuntimeDelegate(JNIEnv* env); |
| 28 |
| 29 // JniRuntimeDelegate is a singleton that hooks into delegate role for |
| 30 // the ChromotingClientRuntime object. This class handles Android specific |
| 31 // integrations for the runtime. Proxies outgoing JNI calls from |
| 32 // ChromotingClientRuntime to Java. All its methods should be invoked |
| 33 // exclusively from the UI thread unless otherwise noted. |
| 34 class JniRuntimeDelegate : public ChromotingClientRuntime::Delegate { |
| 35 public: |
| 36 // This class is instantiated at process initialization and persists until |
| 37 // we close. Its components are reused across |JniRuntimeDelegate|s. |
| 38 static JniRuntimeDelegate* GetInstance(); |
| 39 |
| 40 // Fetch OAuth token for the telemetry logger. Call on UI thread. |
| 41 void FetchAuthToken(); |
| 42 |
| 43 // remoting::ChromotingClientRuntime::Delegate overrides. |
| 44 void RuntimeWillShutdown() override; |
| 45 void RuntimeDidShutdown() override; |
| 46 void RequestAuthTokenForLogger() override; |
| 47 |
| 48 private: |
| 49 JniRuntimeDelegate(); |
| 50 |
| 51 // Forces a DisconnectFromHost() in case there is any active or failed |
| 52 // connection, then proceeds to tear down the Chromium dependencies on which |
| 53 // all sessions depended. Because destruction only occurs at application exit |
| 54 // after all connections have terminated, it is safe to make unretained |
| 55 // cross-thread calls on the class. |
| 56 ~JniRuntimeDelegate() override; |
| 57 |
| 58 // Detaches JVM from the current thread, then signals. Doesn't own |waiter|. |
| 59 void DetachFromVmAndSignal(base::WaitableEvent* waiter); |
| 60 |
| 61 ChromotingClientRuntime* runtime_; |
| 62 |
| 63 friend struct base::DefaultSingletonTraits<JniRuntimeDelegate>; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(JniRuntimeDelegate); |
| 66 }; |
| 67 |
| 68 } // namespace remoting |
| 69 |
| 70 #endif // REMOTING_CLIENT_JNI_JNI_RUNTIME_DELEGATE_H_ |
OLD | NEW |