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_RUNTIME_H_ | |
6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_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> struct DefaultSingletonTraits; | |
22 } | |
23 | |
24 namespace remoting { | |
25 | |
26 bool RegisterChromotingJniRuntime(JNIEnv* env); | |
27 | |
28 // Houses the global resources on which the Chromoting components run | |
29 // (e.g. message loops and task runners). Proxies outgoing JNI calls from its | |
30 // ChromotingJniInstance member to Java. All its methods should be invoked | |
31 // exclusively from the UI thread unless otherwise noted. | |
32 class ChromotingJniRuntime { | |
33 public: | |
34 // This class is instantiated at process initialization and persists until | |
35 // we close. Its components are reused across |ChromotingJniInstance|s. | |
36 static ChromotingJniRuntime* GetInstance(); | |
37 | |
38 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { | |
39 return runtime_->ui_task_runner(); | |
40 } | |
41 | |
42 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { | |
43 return runtime_->network_task_runner(); | |
44 } | |
45 | |
46 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { | |
47 return runtime_->display_task_runner(); | |
48 } | |
49 | |
50 scoped_refptr<net::URLRequestContextGetter> url_requester() { | |
51 return runtime_->url_requester(); | |
52 } | |
53 | |
54 // Returns the log writer that can be used by ClientTelemetryLogger to send | |
55 // out logs. | |
56 // Method must be called and returned object must be used on the network | |
57 // thread. | |
58 TelemetryLogWriter* GetLogWriter(); | |
59 | |
60 // Fetch OAuth token for the telemetry logger. Call on UI thread. | |
61 void FetchAuthToken(); | |
62 | |
63 private: | |
64 ChromotingJniRuntime(); | |
65 | |
66 // Forces a DisconnectFromHost() in case there is any active or failed | |
67 // connection, then proceeds to tear down the Chromium dependencies on which | |
68 // all sessions depended. Because destruction only occurs at application exit | |
69 // after all connections have terminated, it is safe to make unretained | |
70 // cross-thread calls on the class. | |
71 virtual ~ChromotingJniRuntime(); | |
72 | |
73 // Detaches JVM from the current thread, then signals. Doesn't own |waiter|. | |
74 void DetachFromVmAndSignal(base::WaitableEvent* waiter); | |
75 | |
76 // Starts the logger on the network thread. | |
77 void StartLoggerOnNetworkThread(); | |
78 | |
79 // Chromium code's connection to the app message loop. Once created the | |
80 // MessageLoop will live for the life of the program. | |
81 std::unique_ptr<base::MessageLoopForUI> ui_loop_; | |
82 | |
83 // Contains threads. | |
84 // | |
85 std::unique_ptr<ChromotingClientRuntime> runtime_; | |
86 | |
87 // For logging session stage changes and stats. | |
88 std::unique_ptr<TelemetryLogWriter> log_writer_; | |
89 | |
90 friend struct base::DefaultSingletonTraits<ChromotingJniRuntime>; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(ChromotingJniRuntime); | |
93 }; | |
94 | |
95 } // namespace remoting | |
96 | |
97 #endif | |
OLD | NEW |