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

Side by Side Diff: remoting/client/chromoting_client_runtime.h

Issue 2745583008: Refactoring out the chromoting jni runtime class in favor of chromoting client runtime. (Closed)
Patch Set: Missed out on a () 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_CHROMOTING_CLIENT_RUNTIME_H_ 5 #ifndef REMOTING_CLIENT_CHROMOTING_CLIENT_RUNTIME_H_
6 #define REMOTING_CLIENT_CHROMOTING_CLIENT_RUNTIME_H_ 6 #define REMOTING_CLIENT_CHROMOTING_CLIENT_RUNTIME_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
11 #include "net/url_request/url_request_context_getter.h" 12 #include "net/url_request/url_request_context_getter.h"
12 #include "remoting/base/auto_thread.h" 13 #include "remoting/base/auto_thread.h"
14 #include "remoting/base/telemetry_log_writer.h"
13 15
14 namespace base { 16 namespace base {
15 class MessageLoopForUI; 17 class MessageLoopForUI;
18
19 template <typename T>
20 struct DefaultSingletonTraits;
16 } // namespace base 21 } // namespace base
17 22
18 // Houses the global resources on which the Chromoting components run 23 // Houses the global resources on which the Chromoting components run
19 // (e.g. message loops and task runners). 24 // (e.g. message loops and task runners).
20 namespace remoting { 25 namespace remoting {
21 26
22 class ChromotingClientRuntime { 27 class ChromotingClientRuntime {
23 public: 28 public:
24 // Caller to create is responsible for creating and attaching a new ui thread 29 class Delegate {
25 // for use. Example: 30 public:
26 // 31 virtual ~Delegate() {}
27 // On Android, the UI thread is managed by Java, so we need to attach and
28 // start a special type of message loop to allow Chromium code to run tasks.
29 //
30 // base::MessageLoopForUI *ui_loop = new base::MessageLoopForUI();
31 // ui_loop_->Start();
32 // std::unique_ptr<ChromotingClientRuntime> runtime =
33 // ChromotingClientRuntime::Create(ui_loop);
34 //
35 // On iOS we created a new message loop and now attach it.
36 //
37 // base::MessageLoopForUI *ui_loop = new base::MessageLoopForUI();
38 // ui_loop_->Attach();
39 // std::unique_ptr<ChromotingClientRuntime> runtime =
40 // ChromotingClientRuntime::Create(ui_loop);
41 //
42 static std::unique_ptr<ChromotingClientRuntime> Create(
43 base::MessageLoopForUI* ui_loop);
44 32
45 ~ChromotingClientRuntime(); 33 // RuntimeWillShutdown will be called on the delegate when the runtime
34 // enters into the destructor. This is a good time for the delegate to
35 // start shutting down on threads while they exist.
36 virtual void RuntimeWillShutdown() = 0;
37
38 // RuntimeDidShutdown will be called after task managers and threads
39 // have been stopped.
40 virtual void RuntimeDidShutdown() = 0;
41
42 // RequestAuthTokenForLogger is called when the logger is requesting
43 // and auth token and the delegate is set. It is expected that the
44 // delegate will give the logger and auth token on the network thread like:
45 // (network thread): runtime->log_writer()->SetAuthToken(token)
46 virtual void RequestAuthTokenForLogger() = 0;
47 };
48
49 static ChromotingClientRuntime* GetInstance();
50
51 void SetDelegate(ChromotingClientRuntime::Delegate* delegate);
46 52
47 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { 53 scoped_refptr<AutoThreadTaskRunner> network_task_runner() {
48 return network_task_runner_; 54 return network_task_runner_;
49 } 55 }
50 56
51 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { 57 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() {
52 return ui_task_runner_; 58 return ui_task_runner_;
53 } 59 }
54 60
55 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { 61 scoped_refptr<AutoThreadTaskRunner> display_task_runner() {
56 return display_task_runner_; 62 return display_task_runner_;
57 } 63 }
58 64
59 scoped_refptr<AutoThreadTaskRunner> file_task_runner() { 65 scoped_refptr<AutoThreadTaskRunner> file_task_runner() {
60 return file_task_runner_; 66 return file_task_runner_;
61 } 67 }
62 68
63 scoped_refptr<net::URLRequestContextGetter> url_requester() { 69 scoped_refptr<net::URLRequestContextGetter> url_requester() {
64 return url_requester_; 70 return url_requester_;
65 } 71 }
66 72
73 // Must call and use log_writter on the network thread.
74 ChromotingEventLogWriter* log_writer();
75
67 private: 76 private:
68 ChromotingClientRuntime(); 77 ChromotingClientRuntime();
69 ChromotingClientRuntime( 78 virtual ~ChromotingClientRuntime();
70 scoped_refptr<AutoThreadTaskRunner> ui_task_runner, 79
71 scoped_refptr<AutoThreadTaskRunner> display_task_runner, 80 void CreateLogWriter();
72 scoped_refptr<AutoThreadTaskRunner> network_task_runner, 81 void RequestAuthTokenForLogger();
73 scoped_refptr<AutoThreadTaskRunner> file_task_runner, 82
74 scoped_refptr<net::URLRequestContextGetter> url_requester); 83 // Chromium code's connection to the app message loop. Once created the
84 // MessageLoop will live for the life of the program.
85 std::unique_ptr<base::MessageLoopForUI> ui_loop_;
75 86
76 // References to native threads. 87 // References to native threads.
77 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; 88 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
78 89
79 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; 90 scoped_refptr<AutoThreadTaskRunner> display_task_runner_;
80 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; 91 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
81 scoped_refptr<AutoThreadTaskRunner> file_task_runner_; 92 scoped_refptr<AutoThreadTaskRunner> file_task_runner_;
82 93
83 scoped_refptr<net::URLRequestContextGetter> url_requester_; 94 scoped_refptr<net::URLRequestContextGetter> url_requester_;
84 95
96 // For logging session stage changes and stats.
97 std::unique_ptr<TelemetryLogWriter> log_writer_;
98
99 ChromotingClientRuntime::Delegate* delegate_;
100
101 friend struct base::DefaultSingletonTraits<ChromotingClientRuntime>;
102
85 DISALLOW_COPY_AND_ASSIGN(ChromotingClientRuntime); 103 DISALLOW_COPY_AND_ASSIGN(ChromotingClientRuntime);
86 }; 104 };
87 105
88 } // namespace remoting 106 } // namespace remoting
89 107
90 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_RUNTIME_H_ 108 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_RUNTIME_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698