| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 file implements a standalone host process for Me2Me, which is currently | 5 // This file implements a standalone host process for Me2Me, which is currently |
| 6 // used for the Linux-only Virtual Me2Me build. | 6 // used for the Linux-only Virtual Me2Me build. |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 &HostProcess::StartHost, base::Unretained(this))); | 103 &HostProcess::StartHost, base::Unretained(this))); |
| 104 | 104 |
| 105 message_loop_.Run(); | 105 message_loop_.Run(); |
| 106 | 106 |
| 107 return 0; | 107 return 0; |
| 108 } | 108 } |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 // Read Host config from disk, returning true if successful. | 111 // Read Host config from disk, returning true if successful. |
| 112 bool LoadConfig(base::MessageLoopProxy* io_message_loop) { | 112 bool LoadConfig(base::MessageLoopProxy* io_message_loop) { |
| 113 scoped_refptr<remoting::JsonHostConfig> host_config = | 113 scoped_refptr<JsonHostConfig> host_config = |
| 114 new remoting::JsonHostConfig(host_config_path_, io_message_loop); | 114 new JsonHostConfig(host_config_path_, io_message_loop); |
| 115 scoped_refptr<remoting::JsonHostConfig> auth_config = | 115 scoped_refptr<JsonHostConfig> auth_config = |
| 116 new remoting::JsonHostConfig(auth_config_path_, io_message_loop); | 116 new JsonHostConfig(auth_config_path_, io_message_loop); |
| 117 | 117 |
| 118 std::string failed_path; | 118 std::string failed_path; |
| 119 if (!host_config->Read()) { | 119 if (!host_config->Read()) { |
| 120 failed_path = host_config_path_.value(); | 120 failed_path = host_config_path_.value(); |
| 121 } else if (!auth_config->Read()) { | 121 } else if (!auth_config->Read()) { |
| 122 failed_path = auth_config_path_.value(); | 122 failed_path = auth_config_path_.value(); |
| 123 } | 123 } |
| 124 if (!failed_path.empty()) { | 124 if (!failed_path.empty()) { |
| 125 LOG(ERROR) << "Failed to read configuration file " << failed_path; | 125 LOG(ERROR) << "Failed to read configuration file " << failed_path; |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { | 129 if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { |
| 130 LOG(ERROR) << "host_id is not defined in the config."; | 130 LOG(ERROR) << "host_id is not defined in the config."; |
| 131 return false; | 131 return false; |
| 132 } | 132 } |
| 133 | 133 |
| 134 if (!key_pair_.Load(host_config)) { | 134 if (!key_pair_.Load(host_config)) { |
| 135 return false; | 135 return false; |
| 136 } | 136 } |
| 137 | 137 |
| 138 std::string host_secret_hash_string; |
| 139 if (!host_config->GetString(kHostSecretHashConfigPath, |
| 140 &host_secret_hash_string)) { |
| 141 host_secret_hash_string = "plain:"; |
| 142 } |
| 143 |
| 144 if (!host_secret_hash_.Parse(host_secret_hash_string)) { |
| 145 LOG(ERROR) << "Invalid host_secret_hash."; |
| 146 return false; |
| 147 } |
| 148 |
| 138 // Use an XMPP connection to the Talk network for session signalling. | 149 // Use an XMPP connection to the Talk network for session signalling. |
| 139 if (!auth_config->GetString(kXmppLoginConfigPath, &xmpp_login_) || | 150 if (!auth_config->GetString(kXmppLoginConfigPath, &xmpp_login_) || |
| 140 !auth_config->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_)) { | 151 !auth_config->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_)) { |
| 141 LOG(ERROR) << "XMPP credentials are not defined in the config."; | 152 LOG(ERROR) << "XMPP credentials are not defined in the config."; |
| 142 return false; | 153 return false; |
| 143 } | 154 } |
| 144 | 155 |
| 145 if (!auth_config->GetString(remoting::kXmppAuthServiceConfigPath, | 156 if (!auth_config->GetString(kXmppAuthServiceConfigPath, |
| 146 &xmpp_auth_service_)) { | 157 &xmpp_auth_service_)) { |
| 147 // For the me2me host, we assume we use the ClientLogin token for | 158 // For the me2me host, we assume we use the ClientLogin token for |
| 148 // chromiumsync because we do not have an HTTP stack with which we can | 159 // chromiumsync because we do not have an HTTP stack with which we can |
| 149 // easily request an OAuth2 access token even if we had a RefreshToken for | 160 // easily request an OAuth2 access token even if we had a RefreshToken for |
| 150 // the account. | 161 // the account. |
| 151 xmpp_auth_service_ = remoting::kChromotingTokenDefaultServiceName; | 162 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; |
| 152 } | 163 } |
| 153 | 164 |
| 154 return true; | 165 return true; |
| 155 } | 166 } |
| 156 | 167 |
| 157 void StartHost() { | 168 void StartHost() { |
| 158 DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); | 169 DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); |
| 159 | 170 |
| 160 signal_strategy_.reset( | 171 signal_strategy_.reset( |
| 161 new XmppSignalStrategy(context_.jingle_thread(), xmpp_login_, | 172 new XmppSignalStrategy(context_.jingle_thread(), xmpp_login_, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 176 heartbeat_sender_.reset( | 187 heartbeat_sender_.reset( |
| 177 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); | 188 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); |
| 178 | 189 |
| 179 log_to_server_.reset( | 190 log_to_server_.reset( |
| 180 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); | 191 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); |
| 181 host_event_logger_.reset(new HostEventLogger(host_, kApplicationName)); | 192 host_event_logger_.reset(new HostEventLogger(host_, kApplicationName)); |
| 182 | 193 |
| 183 host_->Start(); | 194 host_->Start(); |
| 184 | 195 |
| 185 // Create authenticator factory. | 196 // Create authenticator factory. |
| 186 // | |
| 187 // TODO(sergeyu): Currently empty PIN is used. This is a temporary | |
| 188 // hack pending us adding a way to set a PIN. crbug.com/105214 . | |
| 189 scoped_ptr<protocol::AuthenticatorFactory> factory( | 197 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 190 new protocol::Me2MeHostAuthenticatorFactory( | 198 new protocol::Me2MeHostAuthenticatorFactory( |
| 191 xmpp_login_, key_pair_.GenerateCertificate(), | 199 xmpp_login_, key_pair_.GenerateCertificate(), |
| 192 *key_pair_.private_key(), "")); | 200 *key_pair_.private_key(), host_secret_hash_)); |
| 193 host_->SetAuthenticatorFactory(factory.Pass()); | 201 host_->SetAuthenticatorFactory(factory.Pass()); |
| 194 } | 202 } |
| 195 | 203 |
| 196 MessageLoop message_loop_; | 204 MessageLoop message_loop_; |
| 197 base::Thread file_io_thread_; | 205 base::Thread file_io_thread_; |
| 198 remoting::ChromotingHostContext context_; | 206 ChromotingHostContext context_; |
| 199 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 207 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 200 | 208 |
| 201 FilePath auth_config_path_; | 209 FilePath auth_config_path_; |
| 202 FilePath host_config_path_; | 210 FilePath host_config_path_; |
| 203 | 211 |
| 204 std::string host_id_; | 212 std::string host_id_; |
| 205 HostKeyPair key_pair_; | 213 HostKeyPair key_pair_; |
| 214 protocol::SharedSecretHash host_secret_hash_; |
| 206 std::string xmpp_login_; | 215 std::string xmpp_login_; |
| 207 std::string xmpp_auth_token_; | 216 std::string xmpp_auth_token_; |
| 208 std::string xmpp_auth_service_; | 217 std::string xmpp_auth_service_; |
| 209 | 218 |
| 210 scoped_ptr<SignalStrategy> signal_strategy_; | 219 scoped_ptr<SignalStrategy> signal_strategy_; |
| 211 scoped_ptr<SignalingConnector> signaling_connector_; | 220 scoped_ptr<SignalingConnector> signaling_connector_; |
| 212 scoped_ptr<DesktopEnvironment> desktop_environment_; | 221 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 213 scoped_ptr<remoting::HeartbeatSender> heartbeat_sender_; | 222 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 214 scoped_ptr<LogToServer> log_to_server_; | 223 scoped_ptr<LogToServer> log_to_server_; |
| 215 scoped_ptr<HostEventLogger> host_event_logger_; | 224 scoped_ptr<HostEventLogger> host_event_logger_; |
| 216 scoped_refptr<ChromotingHost> host_; | 225 scoped_refptr<ChromotingHost> host_; |
| 217 }; | 226 }; |
| 218 | 227 |
| 219 } // namespace remoting | 228 } // namespace remoting |
| 220 | 229 |
| 221 int main(int argc, char** argv) { | 230 int main(int argc, char** argv) { |
| 222 CommandLine::Init(argc, argv); | 231 CommandLine::Init(argc, argv); |
| 223 | 232 |
| 224 // This object instance is required by Chrome code (for example, | 233 // This object instance is required by Chrome code (for example, |
| 225 // LazyInstance, MessageLoop). | 234 // LazyInstance, MessageLoop). |
| 226 base::AtExitManager exit_manager; | 235 base::AtExitManager exit_manager; |
| 227 | 236 |
| 228 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 237 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 229 | 238 |
| 230 #if defined(TOOLKIT_USES_GTK) | 239 #if defined(TOOLKIT_USES_GTK) |
| 231 // Required for any calls into GTK functions, such as the Disconnect and | 240 // Required for any calls into GTK functions, such as the Disconnect and |
| 232 // Continue windows, though these should not be used for the Me2Me case | 241 // Continue windows, though these should not be used for the Me2Me case |
| 233 // (crbug.com/104377). | 242 // (crbug.com/104377). |
| 234 gfx::GtkInitFromCommandLine(*cmd_line); | 243 gfx::GtkInitFromCommandLine(*cmd_line); |
| 235 #endif // TOOLKIT_USES_GTK | 244 #endif // TOOLKIT_USES_GTK |
| 236 | 245 |
| 237 remoting::HostProcess me2me_host; | 246 remoting::HostProcess me2me_host; |
| 238 me2me_host.InitWithCommandLine(cmd_line); | 247 me2me_host.InitWithCommandLine(cmd_line); |
| 239 | 248 |
| 240 return me2me_host.Run(); | 249 return me2me_host.Run(); |
| 241 } | 250 } |
| OLD | NEW |