OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This is an application of a minimal host process in a Chromoting | 5 // This is an application of a minimal host process in a Chromoting |
6 // system. It serves the purpose of gluing different pieces together | 6 // system. It serves the purpose of gluing different pieces together |
7 // to make a functional host process for testing. | 7 // to make a functional host process for testing. |
8 // | 8 // |
9 // It peforms the following functionality: | 9 // It peforms the following functionality: |
10 // 1. Connect to the GTalk network and register the machine as a host. | 10 // 1. Connect to the GTalk network and register the machine as a host. |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "remoting/host/chromoting_host.h" | 35 #include "remoting/host/chromoting_host.h" |
36 #include "remoting/host/chromoting_host_context.h" | 36 #include "remoting/host/chromoting_host_context.h" |
37 #include "remoting/host/desktop_environment.h" | 37 #include "remoting/host/desktop_environment.h" |
38 #include "remoting/host/event_executor.h" | 38 #include "remoting/host/event_executor.h" |
39 #include "remoting/host/heartbeat_sender.h" | 39 #include "remoting/host/heartbeat_sender.h" |
40 #include "remoting/host/host_secret.h" | 40 #include "remoting/host/host_secret.h" |
41 #include "remoting/host/it2me_host_user_interface.h" | 41 #include "remoting/host/it2me_host_user_interface.h" |
42 #include "remoting/host/log_to_server.h" | 42 #include "remoting/host/log_to_server.h" |
43 #include "remoting/host/json_host_config.h" | 43 #include "remoting/host/json_host_config.h" |
44 #include "remoting/host/register_support_host_request.h" | 44 #include "remoting/host/register_support_host_request.h" |
| 45 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
45 #include "remoting/proto/video.pb.h" | 46 #include "remoting/proto/video.pb.h" |
46 | 47 |
47 #if defined(TOOLKIT_USES_GTK) | 48 #if defined(TOOLKIT_USES_GTK) |
48 #include "ui/gfx/gtk_util.h" | 49 #include "ui/gfx/gtk_util.h" |
49 #elif defined(OS_MACOSX) | 50 #elif defined(OS_MACOSX) |
50 #include "base/mac/scoped_nsautorelease_pool.h" | 51 #include "base/mac/scoped_nsautorelease_pool.h" |
51 #elif defined(OS_WIN) | 52 #elif defined(OS_WIN) |
52 // TODO(garykac) Make simple host into a proper GUI app on Windows so that we | 53 // TODO(garykac) Make simple host into a proper GUI app on Windows so that we |
53 // have an hModule for the dialog resource. | 54 // have an hModule for the dialog resource. |
54 HMODULE g_hModule = NULL; | 55 HMODULE g_hModule = NULL; |
55 #endif | 56 #endif |
56 | 57 |
57 using remoting::ChromotingHost; | 58 using remoting::ChromotingHost; |
58 using remoting::DesktopEnvironment; | 59 using remoting::DesktopEnvironment; |
59 using remoting::kChromotingTokenDefaultServiceName; | |
60 using remoting::kXmppAuthServiceConfigPath; | |
61 using remoting::It2MeHostUserInterface; | 60 using remoting::It2MeHostUserInterface; |
62 using remoting::protocol::CandidateSessionConfig; | 61 using remoting::protocol::CandidateSessionConfig; |
63 using remoting::protocol::ChannelConfig; | 62 using remoting::protocol::ChannelConfig; |
64 using std::string; | 63 using std::string; |
65 using std::wstring; | 64 using std::wstring; |
66 | 65 |
67 #if defined(OS_WIN) | 66 #if defined(OS_WIN) |
68 const wchar_t kDefaultConfigPath[] = L".ChromotingConfig.json"; | 67 const wchar_t kDefaultConfigPath[] = L".ChromotingConfig.json"; |
69 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; | 68 const wchar_t kHomeDrive[] = L"HOMEDRIVE"; |
70 const wchar_t kHomePath[] = L"HOMEPATH"; | 69 const wchar_t kHomePath[] = L"HOMEPATH"; |
(...skipping 20 matching lines...) Expand all Loading... |
91 : fake_(false), | 90 : fake_(false), |
92 is_it2me_(false) { | 91 is_it2me_(false) { |
93 } | 92 } |
94 | 93 |
95 int Run() { | 94 int Run() { |
96 // |message_loop| is declared early so that any code we call into which | 95 // |message_loop| is declared early so that any code we call into which |
97 // requires a current message-loop won't complain. | 96 // requires a current message-loop won't complain. |
98 // It needs to be a UI message loop to keep runloops spinning on the Mac. | 97 // It needs to be a UI message loop to keep runloops spinning on the Mac. |
99 MessageLoop message_loop(MessageLoop::TYPE_UI); | 98 MessageLoop message_loop(MessageLoop::TYPE_UI); |
100 | 99 |
101 remoting::ChromotingHostContext context( | |
102 base::MessageLoopProxy::current()); | |
103 context.Start(); | |
104 | |
105 base::Thread file_io_thread("FileIO"); | 100 base::Thread file_io_thread("FileIO"); |
106 file_io_thread.Start(); | 101 file_io_thread.Start(); |
107 | 102 |
108 FilePath config_path = GetConfigPath(); | 103 FilePath config_path = GetConfigPath(); |
109 scoped_refptr<remoting::JsonHostConfig> config = | 104 scoped_refptr<remoting::JsonHostConfig> config = |
110 new remoting::JsonHostConfig( | 105 new remoting::JsonHostConfig( |
111 config_path, file_io_thread.message_loop_proxy()); | 106 config_path, file_io_thread.message_loop_proxy()); |
112 if (!config->Read()) { | 107 if (!config->Read()) { |
113 LOG(ERROR) << "Failed to read configuration file " | 108 LOG(ERROR) << "Failed to read configuration file " |
114 << config_path.value(); | 109 << config_path.value(); |
115 context.Stop(); | |
116 return 1; | 110 return 1; |
117 } | 111 } |
118 | 112 |
119 // For the simple host, we assume we always use the ClientLogin token for | 113 remoting::ChromotingHostContext context( |
120 // chromiumsync because we do not have an HTTP stack with which we can | 114 base::MessageLoopProxy::current()); |
121 // easily request an OAuth2 access token even if we had a RefreshToken for | 115 context.Start(); |
122 // the account. | |
123 config->SetString(kXmppAuthServiceConfigPath, | |
124 kChromotingTokenDefaultServiceName); | |
125 | 116 |
126 // Initialize AccessVerifier. | 117 // Use an XMPP connection to the Talk network for session signalling. |
127 // TODO(jamiewalch): For the IT2Me case, the access verifier is passed to | 118 std::string xmpp_login; |
128 // RegisterSupportHostRequest::Init, so transferring ownership of it to the | 119 std::string xmpp_auth_token; |
129 // ChromotingHost could cause a crash condition if SetIT2MeAccessCode is | 120 if (!config->GetString(remoting::kXmppLoginConfigPath, &xmpp_login) || |
130 // called after the ChromotingHost is destroyed (for example, at shutdown). | 121 !config->GetString(remoting::kXmppAuthTokenConfigPath, |
131 // Fix this. | 122 &xmpp_auth_token)) { |
132 scoped_ptr<remoting::RegisterSupportHostRequest> register_request; | 123 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
133 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender; | 124 return 1; |
134 scoped_ptr<remoting::LogToServer> log_to_server; | |
135 if (is_it2me_) { | |
136 register_request.reset(new remoting::RegisterSupportHostRequest()); | |
137 if (!register_request->Init( | |
138 config, base::Bind(&SimpleHost::SetIT2MeAccessCode, | |
139 base::Unretained(this)))) { | |
140 return 1; | |
141 } | |
142 } | 125 } |
143 log_to_server.reset(new remoting::LogToServer( | 126 std::string xmpp_auth_service; |
144 context.network_message_loop())); | 127 if (!config->GetString(remoting::kXmppAuthServiceConfigPath, |
| 128 &xmpp_auth_service)) { |
| 129 // For the simple host, we assume we always use the ClientLogin token for |
| 130 // chromiumsync because we do not have an HTTP stack with which we can |
| 131 // easily request an OAuth2 access token even if we had a RefreshToken for |
| 132 // the account. |
| 133 xmpp_auth_service = remoting::kChromotingTokenDefaultServiceName; |
| 134 } |
| 135 |
| 136 // Create and start XMPP connection. |
| 137 scoped_ptr<remoting::SignalStrategy> signal_strategy( |
| 138 new remoting::XmppSignalStrategy(context.jingle_thread(), xmpp_login, |
| 139 xmpp_auth_token, xmpp_auth_service)); |
| 140 |
145 | 141 |
146 // Construct a chromoting host. | 142 // Construct a chromoting host. |
147 scoped_ptr<DesktopEnvironment> desktop_environment; | 143 scoped_ptr<DesktopEnvironment> desktop_environment; |
148 if (fake_) { | 144 if (fake_) { |
149 remoting::Capturer* capturer = | 145 remoting::Capturer* capturer = |
150 new remoting::CapturerFake(); | 146 new remoting::CapturerFake(); |
151 remoting::EventExecutor* event_executor = | 147 remoting::EventExecutor* event_executor = |
152 remoting::EventExecutor::Create(context.desktop_message_loop(), | 148 remoting::EventExecutor::Create(context.desktop_message_loop(), |
153 capturer); | 149 capturer); |
154 desktop_environment.reset( | 150 desktop_environment.reset( |
155 new DesktopEnvironment(&context, capturer, event_executor)); | 151 new DesktopEnvironment(&context, capturer, event_executor)); |
156 } else { | 152 } else { |
157 desktop_environment.reset(DesktopEnvironment::Create(&context)); | 153 desktop_environment.reset(DesktopEnvironment::Create(&context)); |
158 } | 154 } |
159 | 155 |
160 host_ = ChromotingHost::Create( | 156 host_ = new ChromotingHost(&context, config, signal_strategy.get(), |
161 &context, config, desktop_environment.get(), false); | 157 desktop_environment.get(), false); |
162 host_->set_it2me(is_it2me_); | 158 host_->set_it2me(is_it2me_); |
163 | 159 |
| 160 scoped_ptr<remoting::LogToServer> log_to_server; |
| 161 log_to_server.reset(new remoting::LogToServer(signal_strategy.get())); |
| 162 host_->AddStatusObserver(log_to_server.get()); |
| 163 |
164 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface; | 164 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface; |
165 if (is_it2me_) { | 165 if (is_it2me_) { |
166 it2me_host_user_interface.reset(new It2MeHostUserInterface(host_, | 166 it2me_host_user_interface.reset(new It2MeHostUserInterface(host_, |
167 &context)); | 167 &context)); |
168 it2me_host_user_interface->Init(); | 168 it2me_host_user_interface->Init(); |
169 host_->AddStatusObserver(it2me_host_user_interface.get()); | 169 host_->AddStatusObserver(it2me_host_user_interface.get()); |
170 } | 170 } |
171 | 171 |
172 if (protocol_config_.get()) { | 172 if (protocol_config_.get()) { |
173 host_->set_protocol_config(protocol_config_.release()); | 173 host_->set_protocol_config(protocol_config_.release()); |
174 } | 174 } |
175 | 175 |
| 176 scoped_ptr<remoting::RegisterSupportHostRequest> register_request; |
| 177 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender; |
176 if (is_it2me_) { | 178 if (is_it2me_) { |
177 host_->AddStatusObserver(register_request.get()); | 179 register_request.reset(new remoting::RegisterSupportHostRequest()); |
| 180 if (!register_request->Init(signal_strategy.get(), config, |
| 181 base::Bind(&SimpleHost::SetIT2MeAccessCode, |
| 182 base::Unretained(this)))) { |
| 183 return 1; |
| 184 } |
178 } else { | 185 } else { |
179 // Initialize HeartbeatSender. | 186 // Initialize HeartbeatSender. |
180 heartbeat_sender.reset( | 187 heartbeat_sender.reset( |
181 new remoting::HeartbeatSender(context.network_message_loop(), | 188 new remoting::HeartbeatSender()); |
182 config)); | 189 if (!heartbeat_sender->Init(signal_strategy.get(), config)) |
183 if (!heartbeat_sender->Init()) | |
184 return 1; | 190 return 1; |
185 host_->AddStatusObserver(heartbeat_sender.get()); | |
186 } | 191 } |
187 host_->AddStatusObserver(log_to_server.get()); | 192 |
| 193 // Post a task to start XMPP connection. |
| 194 context.network_message_loop()->PostTask( |
| 195 FROM_HERE, base::Bind(&remoting::SignalStrategy::Connect, |
| 196 base::Unretained(signal_strategy.get()))); |
188 | 197 |
189 // Let the chromoting host run until the shutdown task is executed. | 198 // Let the chromoting host run until the shutdown task is executed. |
190 host_->Start(); | 199 host_->Start(); |
191 | 200 |
192 // Set an empty shared-secret for Me2Me. | 201 // Set an empty shared-secret for Me2Me. |
193 // TODO(lambroslambrou): This is a temporary fix, pending a Me2Me-specific | 202 // TODO(lambroslambrou): This is a temporary fix, pending a Me2Me-specific |
194 // AuthenticatorFactory - crbug.com/105214. | 203 // AuthenticatorFactory - crbug.com/105214. |
195 if (!is_it2me_) { | 204 if (!is_it2me_) { |
196 context.network_message_loop()->PostTask( | 205 context.network_message_loop()->PostTask( |
197 FROM_HERE, base::Bind(&ChromotingHost::SetSharedSecret, host_.get(), | 206 FROM_HERE, base::Bind(&ChromotingHost::SetSharedSecret, host_.get(), |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 LOG(ERROR) << "Unknown video codec: " << video_codec; | 312 LOG(ERROR) << "Unknown video codec: " << video_codec; |
304 return 1; | 313 return 1; |
305 } | 314 } |
306 config->mutable_video_configs()->push_back(ChannelConfig( | 315 config->mutable_video_configs()->push_back(ChannelConfig( |
307 transport, remoting::protocol::kDefaultStreamVersion, codec)); | 316 transport, remoting::protocol::kDefaultStreamVersion, codec)); |
308 simple_host.set_protocol_config(config.release()); | 317 simple_host.set_protocol_config(config.release()); |
309 } | 318 } |
310 | 319 |
311 return simple_host.Run(); | 320 return simple_host.Run(); |
312 } | 321 } |
OLD | NEW |