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

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: 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
« no previous file with comments | « remoting/host/policy_hack/policy_watcher_win.cc ('k') | remoting/remoting.gyp » ('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 // 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 23 matching lines...) Expand all
34 #include "remoting/host/chromoting_host_context.h" 34 #include "remoting/host/chromoting_host_context.h"
35 #include "remoting/host/desktop_environment.h" 35 #include "remoting/host/desktop_environment.h"
36 #include "remoting/host/event_executor.h" 36 #include "remoting/host/event_executor.h"
37 #include "remoting/host/heartbeat_sender.h" 37 #include "remoting/host/heartbeat_sender.h"
38 #include "remoting/host/host_config.h" 38 #include "remoting/host/host_config.h"
39 #include "remoting/host/host_event_logger.h" 39 #include "remoting/host/host_event_logger.h"
40 #include "remoting/host/host_user_interface.h" 40 #include "remoting/host/host_user_interface.h"
41 #include "remoting/host/json_host_config.h" 41 #include "remoting/host/json_host_config.h"
42 #include "remoting/host/log_to_server.h" 42 #include "remoting/host/log_to_server.h"
43 #include "remoting/host/network_settings.h" 43 #include "remoting/host/network_settings.h"
44 #include "remoting/host/policy_hack/nat_policy.h" 44 #include "remoting/host/policy_hack/policy_watcher.h"
45 #include "remoting/host/session_manager_factory.h" 45 #include "remoting/host/session_manager_factory.h"
46 #include "remoting/host/signaling_connector.h" 46 #include "remoting/host/signaling_connector.h"
47 #include "remoting/host/usage_stats_consent.h" 47 #include "remoting/host/usage_stats_consent.h"
48 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 48 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
49 #include "remoting/protocol/me2me_host_authenticator_factory.h" 49 #include "remoting/protocol/me2me_host_authenticator_factory.h"
50 50
51 #if defined(OS_MACOSX) 51 #if defined(OS_MACOSX)
52 #include "base/mac/scoped_nsautorelease_pool.h" 52 #include "base/mac/scoped_nsautorelease_pool.h"
53 #include "remoting/host/sighup_listener_mac.h" 53 #include "remoting/host/sighup_listener_mac.h"
54 #endif 54 #endif
(...skipping 151 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
« no previous file with comments | « remoting/host/policy_hack/policy_watcher_win.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698