Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(776)

Side by Side Diff: remoting/host/remoting_me2me_host.cc

Issue 886913002: Always run PolicyWatcher on UI thread in It2Me host. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/policy_watcher_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 270
271 // Stops the host and shuts down the process with the specified |exit_code|. 271 // Stops the host and shuts down the process with the specified |exit_code|.
272 void ShutdownHost(HostExitCodes exit_code); 272 void ShutdownHost(HostExitCodes exit_code);
273 273
274 // Private helper used by ShutdownHost method to initiate sending of 274 // Private helper used by ShutdownHost method to initiate sending of
275 // host-offline-reason before continuing shutdown. 275 // host-offline-reason before continuing shutdown.
276 void SendOfflineReasonAndShutdownOnNetworkThread(HostExitCodes exit_code); 276 void SendOfflineReasonAndShutdownOnNetworkThread(HostExitCodes exit_code);
277 277
278 void ShutdownOnNetworkThread(); 278 void ShutdownOnNetworkThread();
279 279
280 void OnPolicyWatcherShutdown();
281
282 #if defined(OS_WIN) 280 #if defined(OS_WIN)
283 // Initializes the pairing registry on Windows. This should be invoked on the 281 // Initializes the pairing registry on Windows. This should be invoked on the
284 // network thread. 282 // network thread.
285 void InitializePairingRegistry( 283 void InitializePairingRegistry(
286 IPC::PlatformFileForTransit privileged_key, 284 IPC::PlatformFileForTransit privileged_key,
287 IPC::PlatformFileForTransit unprivileged_key); 285 IPC::PlatformFileForTransit unprivileged_key);
288 #endif // defined(OS_WIN) 286 #endif // defined(OS_WIN)
289 287
290 // Crashes the process in response to a daemon's request. The daemon passes 288 // Crashes the process in response to a daemon's request. The daemon passes
291 // the location of the code that detected the fatal error resulted in this 289 // the location of the code that detected the fatal error resulted in this
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 ShutdownHost(kInvalidHostConfigurationExitCode); 546 ShutdownHost(kInvalidHostConfigurationExitCode);
549 return; 547 return;
550 } 548 }
551 549
552 if (state_ == HOST_INITIALIZING) { 550 if (state_ == HOST_INITIALIZING) {
553 // TODO(sergeyu): Currently OnPolicyUpdate() assumes that host config is 551 // TODO(sergeyu): Currently OnPolicyUpdate() assumes that host config is
554 // already loaded so PolicyWatcher has to be started here. Separate policy 552 // already loaded so PolicyWatcher has to be started here. Separate policy
555 // loading from policy verifications and move |policy_watcher_| 553 // loading from policy verifications and move |policy_watcher_|
556 // initialization to StartOnNetworkThread(). 554 // initialization to StartOnNetworkThread().
557 policy_watcher_ = 555 policy_watcher_ =
558 PolicyWatcher::Create(nullptr, context_->network_task_runner()); 556 PolicyWatcher::Create(nullptr, context_->file_task_runner());
559 policy_watcher_->StartWatching( 557 policy_watcher_->StartWatching(
560 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)), 558 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)),
561 base::Bind(&HostProcess::OnPolicyError, base::Unretained(this))); 559 base::Bind(&HostProcess::OnPolicyError, base::Unretained(this)));
562 } else { 560 } else {
563 // Reapply policies that could be affected by a new config. 561 // Reapply policies that could be affected by a new config.
564 ApplyHostDomainPolicy(); 562 ApplyHostDomainPolicy();
565 ApplyUsernamePolicy(); 563 ApplyUsernamePolicy();
566 564
567 if (state_ == HOST_STARTED) { 565 if (state_ == HOST_STARTED) {
568 // TODO(sergeyu): Here we assume that PIN is the only part of the config 566 // TODO(sergeyu): Here we assume that PIN is the only part of the config
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 &frame_recorder_buffer_kb); 949 &frame_recorder_buffer_kb);
952 } 950 }
953 if (frame_recorder_buffer_kb > 0) { 951 if (frame_recorder_buffer_kb > 0) {
954 frame_recorder_buffer_size_ = 1024LL * frame_recorder_buffer_kb; 952 frame_recorder_buffer_size_ = 1024LL * frame_recorder_buffer_kb;
955 } 953 }
956 954
957 return true; 955 return true;
958 } 956 }
959 957
960 void HostProcess::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { 958 void HostProcess::OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) {
961 if (!context_->network_task_runner()->BelongsToCurrentThread()) { 959 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
962 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
963 &HostProcess::OnPolicyUpdate, this, base::Passed(&policies)));
964 return;
965 }
966 960
967 bool restart_required = false; 961 bool restart_required = false;
968 restart_required |= OnHostDomainPolicyUpdate(policies.get()); 962 restart_required |= OnHostDomainPolicyUpdate(policies.get());
969 restart_required |= OnCurtainPolicyUpdate(policies.get()); 963 restart_required |= OnCurtainPolicyUpdate(policies.get());
970 // Note: UsernamePolicyUpdate must run after OnCurtainPolicyUpdate. 964 // Note: UsernamePolicyUpdate must run after OnCurtainPolicyUpdate.
971 restart_required |= OnUsernamePolicyUpdate(policies.get()); 965 restart_required |= OnUsernamePolicyUpdate(policies.get());
972 restart_required |= OnNatPolicyUpdate(policies.get()); 966 restart_required |= OnNatPolicyUpdate(policies.get());
973 restart_required |= OnRelayPolicyUpdate(policies.get()); 967 restart_required |= OnRelayPolicyUpdate(policies.get());
974 restart_required |= OnUdpPortPolicyUpdate(policies.get()); 968 restart_required |= OnUdpPortPolicyUpdate(policies.get());
975 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(policies.get()); 969 restart_required |= OnHostTalkGadgetPrefixPolicyUpdate(policies.get());
976 restart_required |= OnHostTokenUrlPolicyUpdate(policies.get()); 970 restart_required |= OnHostTokenUrlPolicyUpdate(policies.get());
977 restart_required |= OnPairingPolicyUpdate(policies.get()); 971 restart_required |= OnPairingPolicyUpdate(policies.get());
978 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get()); 972 restart_required |= OnGnubbyAuthPolicyUpdate(policies.get());
979 973
980 if (state_ == HOST_INITIALIZING) { 974 if (state_ == HOST_INITIALIZING) {
981 StartHost(); 975 StartHost();
982 } else if (state_ == HOST_STARTED && restart_required) { 976 } else if (state_ == HOST_STARTED && restart_required) {
983 RestartHost(); 977 RestartHost();
984 } 978 }
985 } 979 }
986 980
987 void HostProcess::OnPolicyError() { 981 void HostProcess::OnPolicyError() {
988 context_->network_task_runner()->PostTask( 982 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
989 FROM_HERE, 983
990 base::Bind( 984 ShutdownHost(kInvalidHostConfigurationExitCode);
991 &HostProcess::ShutdownHost,
992 this,
993 kInvalidHostConfigurationExitCode));
994 } 985 }
995 986
996 void HostProcess::ApplyHostDomainPolicy() { 987 void HostProcess::ApplyHostDomainPolicy() {
997 HOST_LOG << "Policy sets host domain: " << host_domain_; 988 HOST_LOG << "Policy sets host domain: " << host_domain_;
998 989
999 if (!host_domain_.empty()) { 990 if (!host_domain_.empty()) {
1000 // If the user does not have a Google email, their client JID will not be 991 // If the user does not have a Google email, their client JID will not be
1001 // based on their email. In that case, the username/host domain policies 992 // based on their email. In that case, the username/host domain policies
1002 // would be meaningless, since there is no way to check that the JID 993 // would be meaningless, since there is no way to check that the JID
1003 // trying to connect actually corresponds to the owner email in question. 994 // trying to connect actually corresponds to the owner email in question.
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 1432
1442 if (state_ == HOST_STOPPING_TO_RESTART) { 1433 if (state_ == HOST_STOPPING_TO_RESTART) {
1443 StartHost(); 1434 StartHost();
1444 } else if (state_ == HOST_STOPPING) { 1435 } else if (state_ == HOST_STOPPING) {
1445 state_ = HOST_STOPPED; 1436 state_ = HOST_STOPPED;
1446 1437
1447 shutdown_watchdog_->SetExitCode(*exit_code_out_); 1438 shutdown_watchdog_->SetExitCode(*exit_code_out_);
1448 shutdown_watchdog_->Arm(); 1439 shutdown_watchdog_->Arm();
1449 1440
1450 config_watcher_.reset(); 1441 config_watcher_.reset();
1442 policy_watcher_.reset();
1451 1443
1452 if (policy_watcher_.get()) { 1444 // Complete the rest of shutdown on the main thread.
1453 policy_watcher_->StopWatching( 1445 context_->ui_task_runner()->PostTask(
1454 base::Bind(&HostProcess::OnPolicyWatcherShutdown, this)); 1446 FROM_HERE, base::Bind(&HostProcess::ShutdownOnUiThread, this));
1455 } else {
1456 OnPolicyWatcherShutdown();
1457 }
1458 } else { 1447 } else {
1459 // This method is only called in STOPPING_TO_RESTART and STOPPING states. 1448 // This method is only called in STOPPING_TO_RESTART and STOPPING states.
1460 NOTREACHED(); 1449 NOTREACHED();
1461 } 1450 }
1462 } 1451 }
1463 1452
1464 void HostProcess::OnPolicyWatcherShutdown() {
1465 policy_watcher_.reset();
1466
1467 // Complete the rest of shutdown on the main thread.
1468 context_->ui_task_runner()->PostTask(
1469 FROM_HERE, base::Bind(&HostProcess::ShutdownOnUiThread, this));
1470 }
1471
1472 void HostProcess::OnCrash(const std::string& function_name, 1453 void HostProcess::OnCrash(const std::string& function_name,
1473 const std::string& file_name, 1454 const std::string& file_name,
1474 const int& line_number) { 1455 const int& line_number) {
1475 char message[1024]; 1456 char message[1024];
1476 base::snprintf(message, sizeof(message), 1457 base::snprintf(message, sizeof(message),
1477 "Requested by %s at %s, line %d.", 1458 "Requested by %s at %s, line %d.",
1478 function_name.c_str(), file_name.c_str(), line_number); 1459 function_name.c_str(), file_name.c_str(), line_number);
1479 base::debug::Alias(message); 1460 base::debug::Alias(message);
1480 1461
1481 // The daemon requested us to crash the process. 1462 // The daemon requested us to crash the process.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds)); 1497 base::TimeDelta::FromSeconds(kShutdownTimeoutSeconds));
1517 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog); 1498 new HostProcess(context.Pass(), &exit_code, &shutdown_watchdog);
1518 1499
1519 // Run the main (also UI) message loop until the host no longer needs it. 1500 // Run the main (also UI) message loop until the host no longer needs it.
1520 message_loop.Run(); 1501 message_loop.Run();
1521 1502
1522 return exit_code; 1503 return exit_code;
1523 } 1504 }
1524 1505
1525 } // namespace remoting 1506 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_watcher_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698