Chromium Code Reviews| 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. | 5 // This file implements a standalone host process for Me2Me. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 // STARTED->STOPPING | 206 // STARTED->STOPPING |
| 207 // STOPPING_TO_RESTART->STARTED | 207 // STOPPING_TO_RESTART->STARTED |
| 208 // STOPPING_TO_RESTART->STOPPING | 208 // STOPPING_TO_RESTART->STOPPING |
| 209 // STOPPING->STOPPED | 209 // STOPPING->STOPPED |
| 210 // STOPPED->STARTED | 210 // STOPPED->STARTED |
| 211 // | 211 // |
| 212 // |host_| must be nullptr in INITIALIZING and STOPPED states and not | 212 // |host_| must be nullptr in INITIALIZING and STOPPED states and not |
| 213 // nullptr in all other states. | 213 // nullptr in all other states. |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 enum PolicyState { | |
| 217 // Cannot start the host, because a valid policy has not been read yet. | |
| 218 POLICY_INITIALIZING, | |
| 219 | |
| 220 // Policy was loaded successfully. | |
| 221 POLICY_LOADED, | |
| 222 | |
| 223 // Policy error was detected, and we haven't yet sent out a | |
| 224 // host-offline-reason (i.e. because we haven't yet read the config). | |
| 225 POLICY_ERROR_REPORT_PENDING, | |
| 226 | |
| 227 // Policy error was detected, and we have sent out a host-offline-reason. | |
| 228 POLICY_ERROR_REPORTED, | |
| 229 }; | |
| 230 | |
| 216 friend class base::RefCountedThreadSafe<HostProcess>; | 231 friend class base::RefCountedThreadSafe<HostProcess>; |
| 217 ~HostProcess() override; | 232 ~HostProcess() override; |
| 218 | 233 |
| 219 void StartOnNetworkThread(); | 234 void StartOnNetworkThread(); |
| 220 | 235 |
| 221 #if defined(OS_POSIX) | 236 #if defined(OS_POSIX) |
| 222 // Callback passed to RegisterSignalHandler() to handle SIGTERM events. | 237 // Callback passed to RegisterSignalHandler() to handle SIGTERM events. |
| 223 void SigTermHandler(int signal_number); | 238 void SigTermHandler(int signal_number); |
| 224 #endif | 239 #endif |
| 225 | 240 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 238 | 253 |
| 239 // Tear down resources that run on the UI thread. | 254 // Tear down resources that run on the UI thread. |
| 240 void ShutdownOnUiThread(); | 255 void ShutdownOnUiThread(); |
| 241 | 256 |
| 242 // Applies the host config, returning true if successful. | 257 // Applies the host config, returning true if successful. |
| 243 bool ApplyConfig(const base::DictionaryValue& config); | 258 bool ApplyConfig(const base::DictionaryValue& config); |
| 244 | 259 |
| 245 // Handles policy updates, by calling On*PolicyUpdate methods. | 260 // Handles policy updates, by calling On*PolicyUpdate methods. |
| 246 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); | 261 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); |
| 247 void OnPolicyError(); | 262 void OnPolicyError(); |
| 263 void ReportPolicyErrorAndRestartHost(); | |
| 248 void ApplyHostDomainPolicy(); | 264 void ApplyHostDomainPolicy(); |
| 249 void ApplyUsernamePolicy(); | 265 void ApplyUsernamePolicy(); |
| 250 bool OnHostDomainPolicyUpdate(base::DictionaryValue* policies); | 266 bool OnHostDomainPolicyUpdate(base::DictionaryValue* policies); |
| 251 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); | 267 bool OnUsernamePolicyUpdate(base::DictionaryValue* policies); |
| 252 bool OnNatPolicyUpdate(base::DictionaryValue* policies); | 268 bool OnNatPolicyUpdate(base::DictionaryValue* policies); |
| 253 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); | 269 bool OnRelayPolicyUpdate(base::DictionaryValue* policies); |
| 254 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); | 270 bool OnUdpPortPolicyUpdate(base::DictionaryValue* policies); |
| 255 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); | 271 bool OnCurtainPolicyUpdate(base::DictionaryValue* policies); |
| 256 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); | 272 bool OnHostTalkGadgetPrefixPolicyUpdate(base::DictionaryValue* policies); |
| 257 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); | 273 bool OnHostTokenUrlPolicyUpdate(base::DictionaryValue* policies); |
| 258 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); | 274 bool OnPairingPolicyUpdate(base::DictionaryValue* policies); |
| 259 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); | 275 bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies); |
| 260 | 276 |
| 261 scoped_ptr<HostSignalingManager> CreateHostSignalingManager(); | 277 scoped_ptr<HostSignalingManager> CreateHostSignalingManager(); |
| 262 | 278 |
| 263 void StartHostIfReady(); | 279 void StartHostIfReady(); |
| 264 void StartHost(); | 280 void StartHost(); |
| 265 | 281 |
| 266 // Overrides for HostSignalingManager::Listener interface. | 282 // Overrides for HostSignalingManager::Listener interface. |
| 267 void OnHeartbeatSuccessful() override; | 283 void OnHeartbeatSuccessful() override; |
| 268 void OnUnknownHostIdError() override; | 284 void OnUnknownHostIdError() override; |
| 269 void OnAuthFailed() override; | 285 void OnAuthFailed() override; |
| 270 | 286 |
| 271 void RestartHost(); | 287 void RestartHost(); |
| 272 | 288 |
| 273 // Stops the host and shuts down the process with the specified |exit_code|. | 289 // Stops the host and shuts down the process with the specified |exit_code|. |
| 274 void ShutdownHost(HostExitCodes exit_code); | 290 void ShutdownHost(HostExitCodes exit_code); |
| 275 | 291 |
| 276 // Private helper used by ShutdownHost method to initiate sending of | 292 // Starts host shut down with an optional |host_offline_reason|. |
| 277 // host-offline-reason before continuing shutdown. | 293 void ShutdownOnNetworkThread(const std::string* host_offline_reason); |
|
Wez
2015/02/12 02:51:25
Do we need to express "no reason" via nullptr - co
Łukasz Anforowicz
2015/02/12 18:08:01
We can use an empty string. Thanks for bringing t
Wez
2015/02/12 21:07:07
Acknowledged.
| |
| 278 void SendOfflineReasonAndShutdownOnNetworkThread(HostExitCodes exit_code); | 294 void ContinueShutdownOnNetworkThread(); |
| 279 | 295 void OnHostOfflineReasonAck(bool success); |
| 280 void ShutdownOnNetworkThread(); | |
| 281 | 296 |
| 282 #if defined(OS_WIN) | 297 #if defined(OS_WIN) |
| 283 // Initializes the pairing registry on Windows. This should be invoked on the | 298 // Initializes the pairing registry on Windows. This should be invoked on the |
| 284 // network thread. | 299 // network thread. |
| 285 void InitializePairingRegistry( | 300 void InitializePairingRegistry( |
| 286 IPC::PlatformFileForTransit privileged_key, | 301 IPC::PlatformFileForTransit privileged_key, |
| 287 IPC::PlatformFileForTransit unprivileged_key); | 302 IPC::PlatformFileForTransit unprivileged_key); |
| 288 #endif // defined(OS_WIN) | 303 #endif // defined(OS_WIN) |
| 289 | 304 |
| 290 // Crashes the process in response to a daemon's request. The daemon passes | 305 // Crashes the process in response to a daemon's request. The daemon passes |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 318 scoped_refptr<RsaKeyPair> key_pair_; | 333 scoped_refptr<RsaKeyPair> key_pair_; |
| 319 std::string oauth_refresh_token_; | 334 std::string oauth_refresh_token_; |
| 320 std::string serialized_config_; | 335 std::string serialized_config_; |
| 321 std::string host_owner_; | 336 std::string host_owner_; |
| 322 std::string host_owner_email_; | 337 std::string host_owner_email_; |
| 323 bool use_service_account_; | 338 bool use_service_account_; |
| 324 bool enable_vp9_; | 339 bool enable_vp9_; |
| 325 int64_t frame_recorder_buffer_size_; | 340 int64_t frame_recorder_buffer_size_; |
| 326 | 341 |
| 327 scoped_ptr<PolicyWatcher> policy_watcher_; | 342 scoped_ptr<PolicyWatcher> policy_watcher_; |
| 328 bool policies_loaded_; | 343 PolicyState policy_state_; |
| 329 std::string host_domain_; | 344 std::string host_domain_; |
| 330 bool host_username_match_required_; | 345 bool host_username_match_required_; |
| 331 bool allow_nat_traversal_; | 346 bool allow_nat_traversal_; |
| 332 bool allow_relay_; | 347 bool allow_relay_; |
| 333 uint16 min_udp_port_; | 348 uint16 min_udp_port_; |
| 334 uint16 max_udp_port_; | 349 uint16 max_udp_port_; |
| 335 std::string talkgadget_prefix_; | 350 std::string talkgadget_prefix_; |
| 336 bool allow_pairing_; | 351 bool allow_pairing_; |
| 337 | 352 |
| 338 bool curtain_required_; | 353 bool curtain_required_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 }; | 389 }; |
| 375 | 390 |
| 376 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, | 391 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context, |
| 377 int* exit_code_out, | 392 int* exit_code_out, |
| 378 ShutdownWatchdog* shutdown_watchdog) | 393 ShutdownWatchdog* shutdown_watchdog) |
| 379 : context_(context.Pass()), | 394 : context_(context.Pass()), |
| 380 state_(HOST_INITIALIZING), | 395 state_(HOST_INITIALIZING), |
| 381 use_service_account_(false), | 396 use_service_account_(false), |
| 382 enable_vp9_(false), | 397 enable_vp9_(false), |
| 383 frame_recorder_buffer_size_(0), | 398 frame_recorder_buffer_size_(0), |
| 384 policies_loaded_(false), | 399 policy_state_(POLICY_INITIALIZING), |
| 385 host_username_match_required_(false), | 400 host_username_match_required_(false), |
| 386 allow_nat_traversal_(true), | 401 allow_nat_traversal_(true), |
| 387 allow_relay_(true), | 402 allow_relay_(true), |
| 388 min_udp_port_(0), | 403 min_udp_port_(0), |
| 389 max_udp_port_(0), | 404 max_udp_port_(0), |
| 390 allow_pairing_(true), | 405 allow_pairing_(true), |
| 391 curtain_required_(false), | 406 curtain_required_(false), |
| 392 enable_gnubby_auth_(false), | 407 enable_gnubby_auth_(false), |
| 393 enable_window_capture_(false), | 408 enable_window_capture_(false), |
| 394 window_id_(0), | 409 window_id_(0), |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 ShutdownHost(kInvalidHostConfigurationExitCode); | 559 ShutdownHost(kInvalidHostConfigurationExitCode); |
| 545 return; | 560 return; |
| 546 } | 561 } |
| 547 | 562 |
| 548 if (!ApplyConfig(*config)) { | 563 if (!ApplyConfig(*config)) { |
| 549 LOG(ERROR) << "Failed to apply the configuration."; | 564 LOG(ERROR) << "Failed to apply the configuration."; |
| 550 ShutdownHost(kInvalidHostConfigurationExitCode); | 565 ShutdownHost(kInvalidHostConfigurationExitCode); |
| 551 return; | 566 return; |
| 552 } | 567 } |
| 553 | 568 |
| 554 if (state_ == HOST_INITIALIZING) { | 569 if (state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART) { |
| 555 StartHostIfReady(); | 570 StartHostIfReady(); |
| 556 } else if (state_ == HOST_STARTED) { | 571 } else if (state_ == HOST_STARTED) { |
| 557 DCHECK(policies_loaded_); | |
| 558 | |
| 559 // Reapply policies that could be affected by a new config. | 572 // Reapply policies that could be affected by a new config. |
| 573 DCHECK(policy_state_ == POLICY_LOADED); | |
| 560 ApplyHostDomainPolicy(); | 574 ApplyHostDomainPolicy(); |
| 561 ApplyUsernamePolicy(); | 575 ApplyUsernamePolicy(); |
| 562 | 576 |
| 563 // TODO(sergeyu): Here we assume that PIN is the only part of the config | 577 // TODO(sergeyu): Here we assume that PIN is the only part of the config |
| 564 // that may change while the service is running. Change ApplyConfig() to | 578 // that may change while the service is running. Change ApplyConfig() to |
| 565 // detect other changes in the config and restart host if necessary here. | 579 // detect other changes in the config and restart host if necessary here. |
| 566 CreateAuthenticatorFactory(); | 580 CreateAuthenticatorFactory(); |
| 567 } | 581 } |
| 568 } | 582 } |
| 569 | 583 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 // Note: UsernamePolicyUpdate must run after OnCurtainPolicyUpdate. | 988 // Note: UsernamePolicyUpdate must run after OnCurtainPolicyUpdate. |
| 975 restart_required |= OnUsernamePolicyUpdate(policies.get()); | 989 restart_required |= OnUsernamePolicyUpdate(policies.get()); |
| 976 restart_required |= OnNatPolicyUpdate(policies.get()); | 990 restart_required |= OnNatPolicyUpdate(policies.get()); |
| 977 restart_required |= OnRelayPolicyUpdate(policies.get()); | 991 restart_required |= OnRelayPolicyUpdate(policies.get()); |
| 978 restart_required |= OnUdpPortPolicyUpdate(policies.get()); | 992 restart_required |= OnUdpPortPolicyUpdate(policies.get()); |
| 979 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(policies.get()); | 993 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(policies.get()); |
| 980 restart_required |= OnHostTokenUrlPolicyUpdate(policies.get()); | 994 restart_required |= OnHostTokenUrlPolicyUpdate(policies.get()); |
| 981 restart_required |= OnPairingPolicyUpdate(policies.get()); | 995 restart_required |= OnPairingPolicyUpdate(policies.get()); |
| 982 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); | 996 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); |
| 983 | 997 |
| 984 policies_loaded_ = true; | 998 policy_state_ = POLICY_LOADED; |
| 985 | 999 |
| 986 if (state_ == HOST_INITIALIZING) { | 1000 if (state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART) { |
| 987 StartHostIfReady(); | 1001 StartHostIfReady(); |
| 988 } else if (state_ == HOST_STARTED) { | 1002 } else if (state_ == HOST_STARTED) { |
| 989 if (restart_required) | 1003 if (restart_required) |
| 990 RestartHost(); | 1004 RestartHost(); |
| 991 } | 1005 } |
| 992 } | 1006 } |
| 993 | 1007 |
| 994 void HostProcess::OnPolicyError() { | 1008 void HostProcess::OnPolicyError() { |
| 995 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 1009 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 996 context_->network_task_runner()->PostTask( | 1010 context_->network_task_runner()->PostTask( |
| 997 FROM_HERE, base::Bind(&HostProcess::OnPolicyError, this)); | 1011 FROM_HERE, base::Bind(&HostProcess::OnPolicyError, this)); |
| 998 return; | 1012 return; |
| 999 } | 1013 } |
| 1000 | 1014 |
| 1001 ShutdownHost(kInvalidHostConfigurationExitCode); | 1015 if (policy_state_ != POLICY_ERROR_REPORTED) { |
| 1016 policy_state_ = POLICY_ERROR_REPORT_PENDING; | |
| 1017 if (state_ == HOST_INITIALIZING) { | |
| 1018 StartHostIfReady(); | |
| 1019 } else if (state_ == HOST_STARTED) { | |
| 1020 ReportPolicyErrorAndRestartHost(); | |
| 1021 } | |
| 1022 } | |
| 1023 } | |
| 1024 | |
| 1025 void HostProcess::ReportPolicyErrorAndRestartHost() { | |
|
Wez
2015/02/12 02:51:25
Please put some blank lines in this function to br
Łukasz Anforowicz
2015/02/12 18:08:01
Done.
| |
| 1026 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
| 1027 DCHECK_EQ(policy_state_, POLICY_ERROR_REPORT_PENDING); | |
| 1028 LOG(INFO) << "Restarting the host due to policy errors."; | |
| 1029 state_ = HOST_STOPPING_TO_RESTART; | |
| 1030 policy_state_ = POLICY_ERROR_REPORTED; | |
| 1031 std::string host_offline_reason = "POLICY_READ_ERROR"; | |
| 1032 ShutdownOnNetworkThread(&host_offline_reason); | |
| 1002 } | 1033 } |
| 1003 | 1034 |
| 1004 void HostProcess::ApplyHostDomainPolicy() { | 1035 void HostProcess::ApplyHostDomainPolicy() { |
| 1005 if (state_ != HOST_STARTED) | 1036 if (state_ != HOST_STARTED) |
| 1006 return; | 1037 return; |
| 1007 | 1038 |
| 1008 HOST_LOG << "Policy sets host domain: " << host_domain_; | 1039 HOST_LOG << "Policy sets host domain: " << host_domain_; |
| 1009 | 1040 |
| 1010 if (!host_domain_.empty()) { | 1041 if (!host_domain_.empty()) { |
| 1011 // If the user does not have a Google email, their client JID will not be | 1042 // If the user does not have a Google email, their client JID will not be |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1293 } | 1324 } |
| 1294 | 1325 |
| 1295 scoped_ptr<HostSignalingManager> HostProcess::CreateHostSignalingManager() { | 1326 scoped_ptr<HostSignalingManager> HostProcess::CreateHostSignalingManager() { |
| 1296 DCHECK(!host_id_.empty()); // |ApplyConfig| should already have been run. | 1327 DCHECK(!host_id_.empty()); // |ApplyConfig| should already have been run. |
| 1297 | 1328 |
| 1298 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials( | 1329 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials( |
| 1299 new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username, | 1330 new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username, |
| 1300 oauth_refresh_token_, | 1331 oauth_refresh_token_, |
| 1301 use_service_account_)); | 1332 use_service_account_)); |
| 1302 | 1333 |
| 1303 return HostSignalingManager::Create(this, context_->network_task_runner(), | 1334 return HostSignalingManager::Create( |
| 1304 context_->url_request_context_getter(), | 1335 this, context_->url_request_context_getter(), xmpp_server_config_, |
| 1305 xmpp_server_config_, talkgadget_prefix_, | 1336 talkgadget_prefix_, host_id_, key_pair_, directory_bot_jid_, |
| 1306 host_id_, key_pair_, directory_bot_jid_, | 1337 oauth_credentials.Pass()); |
| 1307 oauth_credentials.Pass()); | |
| 1308 } | 1338 } |
| 1309 | 1339 |
| 1310 void HostProcess::StartHostIfReady() { | 1340 void HostProcess::StartHostIfReady() { |
| 1311 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1341 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1312 DCHECK_EQ(state_, HOST_INITIALIZING); | 1342 DCHECK((state_ == HOST_INITIALIZING) || (state_ == HOST_STOPPING_TO_RESTART)); |
| 1313 | 1343 |
| 1314 // Start the host if both the config and the policies are loaded. | 1344 // Start the host if both the config and the policies are loaded. |
| 1315 if (!serialized_config_.empty() && policies_loaded_) | 1345 if (!serialized_config_.empty()) { |
| 1316 StartHost(); | 1346 if (policy_state_ == POLICY_LOADED) { |
| 1347 StartHost(); | |
| 1348 } else if (policy_state_ == POLICY_ERROR_REPORT_PENDING) { | |
| 1349 ReportPolicyErrorAndRestartHost(); | |
| 1350 } | |
| 1351 } | |
| 1317 } | 1352 } |
| 1318 | 1353 |
| 1319 void HostProcess::StartHost() { | 1354 void HostProcess::StartHost() { |
| 1320 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1355 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1321 DCHECK(!host_); | 1356 DCHECK(!host_); |
| 1322 DCHECK(!host_signaling_manager_); | 1357 DCHECK(!host_signaling_manager_); |
| 1323 | 1358 |
| 1324 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || | 1359 DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART || |
| 1325 state_ == HOST_STOPPED) | 1360 state_ == HOST_STOPPED) |
| 1326 << "state_ = " << state_; | 1361 << "state_ = " << state_; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1407 | 1442 |
| 1408 void HostProcess::OnAuthFailed() { | 1443 void HostProcess::OnAuthFailed() { |
| 1409 ShutdownHost(kInvalidOauthCredentialsExitCode); | 1444 ShutdownHost(kInvalidOauthCredentialsExitCode); |
| 1410 } | 1445 } |
| 1411 | 1446 |
| 1412 void HostProcess::RestartHost() { | 1447 void HostProcess::RestartHost() { |
| 1413 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1448 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1414 DCHECK_EQ(state_, HOST_STARTED); | 1449 DCHECK_EQ(state_, HOST_STARTED); |
| 1415 | 1450 |
| 1416 state_ = HOST_STOPPING_TO_RESTART; | 1451 state_ = HOST_STOPPING_TO_RESTART; |
| 1417 ShutdownOnNetworkThread(); | 1452 ShutdownOnNetworkThread(nullptr); |
|
Wez
2015/02/12 02:51:25
Is "no reason" the right thing to report here? Why
Łukasz Anforowicz
2015/02/12 18:08:01
Good point. Done.
I was also struggling with a d
| |
| 1418 } | |
| 1419 | |
| 1420 void HostProcess::SendOfflineReasonAndShutdownOnNetworkThread( | |
| 1421 HostExitCodes exit_code) { | |
| 1422 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
| 1423 DCHECK(host_signaling_manager_); | |
| 1424 host_signaling_manager_.release()->SendHostOfflineReasonAndDelete( | |
| 1425 ExitCodeToString(exit_code), | |
| 1426 base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds)); | |
| 1427 ShutdownOnNetworkThread(); | |
| 1428 } | 1453 } |
| 1429 | 1454 |
| 1430 void HostProcess::ShutdownHost(HostExitCodes exit_code) { | 1455 void HostProcess::ShutdownHost(HostExitCodes exit_code) { |
| 1431 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1456 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1432 | 1457 |
| 1433 *exit_code_out_ = exit_code; | 1458 *exit_code_out_ = exit_code; |
| 1459 std::string host_offline_reason = ExitCodeToString(exit_code); | |
| 1434 | 1460 |
| 1435 switch (state_) { | 1461 switch (state_) { |
| 1436 case HOST_INITIALIZING: | 1462 case HOST_INITIALIZING: |
| 1437 state_ = HOST_STOPPING; | |
| 1438 DCHECK(!host_signaling_manager_); | |
| 1439 host_signaling_manager_ = CreateHostSignalingManager(); | |
| 1440 SendOfflineReasonAndShutdownOnNetworkThread(exit_code); | |
| 1441 break; | |
| 1442 | |
| 1443 case HOST_STARTED: | 1463 case HOST_STARTED: |
| 1444 state_ = HOST_STOPPING; | 1464 state_ = HOST_STOPPING; |
| 1445 SendOfflineReasonAndShutdownOnNetworkThread(exit_code); | 1465 ShutdownOnNetworkThread(&host_offline_reason); |
| 1446 break; | 1466 break; |
| 1447 | 1467 |
| 1448 case HOST_STOPPING_TO_RESTART: | 1468 case HOST_STOPPING_TO_RESTART: |
| 1449 state_ = HOST_STOPPING; | 1469 state_ = HOST_STOPPING; |
| 1450 break; | 1470 break; |
| 1451 | 1471 |
| 1452 case HOST_STOPPING: | 1472 case HOST_STOPPING: |
| 1453 case HOST_STOPPED: | 1473 case HOST_STOPPED: |
| 1454 // Host is already stopped or being stopped. No action is required. | 1474 // Host is already stopped or being stopped. No action is required. |
| 1455 break; | 1475 break; |
| 1456 } | 1476 } |
| 1457 } | 1477 } |
| 1458 | 1478 |
| 1459 void HostProcess::ShutdownOnNetworkThread() { | 1479 void HostProcess::ShutdownOnNetworkThread( |
| 1480 const std::string* host_offline_reason) { | |
| 1460 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 1481 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 1461 | 1482 |
| 1462 host_.reset(); | 1483 host_.reset(); |
| 1463 host_event_logger_.reset(); | 1484 host_event_logger_.reset(); |
| 1464 host_status_logger_.reset(); | 1485 host_status_logger_.reset(); |
| 1465 host_signaling_manager_.reset(); | |
| 1466 host_change_notification_listener_.reset(); | 1486 host_change_notification_listener_.reset(); |
| 1467 | 1487 |
| 1488 if (host_offline_reason == nullptr) { | |
|
Wez
2015/02/12 02:51:25
nit: Please add some comments to these two blocks
Łukasz Anforowicz
2015/02/12 18:08:01
Done (at least I tried to add sensible comments).
Wez
2015/02/12 21:07:07
These look good in terms of content, but instead o
Łukasz Anforowicz
2015/02/12 22:51:13
Done.
| |
| 1489 ContinueShutdownOnNetworkThread(); | |
| 1490 return; | |
| 1491 } | |
| 1492 if (serialized_config_.empty()) { | |
| 1493 HOST_LOG << "SendHostOfflineReason( " << host_offline_reason << ") " | |
| 1494 << "not possible without a config..."; | |
| 1495 ContinueShutdownOnNetworkThread(); | |
| 1496 return; | |
| 1497 } | |
| 1498 | |
| 1499 if (!host_signaling_manager_) { | |
| 1500 host_signaling_manager_ = CreateHostSignalingManager(); | |
| 1501 } | |
| 1502 host_signaling_manager_->SendHostOfflineReason( | |
| 1503 *host_offline_reason, | |
| 1504 base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds), | |
| 1505 base::Bind(&HostProcess::OnHostOfflineReasonAck, base::Unretained(this))); | |
|
Wez
2015/02/12 02:51:25
With things structured as they are, with a nullptr
Łukasz Anforowicz
2015/02/12 18:08:01
Done. I think things look better now.
- I didn't
| |
| 1506 } | |
| 1507 | |
| 1508 void HostProcess::ContinueShutdownOnNetworkThread() { | |
|
Wez
2015/02/12 02:51:25
If you prefer to keep this as-is then I'd suggest
Łukasz Anforowicz
2015/02/12 18:08:01
N/A (I went with one function as you suggested abo
| |
| 1509 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
| 1510 host_signaling_manager_.reset(); | |
| 1511 | |
| 1468 if (state_ == HOST_STOPPING_TO_RESTART) { | 1512 if (state_ == HOST_STOPPING_TO_RESTART) { |
| 1469 StartHost(); | 1513 StartHostIfReady(); |
| 1470 } else if (state_ == HOST_STOPPING) { | 1514 } else if (state_ == HOST_STOPPING) { |
| 1471 state_ = HOST_STOPPED; | 1515 state_ = HOST_STOPPED; |
| 1472 | 1516 |
| 1473 shutdown_watchdog_->SetExitCode(*exit_code_out_); | 1517 shutdown_watchdog_->SetExitCode(*exit_code_out_); |
| 1474 shutdown_watchdog_->Arm(); | 1518 shutdown_watchdog_->Arm(); |
| 1475 | 1519 |
| 1476 config_watcher_.reset(); | 1520 config_watcher_.reset(); |
| 1477 | 1521 |
| 1478 // Complete the rest of shutdown on the main thread. | 1522 // Complete the rest of shutdown on the main thread. |
| 1479 context_->ui_task_runner()->PostTask( | 1523 context_->ui_task_runner()->PostTask( |
| 1480 FROM_HERE, base::Bind(&HostProcess::ShutdownOnUiThread, this)); | 1524 FROM_HERE, base::Bind(&HostProcess::ShutdownOnUiThread, this)); |
| 1481 } else { | 1525 } else { |
| 1482 // This method is only called in STOPPING_TO_RESTART and STOPPING states. | 1526 // This method is only called in STOPPING_TO_RESTART and STOPPING states. |
| 1483 NOTREACHED(); | 1527 NOTREACHED(); |
| 1484 } | 1528 } |
| 1485 } | 1529 } |
| 1486 | 1530 |
| 1531 void HostProcess::OnHostOfflineReasonAck(bool success) { | |
| 1532 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
|
Wez
2015/02/12 02:51:25
As above, suggest blank line between the pre-condi
Łukasz Anforowicz
2015/02/12 18:08:01
Done.
| |
| 1533 if (success) { | |
| 1534 HOST_LOG << "SendHostOfflineReason: succeeded"; | |
| 1535 } else { | |
| 1536 HOST_LOG << "SendHostOfflineReason: timed out"; | |
| 1537 } | |
| 1538 | |
| 1539 ContinueShutdownOnNetworkThread(); | |
| 1540 } | |
| 1541 | |
| 1487 void HostProcess::OnCrash(const std::string& function_name, | 1542 void HostProcess::OnCrash(const std::string& function_name, |
| 1488 const std::string& file_name, | 1543 const std::string& file_name, |
| 1489 const int& line_number) { | 1544 const int& line_number) { |
| 1490 char message[1024]; | 1545 char message[1024]; |
| 1491 base::snprintf(message, sizeof(message), | 1546 base::snprintf(message, sizeof(message), |
| 1492 "Requested by %s at %s, line %d.", | 1547 "Requested by %s at %s, line %d.", |
| 1493 function_name.c_str(), file_name.c_str(), line_number); | 1548 function_name.c_str(), file_name.c_str(), line_number); |
| 1494 base::debug::Alias(message); | 1549 base::debug::Alias(message); |
| 1495 | 1550 |
| 1496 // The daemon requested us to crash the process. | 1551 // The daemon requested us to crash the process. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1542 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); | 1597 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); |
| 1543 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); | 1598 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); |
| 1544 | 1599 |
| 1545 // Run the main (also UI) message loop until the host no longer needs it. | 1600 // Run the main (also UI) message loop until the host no longer needs it. |
| 1546 message_loop.Run(); | 1601 message_loop.Run(); |
| 1547 | 1602 |
| 1548 return exit_code; | 1603 return exit_code; |
| 1549 } | 1604 } |
| 1550 | 1605 |
| 1551 } // namespace remoting | 1606 } // namespace remoting |
| OLD | NEW |