OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/it2me/it2me_native_messaging_host.h" | 5 #include "remoting/host/it2me/it2me_native_messaging_host.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 // Called when malformed policies are detected. | 76 // Called when malformed policies are detected. |
77 void OnPolicyError() { | 77 void OnPolicyError() { |
78 // TODO(joedow): Report the policy error to the user. crbug.com/433009 | 78 // TODO(joedow): Report the policy error to the user. crbug.com/433009 |
79 NOTIMPLEMENTED(); | 79 NOTIMPLEMENTED(); |
80 } | 80 } |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 It2MeNativeMessagingHost::It2MeNativeMessagingHost( | 84 It2MeNativeMessagingHost::It2MeNativeMessagingHost( |
85 bool needs_elevation, | 85 bool needs_elevation, |
86 policy::PolicyService* policy_service, | 86 std::unique_ptr<PolicyWatcher> policy_watcher, |
87 std::unique_ptr<ChromotingHostContext> context, | 87 std::unique_ptr<ChromotingHostContext> context, |
88 std::unique_ptr<It2MeHostFactory> factory) | 88 std::unique_ptr<It2MeHostFactory> factory) |
89 : needs_elevation_(needs_elevation), | 89 : needs_elevation_(needs_elevation), |
90 host_context_(std::move(context)), | 90 host_context_(std::move(context)), |
91 factory_(std::move(factory)), | 91 factory_(std::move(factory)), |
92 policy_service_(policy_service), | 92 policy_watcher_(std::move(policy_watcher)), |
93 policy_watcher_(PolicyWatcher::Create(policy_service_, | |
94 host_context_->file_task_runner())), | |
95 weak_factory_(this) { | 93 weak_factory_(this) { |
96 weak_ptr_ = weak_factory_.GetWeakPtr(); | 94 weak_ptr_ = weak_factory_.GetWeakPtr(); |
97 | 95 |
98 // The policy watcher runs on the |file_task_runner| but we want to run the | 96 // The policy watcher runs on the |file_task_runner| but we want to run the |
99 // update code on |task_runner| so we use a shim to post the callback to the | 97 // update code on |task_runner| so we use a shim to post the callback to the |
100 // preferred task runner. | 98 // preferred task runner. |
101 PolicyWatcher::PolicyUpdatedCallback update_callback = | 99 PolicyWatcher::PolicyUpdatedCallback update_callback = |
102 base::Bind(&It2MeNativeMessagingHost::OnPolicyUpdate, weak_ptr_); | 100 base::Bind(&It2MeNativeMessagingHost::OnPolicyUpdate, weak_ptr_); |
103 policy_watcher_->StartWatching( | 101 policy_watcher_->StartWatching( |
104 base::Bind(&PolicyUpdateCallback, task_runner(), update_callback), | 102 base::Bind(&PolicyUpdateCallback, task_runner(), update_callback), |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 | 308 |
311 #if !defined(NDEBUG) | 309 #if !defined(NDEBUG) |
312 if (!message->GetString("directoryBotJid", &directory_bot_jid)) { | 310 if (!message->GetString("directoryBotJid", &directory_bot_jid)) { |
313 SendErrorAndExit(std::move(response), | 311 SendErrorAndExit(std::move(response), |
314 "'directoryBotJid' not found in request."); | 312 "'directoryBotJid' not found in request."); |
315 return; | 313 return; |
316 } | 314 } |
317 #endif // !defined(NDEBUG) | 315 #endif // !defined(NDEBUG) |
318 | 316 |
319 // Create the It2Me host and start connecting. | 317 // Create the It2Me host and start connecting. |
320 it2me_host_ = factory_->CreateIt2MeHost( | 318 it2me_host_ = factory_->CreateIt2MeHost(host_context_->Copy(), weak_ptr_, |
321 host_context_->Copy(), policy_service_, weak_ptr_, | 319 std::move(signal_strategy), username, |
322 std::move(signal_strategy), username, directory_bot_jid); | 320 directory_bot_jid); |
321 it2me_host_->OnPolicyUpdate(policy_watcher_->GetCurrentPolicies()); | |
323 it2me_host_->Connect(); | 322 it2me_host_->Connect(); |
324 | 323 |
325 SendMessageToClient(std::move(response)); | 324 SendMessageToClient(std::move(response)); |
326 } | 325 } |
327 | 326 |
328 void It2MeNativeMessagingHost::ProcessDisconnect( | 327 void It2MeNativeMessagingHost::ProcessDisconnect( |
329 std::unique_ptr<base::DictionaryValue> message, | 328 std::unique_ptr<base::DictionaryValue> message, |
330 std::unique_ptr<base::DictionaryValue> response) { | 329 std::unique_ptr<base::DictionaryValue> response) { |
331 DCHECK(task_runner()->BelongsToCurrentThread()); | 330 DCHECK(task_runner()->BelongsToCurrentThread()); |
332 DCHECK(policy_received_); | 331 DCHECK(policy_received_); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 } | 461 } |
463 | 462 |
464 /* static */ | 463 /* static */ |
465 std::string It2MeNativeMessagingHost::HostStateToString( | 464 std::string It2MeNativeMessagingHost::HostStateToString( |
466 It2MeHostState host_state) { | 465 It2MeHostState host_state) { |
467 return ValueToName(kIt2MeHostStates, host_state); | 466 return ValueToName(kIt2MeHostStates, host_state); |
468 } | 467 } |
469 | 468 |
470 void It2MeNativeMessagingHost::OnPolicyUpdate( | 469 void It2MeNativeMessagingHost::OnPolicyUpdate( |
471 std::unique_ptr<base::DictionaryValue> policies) { | 470 std::unique_ptr<base::DictionaryValue> policies) { |
472 if (policy_received_) { | 471 // Don't dynamically change the elevation status since we don't have a good |
473 // Don't dynamically change how the host operates since we don't have a good | 472 // way to communicate changes to the user. |
474 // way to communicate changes to the user. | 473 if (!policy_received_) { |
475 return; | 474 bool allow_elevated_host = false; |
475 if (!policies->GetBoolean( | |
476 policy::key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, | |
477 &allow_elevated_host)) { | |
478 LOG(WARNING) << "Failed to retrieve elevated host policy value."; | |
479 } | |
480 #if defined(OS_WIN) | |
481 LOG(INFO) << "Allow UiAccess for Remote Assistance: " | |
482 << allow_elevated_host; | |
483 #endif // defined(OS_WIN) | |
484 | |
485 policy_received_ = true; | |
486 | |
487 // If |allow_elevated_host| is false, then we will fall back to using a host | |
488 // running in the current context regardless of the elevation request. This | |
489 // may not be ideal, but is still functional. | |
490 needs_elevation_ = needs_elevation_ && allow_elevated_host; | |
491 if (!pending_connect_.is_null()) { | |
joedow
2017/05/05 14:42:15
nit: the style for this has changed, the preferred
Jamie
2017/05/05 16:49:05
Done, here and above.
| |
492 base::ResetAndReturn(&pending_connect_).Run(); | |
493 } | |
476 } | 494 } |
477 | 495 |
478 bool allow_elevated_host = false; | 496 if (it2me_host_.get()) { |
479 if (!policies->GetBoolean( | 497 it2me_host_->OnPolicyUpdate(std::move(policies)); |
480 policy::key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, | |
481 &allow_elevated_host)) { | |
482 LOG(WARNING) << "Failed to retrieve elevated host policy value."; | |
483 } | |
484 #if defined(OS_WIN) | |
485 LOG(INFO) << "Allow UiAccess for Remote Assistance: " << allow_elevated_host; | |
486 #endif // defined(OS_WIN) | |
487 | |
488 policy_received_ = true; | |
489 | |
490 // If |allow_elevated_host| is false, then we will fall back to using a host | |
491 // running in the current context regardless of the elevation request. This | |
492 // may not be ideal, but is still functional. | |
493 needs_elevation_ = needs_elevation_ && allow_elevated_host; | |
494 if (!pending_connect_.is_null()) { | |
495 base::ResetAndReturn(&pending_connect_).Run(); | |
496 } | 498 } |
497 } | 499 } |
498 | 500 |
499 #if defined(OS_WIN) | 501 #if defined(OS_WIN) |
500 | 502 |
501 bool It2MeNativeMessagingHost::DelegateToElevatedHost( | 503 bool It2MeNativeMessagingHost::DelegateToElevatedHost( |
502 std::unique_ptr<base::DictionaryValue> message) { | 504 std::unique_ptr<base::DictionaryValue> message) { |
503 DCHECK(task_runner()->BelongsToCurrentThread()); | 505 DCHECK(task_runner()->BelongsToCurrentThread()); |
504 DCHECK(needs_elevation_); | 506 DCHECK(needs_elevation_); |
505 | 507 |
(...skipping 24 matching lines...) Expand all Loading... | |
530 | 532 |
531 bool It2MeNativeMessagingHost::DelegateToElevatedHost( | 533 bool It2MeNativeMessagingHost::DelegateToElevatedHost( |
532 std::unique_ptr<base::DictionaryValue> message) { | 534 std::unique_ptr<base::DictionaryValue> message) { |
533 NOTREACHED(); | 535 NOTREACHED(); |
534 return false; | 536 return false; |
535 } | 537 } |
536 | 538 |
537 #endif // !defined(OS_WIN) | 539 #endif // !defined(OS_WIN) |
538 | 540 |
539 } // namespace remoting | 541 } // namespace remoting |
OLD | NEW |