OLD | NEW |
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" |
| 12 #include "base/memory/singleton.h" |
11 #include "net/url_request/url_request_context_getter.h" | 13 #include "net/url_request/url_request_context_getter.h" |
12 #include "remoting/base/auto_thread.h" | 14 #include "remoting/base/auto_thread.h" |
| 15 #include "remoting/base/telemetry_log_writer.h" |
13 | 16 |
14 namespace base { | 17 namespace base { |
15 class MessageLoopForUI; | 18 class MessageLoopForUI; |
| 19 |
| 20 template <typename T> |
| 21 struct DefaultSingletonTraits; |
16 } // namespace base | 22 } // namespace base |
17 | 23 |
18 // Houses the global resources on which the Chromoting components run | 24 // Houses the global resources on which the Chromoting components run |
19 // (e.g. message loops and task runners). | 25 // (e.g. message loops and task runners). |
20 namespace remoting { | 26 namespace remoting { |
21 | 27 |
22 class ChromotingClientRuntime { | 28 class ChromotingClientRuntime { |
23 public: | 29 public: |
24 // Caller to create is responsible for creating and attaching a new ui thread | 30 class Delegate { |
25 // for use. Example: | 31 public: |
26 // | 32 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 | 33 |
45 ~ChromotingClientRuntime(); | 34 virtual void RuntimeWillShutdown() = 0; |
| 35 virtual void RequestAuthTokenForLogger() = 0; |
| 36 }; |
| 37 |
| 38 static ChromotingClientRuntime* GetInstance(); |
| 39 |
| 40 void SetDelegate(ChromotingClientRuntime::Delegate* delegate); |
46 | 41 |
47 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { | 42 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { |
48 return network_task_runner_; | 43 return network_task_runner_; |
49 } | 44 } |
50 | 45 |
51 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { | 46 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { |
52 return ui_task_runner_; | 47 return ui_task_runner_; |
53 } | 48 } |
54 | 49 |
55 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { | 50 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { |
56 return display_task_runner_; | 51 return display_task_runner_; |
57 } | 52 } |
58 | 53 |
59 scoped_refptr<AutoThreadTaskRunner> file_task_runner() { | 54 scoped_refptr<AutoThreadTaskRunner> file_task_runner() { |
60 return file_task_runner_; | 55 return file_task_runner_; |
61 } | 56 } |
62 | 57 |
63 scoped_refptr<net::URLRequestContextGetter> url_requester() { | 58 scoped_refptr<net::URLRequestContextGetter> url_requester() { |
64 return url_requester_; | 59 return url_requester_; |
65 } | 60 } |
66 | 61 |
| 62 // TODO(nicholss): This should return a base::weak_ptr<TelemetryLogWriter> |
| 63 // At some point the application should set the auth closure when auth is |
| 64 // possible. |
| 65 // TODO(nicholss): GetLogWriter is not like the above methods, change to |
| 66 // log_writer? |
| 67 TelemetryLogWriter* GetLogWriter(); |
| 68 |
67 private: | 69 private: |
68 ChromotingClientRuntime(); | 70 ChromotingClientRuntime(); |
69 ChromotingClientRuntime( | 71 virtual ~ChromotingClientRuntime(); |
70 scoped_refptr<AutoThreadTaskRunner> ui_task_runner, | 72 |
71 scoped_refptr<AutoThreadTaskRunner> display_task_runner, | 73 void CreateLogWriter(); |
72 scoped_refptr<AutoThreadTaskRunner> network_task_runner, | 74 void RequestAuthTokenForLogger(); |
73 scoped_refptr<AutoThreadTaskRunner> file_task_runner, | 75 |
74 scoped_refptr<net::URLRequestContextGetter> url_requester); | 76 // Chromium code's connection to the app message loop. Once created the |
| 77 // MessageLoop will live for the life of the program. |
| 78 std::unique_ptr<base::MessageLoopForUI> ui_loop_; |
75 | 79 |
76 // References to native threads. | 80 // References to native threads. |
77 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 81 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
78 | 82 |
79 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; | 83 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; |
80 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | 84 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
81 scoped_refptr<AutoThreadTaskRunner> file_task_runner_; | 85 scoped_refptr<AutoThreadTaskRunner> file_task_runner_; |
82 | 86 |
83 scoped_refptr<net::URLRequestContextGetter> url_requester_; | 87 scoped_refptr<net::URLRequestContextGetter> url_requester_; |
84 | 88 |
| 89 // For logging session stage changes and stats. |
| 90 std::unique_ptr<TelemetryLogWriter> log_writer_; |
| 91 |
| 92 ChromotingClientRuntime::Delegate* delegate_; |
| 93 |
| 94 friend struct base::DefaultSingletonTraits<ChromotingClientRuntime>; |
| 95 |
85 DISALLOW_COPY_AND_ASSIGN(ChromotingClientRuntime); | 96 DISALLOW_COPY_AND_ASSIGN(ChromotingClientRuntime); |
86 }; | 97 }; |
87 | 98 |
88 } // namespace remoting | 99 } // namespace remoting |
89 | 100 |
90 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_RUNTIME_H_ | 101 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_RUNTIME_H_ |
OLD | NEW |