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 #include "remoting/host/plugin/host_script_object.h" | 5 #include "remoting/host/plugin/host_script_object.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 const char* kAttrNameDisconnecting = "DISCONNECTING"; | 71 const char* kAttrNameDisconnecting = "DISCONNECTING"; |
72 const char* kAttrNameError = "ERROR"; | 72 const char* kAttrNameError = "ERROR"; |
73 | 73 |
74 const int kMaxLoginAttempts = 5; | 74 const int kMaxLoginAttempts = 5; |
75 | 75 |
76 // We may need to have more than one task running at the same time | 76 // We may need to have more than one task running at the same time |
77 // (e.g. key generation and status update), yet unlikely to ever need | 77 // (e.g. key generation and status update), yet unlikely to ever need |
78 // more than 2 threads. | 78 // more than 2 threads. |
79 const int kMaxWorkerPoolThreads = 2; | 79 const int kMaxWorkerPoolThreads = 2; |
80 | 80 |
81 // Whether a given string ends with a given suffix. | |
82 bool EndsWith(std::string s, std::string suffix) { | |
Sergey Ulanov
2012/07/31 20:59:53
reuse base::EndsWith()?
simonmorris
2012/07/31 23:16:10
Done.
| |
83 if (s.length() < suffix.length()) { | |
84 return false; | |
85 } | |
86 return s.compare(s.length() - suffix.length(), suffix.length(), suffix) == 0; | |
87 } | |
88 | |
81 } // namespace | 89 } // namespace |
82 | 90 |
83 HostNPScriptObject::HostNPScriptObject( | 91 HostNPScriptObject::HostNPScriptObject( |
84 NPP plugin, | 92 NPP plugin, |
85 NPObject* parent, | 93 NPObject* parent, |
86 PluginThreadTaskRunner::Delegate* plugin_thread_delegate) | 94 PluginThreadTaskRunner::Delegate* plugin_thread_delegate) |
87 : plugin_(plugin), | 95 : plugin_(plugin), |
88 parent_(parent), | 96 parent_(parent), |
89 am_currently_logging_(false), | 97 am_currently_logging_(false), |
90 state_(kDisconnected), | 98 state_(kDisconnected), |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), | 543 &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), |
536 uid, auth_token, auth_service)); | 544 uid, auth_token, auth_service)); |
537 return; | 545 return; |
538 } | 546 } |
539 | 547 |
540 if (state_ != kStarting) { | 548 if (state_ != kStarting) { |
541 // Host has been stopped while we were fetching policy. | 549 // Host has been stopped while we were fetching policy. |
542 return; | 550 return; |
543 } | 551 } |
544 | 552 |
553 // Check the host domain policy. | |
554 if (!host_domain_.empty() && | |
555 !EndsWith(uid, std::string("@") + host_domain_)) { | |
556 SetState(kError); | |
557 return; | |
558 } | |
559 | |
545 // Verify that DesktopEnvironment has been created. | 560 // Verify that DesktopEnvironment has been created. |
546 if (desktop_environment_.get() == NULL) { | 561 if (desktop_environment_.get() == NULL) { |
547 SetState(kError); | 562 SetState(kError); |
548 return; | 563 return; |
549 } | 564 } |
550 | 565 |
551 // Generate a key pair for the Host to use. | 566 // Generate a key pair for the Host to use. |
552 // TODO(wez): Move this to the worker thread. | 567 // TODO(wez): Move this to the worker thread. |
553 host_key_pair_.Generate(); | 568 host_key_pair_.Generate(); |
554 | 569 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 case kStarting: | 884 case kStarting: |
870 SetState(kDisconnecting); | 885 SetState(kDisconnecting); |
871 SetState(kDisconnected); | 886 SetState(kDisconnected); |
872 disconnected_event_.Signal(); | 887 disconnected_event_.Signal(); |
873 return; | 888 return; |
874 | 889 |
875 case kDisconnecting: | 890 case kDisconnecting: |
876 return; | 891 return; |
877 | 892 |
878 default: | 893 default: |
879 DCHECK(host_); | |
880 SetState(kDisconnecting); | 894 SetState(kDisconnecting); |
881 | 895 |
896 if (!host_) { | |
897 OnShutdownFinished(); | |
898 return; | |
899 } | |
882 // ChromotingHost::Shutdown() may destroy SignalStrategy | 900 // ChromotingHost::Shutdown() may destroy SignalStrategy |
883 // synchronously, bug SignalStrategy::Listener handlers are not | 901 // synchronously, but SignalStrategy::Listener handlers are not |
884 // allowed to destroy SignalStrategy, so post task to call | 902 // allowed to destroy SignalStrategy, so post task to call |
885 // Shutdown() later. | 903 // Shutdown() later. |
886 host_context_->network_task_runner()->PostTask( | 904 host_context_->network_task_runner()->PostTask( |
887 FROM_HERE, base::Bind( | 905 FROM_HERE, base::Bind( |
888 &ChromotingHost::Shutdown, host_, | 906 &ChromotingHost::Shutdown, host_, |
889 base::Bind(&HostNPScriptObject::OnShutdownFinished, | 907 base::Bind(&HostNPScriptObject::OnShutdownFinished, |
890 base::Unretained(this)))); | 908 base::Unretained(this)))); |
909 return; | |
891 } | 910 } |
892 } | 911 } |
893 | 912 |
894 void HostNPScriptObject::OnShutdownFinished() { | 913 void HostNPScriptObject::OnShutdownFinished() { |
895 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 914 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
896 | 915 |
897 disconnected_event_.Signal(); | 916 disconnected_event_.Signal(); |
898 } | 917 } |
899 | 918 |
900 void HostNPScriptObject::OnPolicyUpdate( | 919 void HostNPScriptObject::OnPolicyUpdate( |
901 scoped_ptr<base::DictionaryValue> policies) { | 920 scoped_ptr<base::DictionaryValue> policies) { |
902 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 921 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { |
903 host_context_->network_task_runner()->PostTask( | 922 host_context_->network_task_runner()->PostTask( |
904 FROM_HERE, | 923 FROM_HERE, |
905 base::Bind(&HostNPScriptObject::OnPolicyUpdate, | 924 base::Bind(&HostNPScriptObject::OnPolicyUpdate, |
906 base::Unretained(this), base::Passed(&policies))); | 925 base::Unretained(this), base::Passed(&policies))); |
907 return; | 926 return; |
908 } | 927 } |
909 | 928 |
910 bool bool_value; | 929 bool bool_value; |
930 std::string string_value; | |
Sergey Ulanov
2012/07/31 20:59:53
move this below to where it's used. Also use a bet
simonmorris
2012/07/31 23:16:10
Done.
| |
911 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, | 931 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, |
912 &bool_value)) { | 932 &bool_value)) { |
913 OnNatPolicyUpdate(bool_value); | 933 UpdateNatPolicy(bool_value); |
934 } | |
935 if (policies->GetString(policy_hack::PolicyWatcher::kHostDomainPolicyName, | |
Sergey Ulanov
2012/07/31 20:59:53
We always expect this value to be present - DCHECK
simonmorris
2012/07/31 23:16:10
PolicyWatcher only emits changed policy values, so
| |
936 &string_value)) { | |
937 UpdateHostDomainPolicy(string_value); | |
938 } | |
939 | |
940 if (!pending_connect_.is_null()) { | |
941 pending_connect_.Run(); | |
942 pending_connect_.Reset(); | |
914 } | 943 } |
915 } | 944 } |
916 | 945 |
917 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { | 946 void HostNPScriptObject::UpdateNatPolicy(bool nat_traversal_enabled) { |
918 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { | 947 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
919 host_context_->network_task_runner()->PostTask( | |
920 FROM_HERE, | |
921 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, | |
922 base::Unretained(this), nat_traversal_enabled)); | |
923 return; | |
924 } | |
925 | 948 |
926 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled; | 949 VLOG(2) << "UpdateNatPolicy: " << nat_traversal_enabled; |
927 | 950 |
928 // When transitioning from enabled to disabled, force disconnect any | 951 // When transitioning from enabled to disabled, force disconnect any |
929 // existing session. | 952 // existing session. |
930 if (nat_traversal_enabled_ && !nat_traversal_enabled) { | 953 if (nat_traversal_enabled_ && !nat_traversal_enabled) { |
931 DisconnectInternal(); | 954 DisconnectInternal(); |
932 } | 955 } |
933 | 956 |
934 { | 957 { |
935 base::AutoLock lock(nat_policy_lock_); | 958 base::AutoLock lock(nat_policy_lock_); |
936 policy_received_ = true; | 959 policy_received_ = true; |
Sergey Ulanov
2012/07/31 20:59:53
This logically belongs to OnPolicyUpdate(). Then y
simonmorris
2012/07/31 23:16:10
I've moved that line to OnPolicyUpdate(). But I th
| |
937 nat_traversal_enabled_ = nat_traversal_enabled; | 960 nat_traversal_enabled_ = nat_traversal_enabled; |
938 } | 961 } |
939 | 962 |
940 UpdateWebappNatPolicy(nat_traversal_enabled_); | 963 UpdateWebappNatPolicy(nat_traversal_enabled_); |
964 } | |
941 | 965 |
942 if (!pending_connect_.is_null()) { | 966 void HostNPScriptObject::UpdateHostDomainPolicy( |
943 pending_connect_.Run(); | 967 const std::string& host_domain) { |
944 pending_connect_.Reset(); | 968 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
969 | |
970 VLOG(2) << "UpdateHostDomainPolicy: " << host_domain; | |
971 | |
972 // When setting a host domain policy, force disconnect any existing session. | |
973 if (!host_domain.empty() && state_ != kStarting) { | |
Sergey Ulanov
2012/07/31 20:59:53
hm. This will disconnect all connection even when
simonmorris
2012/07/31 23:16:10
If the domain hasn't changed, the PolicyWatcher wo
| |
974 DisconnectInternal(); | |
945 } | 975 } |
976 | |
977 host_domain_ = host_domain; | |
946 } | 978 } |
947 | 979 |
948 void HostNPScriptObject::OnReceivedSupportID( | 980 void HostNPScriptObject::OnReceivedSupportID( |
949 bool success, | 981 bool success, |
950 const std::string& support_id, | 982 const std::string& support_id, |
951 const base::TimeDelta& lifetime) { | 983 const base::TimeDelta& lifetime) { |
952 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); | 984 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); |
953 | 985 |
954 if (!success) { | 986 if (!success) { |
955 SetState(kError); | 987 SetState(kError); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1262 return is_good; | 1294 return is_good; |
1263 } | 1295 } |
1264 | 1296 |
1265 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1297 void HostNPScriptObject::SetException(const std::string& exception_string) { |
1266 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 1298 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
1267 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1299 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
1268 LOG(INFO) << exception_string; | 1300 LOG(INFO) << exception_string; |
1269 } | 1301 } |
1270 | 1302 |
1271 } // namespace remoting | 1303 } // namespace remoting |
OLD | NEW |