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

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

Issue 11886051: Turned UiStrings into a singleton so that the continue window does not depend on ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback Created 7 years, 11 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"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } // namespace 79 } // namespace
80 80
81 // Internal implementation of the plugin's It2Me host function. 81 // Internal implementation of the plugin's It2Me host function.
82 class HostNPScriptObject::It2MeImpl 82 class HostNPScriptObject::It2MeImpl
83 : public base::RefCountedThreadSafe<It2MeImpl>, 83 : public base::RefCountedThreadSafe<It2MeImpl>,
84 public HostStatusObserver { 84 public HostStatusObserver {
85 public: 85 public:
86 It2MeImpl( 86 It2MeImpl(
87 scoped_ptr<ChromotingHostContext> context, 87 scoped_ptr<ChromotingHostContext> context,
88 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner, 88 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner,
89 base::WeakPtr<HostNPScriptObject> script_object, 89 base::WeakPtr<HostNPScriptObject> script_object);
90 const UiStrings& ui_strings);
91 90
92 // Methods called by the script object, from the plugin thread. 91 // Methods called by the script object, from the plugin thread.
93 92
94 // Creates It2Me host structures and starts the host. 93 // Creates It2Me host structures and starts the host.
95 void Connect(const std::string& uid, 94 void Connect(const std::string& uid,
96 const std::string& auth_token, 95 const std::string& auth_token,
97 const std::string& auth_service); 96 const std::string& auth_service,
97 const UiStrings& ui_strings);
98 98
99 // Disconnects the host, ready for tear-down. 99 // Disconnects the host, ready for tear-down.
100 // Also called internally, from the network thread. 100 // Also called internally, from the network thread.
101 void Disconnect(); 101 void Disconnect();
102 102
103 // Request a NAT policy notification. 103 // Request a NAT policy notification.
104 void RequestNatPolicy(); 104 void RequestNatPolicy();
105 105
106 // remoting::HostStatusObserver implementation. 106 // remoting::HostStatusObserver implementation.
107 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; 107 virtual void OnAccessDenied(const std::string& jid) OVERRIDE;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Called when initial policies are read, and when they change. 141 // Called when initial policies are read, and when they change.
142 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); 142 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies);
143 143
144 // Handlers for NAT traversal and host domain policies. 144 // Handlers for NAT traversal and host domain policies.
145 void UpdateNatPolicy(bool nat_traversal_enabled); 145 void UpdateNatPolicy(bool nat_traversal_enabled);
146 void UpdateHostDomainPolicy(const std::string& host_domain); 146 void UpdateHostDomainPolicy(const std::string& host_domain);
147 147
148 scoped_ptr<ChromotingHostContext> host_context_; 148 scoped_ptr<ChromotingHostContext> host_context_;
149 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_; 149 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_;
150 base::WeakPtr<HostNPScriptObject> script_object_; 150 base::WeakPtr<HostNPScriptObject> script_object_;
151 UiStrings ui_strings_;
152 151
153 State state_; 152 State state_;
154 153
155 HostKeyPair host_key_pair_; 154 HostKeyPair host_key_pair_;
156 scoped_ptr<SignalStrategy> signal_strategy_; 155 scoped_ptr<SignalStrategy> signal_strategy_;
157 scoped_ptr<RegisterSupportHostRequest> register_request_; 156 scoped_ptr<RegisterSupportHostRequest> register_request_;
158 scoped_ptr<LogToServer> log_to_server_; 157 scoped_ptr<LogToServer> log_to_server_;
159 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; 158 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
160 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; 159 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_;
161 scoped_ptr<HostEventLogger> host_event_logger_; 160 scoped_ptr<HostEventLogger> host_event_logger_;
(...skipping 19 matching lines...) Expand all
181 // it can be executed after at least one successful policy read. This 180 // it can be executed after at least one successful policy read. This
182 // variable contains the thunk if it is necessary. 181 // variable contains the thunk if it is necessary.
183 base::Closure pending_connect_; 182 base::Closure pending_connect_;
184 183
185 DISALLOW_COPY_AND_ASSIGN(It2MeImpl); 184 DISALLOW_COPY_AND_ASSIGN(It2MeImpl);
186 }; 185 };
187 186
188 HostNPScriptObject::It2MeImpl::It2MeImpl( 187 HostNPScriptObject::It2MeImpl::It2MeImpl(
189 scoped_ptr<ChromotingHostContext> host_context, 188 scoped_ptr<ChromotingHostContext> host_context,
190 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner, 189 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner,
191 base::WeakPtr<HostNPScriptObject> script_object, 190 base::WeakPtr<HostNPScriptObject> script_object)
192 const UiStrings& ui_strings)
193 : host_context_(host_context.Pass()), 191 : host_context_(host_context.Pass()),
194 plugin_task_runner_(plugin_task_runner), 192 plugin_task_runner_(plugin_task_runner),
195 script_object_(script_object), 193 script_object_(script_object),
196 ui_strings_(ui_strings),
197 state_(kDisconnected), 194 state_(kDisconnected),
198 failed_login_attempts_(0), 195 failed_login_attempts_(0),
199 nat_traversal_enabled_(false), 196 nat_traversal_enabled_(false),
200 policy_received_(false) { 197 policy_received_(false) {
201 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 198 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
202 } 199 }
203 200
204 void HostNPScriptObject::It2MeImpl::Connect( 201 void HostNPScriptObject::It2MeImpl::Connect(
205 const std::string& uid, 202 const std::string& uid,
206 const std::string& auth_token, 203 const std::string& auth_token,
207 const std::string& auth_service) { 204 const std::string& auth_service,
205 const UiStrings& ui_strings) {
208 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { 206 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) {
209 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 207 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
210 host_context_->ui_task_runner()->PostTask( 208 host_context_->ui_task_runner()->PostTask(
211 FROM_HERE, 209 FROM_HERE,
212 base::Bind(&It2MeImpl::Connect, this, uid, auth_token, auth_service)); 210 base::Bind(&It2MeImpl::Connect, this, uid, auth_token, auth_service,
211 ui_strings));
213 return; 212 return;
214 } 213 }
215 214
216 // Create the desktop environment factory. 215 // Create the desktop environment factory.
217 desktop_environment_factory_.reset(new DesktopEnvironmentFactory( 216 desktop_environment_factory_.reset(new DesktopEnvironmentFactory(
218 host_context_->input_task_runner(), host_context_->ui_task_runner())); 217 host_context_->input_task_runner(), host_context_->ui_task_runner()));
219 218
220 // Start monitoring configured policies. 219 // Start monitoring configured policies.
221 policy_watcher_.reset( 220 policy_watcher_.reset(
222 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner())); 221 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner()));
223 policy_watcher_->StartWatching( 222 policy_watcher_->StartWatching(
224 base::Bind(&It2MeImpl::OnPolicyUpdate, this)); 223 base::Bind(&It2MeImpl::OnPolicyUpdate, this));
225 224
226 // The UserInterface object needs to be created on the UI thread. 225 // The UserInterface object needs to be created on the UI thread.
227 it2me_host_user_interface_.reset( 226 it2me_host_user_interface_.reset(
228 new It2MeHostUserInterface(host_context_->network_task_runner(), 227 new It2MeHostUserInterface(host_context_->network_task_runner(),
229 host_context_->ui_task_runner())); 228 host_context_->ui_task_runner(), ui_strings));
230 it2me_host_user_interface_->Init(); 229 it2me_host_user_interface_->Init();
231 230
232 // Switch to the network thread to start the actual connection. 231 // Switch to the network thread to start the actual connection.
233 host_context_->network_task_runner()->PostTask( 232 host_context_->network_task_runner()->PostTask(
234 FROM_HERE, base::Bind( 233 FROM_HERE, base::Bind(
235 &It2MeImpl::ReadPolicyAndConnect, this, 234 &It2MeImpl::ReadPolicyAndConnect, this,
236 uid, auth_token, auth_service)); 235 uid, auth_token, auth_service));
237 } 236 }
238 237
239 void HostNPScriptObject::It2MeImpl::Disconnect() { 238 void HostNPScriptObject::It2MeImpl::Disconnect() {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 log_to_server_.reset( 372 log_to_server_.reset(
374 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); 373 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get()));
375 374
376 // Disable audio by default. 375 // Disable audio by default.
377 // TODO(sergeyu): Add UI to enable it. 376 // TODO(sergeyu): Add UI to enable it.
378 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = 377 scoped_ptr<protocol::CandidateSessionConfig> protocol_config =
379 protocol::CandidateSessionConfig::CreateDefault(); 378 protocol::CandidateSessionConfig::CreateDefault();
380 protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get()); 379 protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get());
381 host_->set_protocol_config(protocol_config.Pass()); 380 host_->set_protocol_config(protocol_config.Pass());
382 381
383 // Provide localization strings to the host.
384 host_->SetUiStrings(ui_strings_);
385
386 // Create user interface. 382 // Create user interface.
387 it2me_host_user_interface_->Start(host_.get(), 383 it2me_host_user_interface_->Start(host_.get(),
388 base::Bind(&It2MeImpl::Disconnect, this)); 384 base::Bind(&It2MeImpl::Disconnect, this));
389 385
390 // Create event logger. 386 // Create event logger.
391 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); 387 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
392 388
393 // Connect signaling and start the host. 389 // Connect signaling and start the host.
394 signal_strategy_->Connect(); 390 signal_strategy_->Connect();
395 host_->Start(uid); 391 host_->Start(uid);
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 // Create threads for the Chromoting host & desktop environment to use. 942 // Create threads for the Chromoting host & desktop environment to use.
947 scoped_ptr<ChromotingHostContext> host_context = 943 scoped_ptr<ChromotingHostContext> host_context =
948 ChromotingHostContext::Create(plugin_task_runner_); 944 ChromotingHostContext::Create(plugin_task_runner_);
949 if (!host_context) { 945 if (!host_context) {
950 SetException("connect: failed to start threads"); 946 SetException("connect: failed to start threads");
951 return false; 947 return false;
952 } 948 }
953 949
954 // Create the It2Me host implementation and start connecting. 950 // Create the It2Me host implementation and start connecting.
955 it2me_impl_ = new It2MeImpl( 951 it2me_impl_ = new It2MeImpl(
956 host_context.Pass(), plugin_task_runner_, weak_ptr_, ui_strings_); 952 host_context.Pass(), plugin_task_runner_, weak_ptr_);
957 it2me_impl_->Connect(uid, auth_token, auth_service); 953 it2me_impl_->Connect(uid, auth_token, auth_service, ui_strings_);
958 954
959 return true; 955 return true;
960 } 956 }
961 957
962 bool HostNPScriptObject::Disconnect(const NPVariant* args, 958 bool HostNPScriptObject::Disconnect(const NPVariant* args,
963 uint32_t arg_count, 959 uint32_t arg_count,
964 NPVariant* result) { 960 NPVariant* result) {
965 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 961 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
966 if (arg_count != 0) { 962 if (arg_count != 0) {
967 SetException("disconnect: bad number of arguments"); 963 SetException("disconnect: bad number of arguments");
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 } 1478 }
1483 1479
1484 void HostNPScriptObject::SetException(const std::string& exception_string) { 1480 void HostNPScriptObject::SetException(const std::string& exception_string) {
1485 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1481 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1486 1482
1487 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1483 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1488 LOG(INFO) << exception_string; 1484 LOG(INFO) << exception_string;
1489 } 1485 }
1490 1486
1491 } // namespace remoting 1487 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698