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

Side by Side Diff: remoting/host/remoting_me2me_host.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: Pass the policy dictionary as a scoped_ptr. 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 // 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 int Run() { 207 int Run() {
208 if (!LoadConfig()) { 208 if (!LoadConfig()) {
209 return kInvalidHostConfigurationExitCode; 209 return kInvalidHostConfigurationExitCode;
210 } 210 }
211 211
212 #if defined(OS_MACOSX) || defined(OS_WIN) 212 #if defined(OS_MACOSX) || defined(OS_WIN)
213 host_user_interface_.reset(new HostUserInterface(context_.get())); 213 host_user_interface_.reset(new HostUserInterface(context_.get()));
214 #endif 214 #endif
215 215
216 StartWatchingNatPolicy(); 216 StartWatchingPolicy();
217 217
218 #if defined(OS_MACOSX) || defined(OS_WIN) 218 #if defined(OS_MACOSX) || defined(OS_WIN)
219 context_->file_task_runner()->PostTask( 219 context_->file_task_runner()->PostTask(
220 FROM_HERE, 220 FROM_HERE,
221 base::Bind(&HostProcess::ListenForConfigChanges, 221 base::Bind(&HostProcess::ListenForConfigChanges,
222 base::Unretained(this))); 222 base::Unretained(this)));
223 #endif 223 #endif
224 message_loop_.Run(); 224 message_loop_.Run();
225 225
226 #if defined(OS_MACOSX) || defined(OS_WIN) 226 #if defined(OS_MACOSX) || defined(OS_WIN)
227 host_user_interface_.reset(); 227 host_user_interface_.reset();
228 #endif 228 #endif
229 229
230 base::WaitableEvent done_event(true, false); 230 base::WaitableEvent done_event(true, false);
231 nat_policy_->StopWatching(&done_event); 231 policy_watcher_->StopWatching(&done_event);
232 done_event.Wait(); 232 done_event.Wait();
233 nat_policy_.reset(); 233 policy_watcher_.reset();
234 234
235 return exit_code_; 235 return exit_code_;
236 } 236 }
237 237
238 // Overridden from HeartbeatSender::Listener 238 // Overridden from HeartbeatSender::Listener
239 virtual void OnUnknownHostIdError() OVERRIDE { 239 virtual void OnUnknownHostIdError() OVERRIDE {
240 LOG(ERROR) << "Host ID not found."; 240 LOG(ERROR) << "Host ID not found.";
241 Shutdown(kInvalidHostIdExitCode); 241 Shutdown(kInvalidHostIdExitCode);
242 } 242 }
243 243
244 private: 244 private:
245 void StartWatchingNatPolicy() { 245 void StartWatchingPolicy() {
246 nat_policy_.reset( 246 policy_watcher_.reset(
247 policy_hack::NatPolicy::Create(context_->file_task_runner())); 247 policy_hack::PolicyWatcher::Create(context_->file_task_runner()));
248 nat_policy_->StartWatching( 248 policy_watcher_->StartWatching(
249 base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this))); 249 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)));
250 } 250 }
251 251
252 // Read Host config from disk, returning true if successful. 252 // Read Host config from disk, returning true if successful.
253 bool LoadConfig() { 253 bool LoadConfig() {
254 JsonHostConfig host_config(host_config_path_); 254 JsonHostConfig host_config(host_config_path_);
255 JsonHostConfig auth_config(auth_config_path_); 255 JsonHostConfig auth_config(auth_config_path_);
256 256
257 FilePath failed_path; 257 FilePath failed_path;
258 if (!host_config.Read()) { 258 if (!host_config.Read()) {
259 failed_path = host_config_path_; 259 failed_path = host_config_path_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } else if (!auth_config.GetString(kXmppAuthServiceConfigPath, 307 } else if (!auth_config.GetString(kXmppAuthServiceConfigPath,
308 &xmpp_auth_service_)) { 308 &xmpp_auth_service_)) {
309 // For the me2me host, we default to ClientLogin token for chromiumsync 309 // For the me2me host, we default to ClientLogin token for chromiumsync
310 // because earlier versions of the host had no HTTP stack with which to 310 // because earlier versions of the host had no HTTP stack with which to
311 // request an OAuth2 access token. 311 // request an OAuth2 access token.
312 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; 312 xmpp_auth_service_ = kChromotingTokenDefaultServiceName;
313 } 313 }
314 return true; 314 return true;
315 } 315 }
316 316
317 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) {
318 if (!context_->network_task_runner()->BelongsToCurrentThread()) {
319 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
320 &HostProcess::OnPolicyUpdate, base::Unretained(this),
321 base::Passed(&policies)));
322 return;
323 }
324
325 bool bool_value;
326 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName,
327 &bool_value)) {
328 OnNatPolicyUpdate(bool_value);
329 }
330 }
331
317 void OnNatPolicyUpdate(bool nat_traversal_enabled) { 332 void OnNatPolicyUpdate(bool nat_traversal_enabled) {
318 if (!context_->network_task_runner()->BelongsToCurrentThread()) { 333 if (!context_->network_task_runner()->BelongsToCurrentThread()) {
319 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( 334 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
320 &HostProcess::OnNatPolicyUpdate, base::Unretained(this), 335 &HostProcess::OnNatPolicyUpdate, base::Unretained(this),
321 nat_traversal_enabled)); 336 nat_traversal_enabled));
322 return; 337 return;
323 } 338 }
324 339
325 bool policy_changed = allow_nat_traversal_ != nat_traversal_enabled; 340 bool policy_changed = allow_nat_traversal_ != nat_traversal_enabled;
326 allow_nat_traversal_ = nat_traversal_enabled; 341 allow_nat_traversal_ = nat_traversal_enabled;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 std::string host_id_; 506 std::string host_id_;
492 HostKeyPair key_pair_; 507 HostKeyPair key_pair_;
493 protocol::SharedSecretHash host_secret_hash_; 508 protocol::SharedSecretHash host_secret_hash_;
494 std::string xmpp_login_; 509 std::string xmpp_login_;
495 std::string xmpp_auth_token_; 510 std::string xmpp_auth_token_;
496 std::string xmpp_auth_service_; 511 std::string xmpp_auth_service_;
497 512
498 std::string oauth_refresh_token_; 513 std::string oauth_refresh_token_;
499 bool oauth_use_official_client_id_; 514 bool oauth_use_official_client_id_;
500 515
501 scoped_ptr<policy_hack::NatPolicy> nat_policy_; 516 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_;
502 bool allow_nat_traversal_; 517 bool allow_nat_traversal_;
503 scoped_ptr<base::files::FilePathWatcher> config_watcher_; 518 scoped_ptr<base::files::FilePathWatcher> config_watcher_;
504 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; 519 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_;
505 520
506 bool restarting_; 521 bool restarting_;
507 bool shutting_down_; 522 bool shutting_down_;
508 523
509 scoped_ptr<XmppSignalStrategy> signal_strategy_; 524 scoped_ptr<XmppSignalStrategy> signal_strategy_;
510 scoped_ptr<SignalingConnector> signaling_connector_; 525 scoped_ptr<SignalingConnector> signaling_connector_;
511 scoped_ptr<DesktopEnvironment> desktop_environment_; 526 scoped_ptr<DesktopEnvironment> desktop_environment_;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 user32.GetFunctionPointer("SetProcessDPIAware")); 618 user32.GetFunctionPointer("SetProcessDPIAware"));
604 set_process_dpi_aware(); 619 set_process_dpi_aware();
605 } 620 }
606 621
607 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 622 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
608 // the command line from GetCommandLineW(), so we can safely pass NULL here. 623 // the command line from GetCommandLineW(), so we can safely pass NULL here.
609 return main(0, NULL); 624 return main(0, NULL);
610 } 625 }
611 626
612 #endif // defined(OS_WIN) 627 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698