Chromium Code Reviews| 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; | |
|
Sergey Ulanov
2017/03/14 19:09:37
Do you need this, given that this file includes ba
nicholss
2017/03/14 22:56:44
I was not suppose to have base/singleton in this h
| |
| 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 RuntimeDidShutdown() = 0; | |
| 36 virtual void RequestAuthTokenForLogger() = 0; | |
| 37 }; | |
| 38 | |
| 39 static ChromotingClientRuntime* GetInstance(); | |
| 40 | |
| 41 void SetDelegate(ChromotingClientRuntime::Delegate* delegate); | |
| 46 | 42 |
| 47 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { | 43 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { |
| 48 return network_task_runner_; | 44 return network_task_runner_; |
| 49 } | 45 } |
| 50 | 46 |
| 51 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { | 47 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { |
| 52 return ui_task_runner_; | 48 return ui_task_runner_; |
| 53 } | 49 } |
| 54 | 50 |
| 55 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { | 51 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { |
| 56 return display_task_runner_; | 52 return display_task_runner_; |
| 57 } | 53 } |
| 58 | 54 |
| 59 scoped_refptr<AutoThreadTaskRunner> file_task_runner() { | 55 scoped_refptr<AutoThreadTaskRunner> file_task_runner() { |
| 60 return file_task_runner_; | 56 return file_task_runner_; |
| 61 } | 57 } |
| 62 | 58 |
| 63 scoped_refptr<net::URLRequestContextGetter> url_requester() { | 59 scoped_refptr<net::URLRequestContextGetter> url_requester() { |
| 64 return url_requester_; | 60 return url_requester_; |
| 65 } | 61 } |
| 66 | 62 |
| 63 // TODO(nicholss): This should return a base::weak_ptr<TelemetryLogWriter> | |
|
Sergey Ulanov
2017/03/14 19:09:37
This class owns the log_writer, so I think returni
nicholss
2017/03/14 22:56:44
Ok thanks
Yuwei
2017/03/16 08:38:53
WeakPtr is not necessary as long as the runtime di
| |
| 64 // At some point the application should set the auth closure when auth is | |
| 65 // possible. | |
| 66 // TODO(nicholss): GetLogWriter is not like the above methods, change to | |
|
Sergey Ulanov
2017/03/14 19:09:37
Yes, log_writer() would be a better name
nicholss
2017/03/14 22:56:44
Done.
| |
| 67 // log_writer? | |
| 68 TelemetryLogWriter* GetLogWriter(); | |
|
Sergey Ulanov
2017/03/14 19:09:37
Unlike other stuff this class stores the log write
Sergey Ulanov
2017/03/14 19:09:37
Change return type to ChromotingEventLogWriter
nicholss
2017/03/14 22:56:44
Done.
nicholss
2017/03/14 22:56:44
Done.
| |
| 69 | |
| 67 private: | 70 private: |
| 68 ChromotingClientRuntime(); | 71 ChromotingClientRuntime(); |
| 69 ChromotingClientRuntime( | 72 virtual ~ChromotingClientRuntime(); |
| 70 scoped_refptr<AutoThreadTaskRunner> ui_task_runner, | 73 |
| 71 scoped_refptr<AutoThreadTaskRunner> display_task_runner, | 74 void CreateLogWriter(); |
| 72 scoped_refptr<AutoThreadTaskRunner> network_task_runner, | 75 void RequestAuthTokenForLogger(); |
| 73 scoped_refptr<AutoThreadTaskRunner> file_task_runner, | 76 |
| 74 scoped_refptr<net::URLRequestContextGetter> url_requester); | 77 // Chromium code's connection to the app message loop. Once created the |
| 78 // MessageLoop will live for the life of the program. | |
| 79 std::unique_ptr<base::MessageLoopForUI> ui_loop_; | |
| 75 | 80 |
| 76 // References to native threads. | 81 // References to native threads. |
| 77 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 82 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
| 78 | 83 |
| 79 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; | 84 scoped_refptr<AutoThreadTaskRunner> display_task_runner_; |
| 80 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | 85 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
| 81 scoped_refptr<AutoThreadTaskRunner> file_task_runner_; | 86 scoped_refptr<AutoThreadTaskRunner> file_task_runner_; |
| 82 | 87 |
| 83 scoped_refptr<net::URLRequestContextGetter> url_requester_; | 88 scoped_refptr<net::URLRequestContextGetter> url_requester_; |
| 84 | 89 |
| 90 // For logging session stage changes and stats. | |
| 91 std::unique_ptr<TelemetryLogWriter> log_writer_; | |
| 92 | |
| 93 ChromotingClientRuntime::Delegate* delegate_; | |
| 94 | |
| 95 friend struct base::DefaultSingletonTraits<ChromotingClientRuntime>; | |
| 96 | |
| 85 DISALLOW_COPY_AND_ASSIGN(ChromotingClientRuntime); | 97 DISALLOW_COPY_AND_ASSIGN(ChromotingClientRuntime); |
| 86 }; | 98 }; |
| 87 | 99 |
| 88 } // namespace remoting | 100 } // namespace remoting |
| 89 | 101 |
| 90 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_RUNTIME_H_ | 102 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_RUNTIME_H_ |
| OLD | NEW |