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

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: rebased 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
« no previous file with comments | « remoting/host/it2me_host_user_interface.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | 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 #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 BasicDesktopEnvironmentFactory()); 216 desktop_environment_factory_.reset(new BasicDesktopEnvironmentFactory());
218 217
219 // Start monitoring configured policies. 218 // Start monitoring configured policies.
220 policy_watcher_.reset( 219 policy_watcher_.reset(
221 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner())); 220 policy_hack::PolicyWatcher::Create(host_context_->network_task_runner()));
222 policy_watcher_->StartWatching( 221 policy_watcher_->StartWatching(
223 base::Bind(&It2MeImpl::OnPolicyUpdate, this)); 222 base::Bind(&It2MeImpl::OnPolicyUpdate, this));
224 223
225 // The UserInterface object needs to be created on the UI thread. 224 // The UserInterface object needs to be created on the UI thread.
226 it2me_host_user_interface_.reset( 225 it2me_host_user_interface_.reset(
227 new It2MeHostUserInterface(host_context_->network_task_runner(), 226 new It2MeHostUserInterface(host_context_->network_task_runner(),
228 host_context_->ui_task_runner())); 227 host_context_->ui_task_runner(), ui_strings));
229 it2me_host_user_interface_->Init(); 228 it2me_host_user_interface_->Init();
230 229
231 // Switch to the network thread to start the actual connection. 230 // Switch to the network thread to start the actual connection.
232 host_context_->network_task_runner()->PostTask( 231 host_context_->network_task_runner()->PostTask(
233 FROM_HERE, base::Bind( 232 FROM_HERE, base::Bind(
234 &It2MeImpl::ReadPolicyAndConnect, this, 233 &It2MeImpl::ReadPolicyAndConnect, this,
235 uid, auth_token, auth_service)); 234 uid, auth_token, auth_service));
236 } 235 }
237 236
238 void HostNPScriptObject::It2MeImpl::Disconnect() { 237 void HostNPScriptObject::It2MeImpl::Disconnect() {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 log_to_server_.reset( 373 log_to_server_.reset(
375 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); 374 new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get()));
376 375
377 // Disable audio by default. 376 // Disable audio by default.
378 // TODO(sergeyu): Add UI to enable it. 377 // TODO(sergeyu): Add UI to enable it.
379 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = 378 scoped_ptr<protocol::CandidateSessionConfig> protocol_config =
380 protocol::CandidateSessionConfig::CreateDefault(); 379 protocol::CandidateSessionConfig::CreateDefault();
381 protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get()); 380 protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get());
382 host_->set_protocol_config(protocol_config.Pass()); 381 host_->set_protocol_config(protocol_config.Pass());
383 382
384 // Provide localization strings to the host.
385 host_->SetUiStrings(ui_strings_);
386
387 // Create user interface. 383 // Create user interface.
388 it2me_host_user_interface_->Start(host_.get(), 384 it2me_host_user_interface_->Start(host_.get(),
389 base::Bind(&It2MeImpl::Disconnect, this)); 385 base::Bind(&It2MeImpl::Disconnect, this));
390 386
391 // Create event logger. 387 // Create event logger.
392 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); 388 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
393 389
394 // Connect signaling and start the host. 390 // Connect signaling and start the host.
395 signal_strategy_->Connect(); 391 signal_strategy_->Connect();
396 host_->Start(uid); 392 host_->Start(uid);
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 // Create threads for the Chromoting host & desktop environment to use. 943 // Create threads for the Chromoting host & desktop environment to use.
948 scoped_ptr<ChromotingHostContext> host_context = 944 scoped_ptr<ChromotingHostContext> host_context =
949 ChromotingHostContext::Create(plugin_task_runner_); 945 ChromotingHostContext::Create(plugin_task_runner_);
950 if (!host_context) { 946 if (!host_context) {
951 SetException("connect: failed to start threads"); 947 SetException("connect: failed to start threads");
952 return false; 948 return false;
953 } 949 }
954 950
955 // Create the It2Me host implementation and start connecting. 951 // Create the It2Me host implementation and start connecting.
956 it2me_impl_ = new It2MeImpl( 952 it2me_impl_ = new It2MeImpl(
957 host_context.Pass(), plugin_task_runner_, weak_ptr_, ui_strings_); 953 host_context.Pass(), plugin_task_runner_, weak_ptr_);
958 it2me_impl_->Connect(uid, auth_token, auth_service); 954 it2me_impl_->Connect(uid, auth_token, auth_service, ui_strings_);
959 955
960 return true; 956 return true;
961 } 957 }
962 958
963 bool HostNPScriptObject::Disconnect(const NPVariant* args, 959 bool HostNPScriptObject::Disconnect(const NPVariant* args,
964 uint32_t arg_count, 960 uint32_t arg_count,
965 NPVariant* result) { 961 NPVariant* result) {
966 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 962 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
967 if (arg_count != 0) { 963 if (arg_count != 0) {
968 SetException("disconnect: bad number of arguments"); 964 SetException("disconnect: bad number of arguments");
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 } 1479 }
1484 1480
1485 void HostNPScriptObject::SetException(const std::string& exception_string) { 1481 void HostNPScriptObject::SetException(const std::string& exception_string) {
1486 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1482 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1487 1483
1488 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1484 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1489 LOG(INFO) << exception_string; 1485 LOG(INFO) << exception_string;
1490 } 1486 }
1491 1487
1492 } // namespace remoting 1488 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me_host_user_interface.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698