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

Side by Side Diff: remoting/host/plugin/host_script_object.cc

Issue 10804040: [Chromoting] Refactor the host policy watcher so that policies can easily be added. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for Windows. Created 8 years, 5 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 | Annotate | Revision Log
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 #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"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
17 #include "remoting/base/auth_token_util.h" 17 #include "remoting/base/auth_token_util.h"
18 #include "remoting/host/chromoting_host.h" 18 #include "remoting/host/chromoting_host.h"
19 #include "remoting/host/chromoting_host_context.h" 19 #include "remoting/host/chromoting_host_context.h"
20 #include "remoting/host/desktop_environment.h" 20 #include "remoting/host/desktop_environment.h"
21 #include "remoting/host/host_config.h" 21 #include "remoting/host/host_config.h"
22 #include "remoting/host/host_key_pair.h" 22 #include "remoting/host/host_key_pair.h"
23 #include "remoting/host/host_secret.h" 23 #include "remoting/host/host_secret.h"
24 #include "remoting/host/it2me_host_user_interface.h" 24 #include "remoting/host/it2me_host_user_interface.h"
25 #include "remoting/host/network_settings.h" 25 #include "remoting/host/network_settings.h"
26 #include "remoting/host/pin_hash.h" 26 #include "remoting/host/pin_hash.h"
27 #include "remoting/host/plugin/daemon_controller.h" 27 #include "remoting/host/plugin/daemon_controller.h"
28 #include "remoting/host/plugin/host_log_handler.h" 28 #include "remoting/host/plugin/host_log_handler.h"
29 #include "remoting/host/policy_hack/nat_policy.h" 29 #include "remoting/host/policy_hack/policy_watcher.h"
30 #include "remoting/host/register_support_host_request.h" 30 #include "remoting/host/register_support_host_request.h"
31 #include "remoting/host/session_manager_factory.h" 31 #include "remoting/host/session_manager_factory.h"
32 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 32 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
33 #include "remoting/protocol/it2me_host_authenticator_factory.h" 33 #include "remoting/protocol/it2me_host_authenticator_factory.h"
34 34
35 namespace remoting { 35 namespace remoting {
36 36
37 namespace { 37 namespace {
38 38
39 const char* kAttrNameAccessCode = "accessCode"; 39 const char* kAttrNameAccessCode = "accessCode";
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 97 }
98 98
99 HostNPScriptObject::~HostNPScriptObject() { 99 HostNPScriptObject::~HostNPScriptObject() {
100 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 100 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
101 101
102 HostLogHandler::UnregisterLoggingScriptObject(this); 102 HostLogHandler::UnregisterLoggingScriptObject(this);
103 103
104 plugin_task_runner_->Detach(); 104 plugin_task_runner_->Detach();
105 105
106 // Stop listening for policy updates. 106 // Stop listening for policy updates.
107 if (nat_policy_.get()) { 107 if (policy_watcher_.get()) {
108 base::WaitableEvent nat_policy_stopped_(true, false); 108 base::WaitableEvent policy_watcher_stopped_(true, false);
109 nat_policy_->StopWatching(&nat_policy_stopped_); 109 policy_watcher_->StopWatching(&policy_watcher_stopped_);
110 nat_policy_stopped_.Wait(); 110 policy_watcher_stopped_.Wait();
111 nat_policy_.reset(); 111 policy_watcher_.reset();
112 } 112 }
113 113
114 if (host_context_.get()) { 114 if (host_context_.get()) {
115 // Disconnect synchronously. We cannot disconnect asynchronously 115 // Disconnect synchronously. We cannot disconnect asynchronously
116 // here because |host_context_| needs to be stopped on the plugin 116 // here because |host_context_| needs to be stopped on the plugin
117 // thread, but the plugin thread may not exist after the instance 117 // thread, but the plugin thread may not exist after the instance
118 // is destroyed. 118 // is destroyed.
119 disconnected_event_.Reset(); 119 disconnected_event_.Reset();
120 DisconnectInternal(); 120 DisconnectInternal();
121 disconnected_event_.Wait(); 121 disconnected_event_.Wait();
(...skipping 15 matching lines...) Expand all
137 bool HostNPScriptObject::Init() { 137 bool HostNPScriptObject::Init() {
138 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 138 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
139 VLOG(2) << "Init"; 139 VLOG(2) << "Init";
140 140
141 host_context_.reset(new ChromotingHostContext(plugin_task_runner_)); 141 host_context_.reset(new ChromotingHostContext(plugin_task_runner_));
142 if (!host_context_->Start()) { 142 if (!host_context_->Start()) {
143 host_context_.reset(); 143 host_context_.reset();
144 return false; 144 return false;
145 } 145 }
146 146
147 nat_policy_.reset( 147 policy_watcher_.reset(
148 policy_hack::NatPolicy::Create(host_context_->network_task_runner())); 148 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner()));
149 nat_policy_->StartWatching( 149 policy_watcher_->StartWatching(
150 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, 150 base::Bind(&HostNPScriptObject::OnPolicyUpdate,
151 base::Unretained(this))); 151 base::Unretained(this)));
152 return true; 152 return true;
153 } 153 }
154 154
155 bool HostNPScriptObject::HasMethod(const std::string& method_name) { 155 bool HostNPScriptObject::HasMethod(const std::string& method_name) {
156 VLOG(2) << "HasMethod " << method_name; 156 VLOG(2) << "HasMethod " << method_name;
157 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); 157 CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_);
158 return (method_name == kFuncNameConnect || 158 return (method_name == kFuncNameConnect ||
159 method_name == kFuncNameDisconnect || 159 method_name == kFuncNameDisconnect ||
160 method_name == kFuncNameLocalize || 160 method_name == kFuncNameLocalize ||
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 base::Unretained(this)))); 884 base::Unretained(this))));
885 } 885 }
886 } 886 }
887 887
888 void HostNPScriptObject::OnShutdownFinished() { 888 void HostNPScriptObject::OnShutdownFinished() {
889 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 889 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
890 890
891 disconnected_event_.Signal(); 891 disconnected_event_.Signal();
892 } 892 }
893 893
894 void HostNPScriptObject::OnPolicyUpdate(
895 scoped_ptr<base::DictionaryValue> policies) {
896 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
897 host_context_->network_task_runner()->PostTask(
898 FROM_HERE,
899 base::Bind(&HostNPScriptObject::OnPolicyUpdate,
900 base::Unretained(this), base::Passed(&policies)));
901 return;
902 }
903
904 bool bool_value;
905 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName,
906 &bool_value)) {
907 OnNatPolicyUpdate(bool_value);
908 }
909 }
910
894 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { 911 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) {
895 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 912 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
896 host_context_->network_task_runner()->PostTask( 913 host_context_->network_task_runner()->PostTask(
897 FROM_HERE, 914 FROM_HERE,
898 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, 915 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate,
899 base::Unretained(this), nat_traversal_enabled)); 916 base::Unretained(this), nat_traversal_enabled));
900 return; 917 return;
901 } 918 }
902 919
903 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled; 920 VLOG(2) << "OnNatPolicyUpdate: " << nat_traversal_enabled;
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 return is_good; 1243 return is_good;
1227 } 1244 }
1228 1245
1229 void HostNPScriptObject::SetException(const std::string& exception_string) { 1246 void HostNPScriptObject::SetException(const std::string& exception_string) {
1230 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1247 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1231 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1248 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1232 LOG(INFO) << exception_string; 1249 LOG(INFO) << exception_string;
1233 } 1250 }
1234 1251
1235 } // namespace remoting 1252 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.h ('k') | remoting/host/policy_hack/fake_policy_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698