Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: remoting/client/jni/jni_runtime_delegate.h

Issue 2745583008: Refactoring out the chromoting jni runtime class in favor of chromoting client runtime. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_JNI_RUNTIME_DELEGATE_H_
6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_H_ 6 #define REMOTING_CLIENT_JNI_JNI_RUNTIME_DELEGATE_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/base/telemetry_log_writer.h" 15 #include "remoting/base/telemetry_log_writer.h"
16 #include "remoting/client/chromoting_client_runtime.h" 16 #include "remoting/client/chromoting_client_runtime.h"
17 #include "remoting/client/jni/chromoting_jni_instance.h" 17 #include "remoting/client/jni/chromoting_jni_instance.h"
18 #include "remoting/protocol/connection_to_host.h" 18 #include "remoting/protocol/connection_to_host.h"
19 19
20 namespace base { 20 namespace base {
21 template<typename T> struct DefaultSingletonTraits; 21 template <typename T>
22 struct DefaultSingletonTraits;
22 } 23 }
23 24
24 namespace remoting { 25 namespace remoting {
25 26
26 bool RegisterChromotingJniRuntime(JNIEnv* env); 27 bool RegisterJniRuntimeDelegate(JNIEnv* env);
nicholss 2017/03/10 19:04:28 So for this to work correctly, the JniRuntimeDeleg
27 28
28 // Houses the global resources on which the Chromoting components run 29 // Houses the global resources on which the Chromoting components run
nicholss 2017/03/10 19:04:28 This comment should be updated. Will do.
29 // (e.g. message loops and task runners). Proxies outgoing JNI calls from its 30 // (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 // ChromotingJniInstance member to Java. All its methods should be invoked
31 // exclusively from the UI thread unless otherwise noted. 32 // exclusively from the UI thread unless otherwise noted.
32 class ChromotingJniRuntime { 33 class JniRuntimeDelegate : public ChromotingClientRuntime::Delegate {
33 public: 34 public:
34 // This class is instantiated at process initialization and persists until 35 // This class is instantiated at process initialization and persists until
35 // we close. Its components are reused across |ChromotingJniInstance|s. 36 // we close. Its components are reused across |JniRuntimeDelegate|s.
36 static ChromotingJniRuntime* GetInstance(); 37 static JniRuntimeDelegate* 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 38
60 // Fetch OAuth token for the telemetry logger. Call on UI thread. 39 // Fetch OAuth token for the telemetry logger. Call on UI thread.
61 void FetchAuthToken(); 40 void FetchAuthToken();
62 41
42 // remoting::ChromotingClientRuntime::Delegate overrides.
43 void RuntimeWillShutdown() override;
44 void RequestAuthTokenForLogger() override;
45
63 private: 46 private:
64 ChromotingJniRuntime(); 47 JniRuntimeDelegate();
65 48
66 // Forces a DisconnectFromHost() in case there is any active or failed 49 // Forces a DisconnectFromHost() in case there is any active or failed
67 // connection, then proceeds to tear down the Chromium dependencies on which 50 // connection, then proceeds to tear down the Chromium dependencies on which
68 // all sessions depended. Because destruction only occurs at application exit 51 // all sessions depended. Because destruction only occurs at application exit
69 // after all connections have terminated, it is safe to make unretained 52 // after all connections have terminated, it is safe to make unretained
70 // cross-thread calls on the class. 53 // cross-thread calls on the class.
71 virtual ~ChromotingJniRuntime(); 54 virtual ~JniRuntimeDelegate();
72 55
73 // Detaches JVM from the current thread, then signals. Doesn't own |waiter|. 56 // Detaches JVM from the current thread, then signals. Doesn't own |waiter|.
74 void DetachFromVmAndSignal(base::WaitableEvent* waiter); 57 void DetachFromVmAndSignal(base::WaitableEvent* waiter);
75 58
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 59 // Chromium code's connection to the app message loop. Once created the
80 // MessageLoop will live for the life of the program. 60 // MessageLoop will live for the life of the program.
81 std::unique_ptr<base::MessageLoopForUI> ui_loop_; 61 std::unique_ptr<base::MessageLoopForUI> ui_loop_;
62 ChromotingClientRuntime* runtime_;
82 63
83 // Contains threads. 64 friend struct base::DefaultSingletonTraits<JniRuntimeDelegate>;
84 //
85 std::unique_ptr<ChromotingClientRuntime> runtime_;
86 65
87 // For logging session stage changes and stats. 66 DISALLOW_COPY_AND_ASSIGN(JniRuntimeDelegate);
88 std::unique_ptr<TelemetryLogWriter> log_writer_;
89
90 friend struct base::DefaultSingletonTraits<ChromotingJniRuntime>;
91
92 DISALLOW_COPY_AND_ASSIGN(ChromotingJniRuntime);
93 }; 67 };
94 68
95 } // namespace remoting 69 } // namespace remoting
96 70
97 #endif 71 #endif // REMOTING_CLIENT_JNI_JNI_RUNTIME_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698