remote_support_host_ash.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/host/chromeos/remote_support_host_ash.h"
  5. #include <utility>
  6. #include <stddef.h>
  7. #include "base/notreached.h"
  8. #include "base/strings/stringize_macros.h"
  9. #include "remoting/host/chromeos/remoting_service.h"
  10. #include "remoting/host/chromoting_host_context.h"
  11. #include "remoting/host/it2me/it2me_constants.h"
  12. #include "remoting/host/it2me/it2me_native_messaging_host_ash.h"
  13. #include "remoting/host/policy_watcher.h"
  14. namespace remoting {
  15. RemoteSupportHostAsh::RemoteSupportHostAsh(base::OnceClosure cleanup_callback)
  16. : cleanup_callback_(std::move(cleanup_callback)) {}
  17. RemoteSupportHostAsh::~RemoteSupportHostAsh() = default;
  18. void RemoteSupportHostAsh::StartSession(
  19. mojom::SupportSessionParamsPtr params,
  20. const absl::optional<ChromeOsEnterpriseParams>& enterprise_params,
  21. StartSessionCallback callback) {
  22. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  23. // Ensure there is at most one active remote support connection.
  24. // Since we are initiating the disconnect, don't run the cleanup callback.
  25. if (it2me_native_message_host_ash_) {
  26. auto temp = std::move(it2me_native_message_host_ash_);
  27. temp->Disconnect();
  28. }
  29. it2me_native_message_host_ash_ =
  30. std::make_unique<It2MeNativeMessageHostAsh>();
  31. mojo::PendingReceiver<mojom::SupportHostObserver> pending_receiver =
  32. it2me_native_message_host_ash_->Start(
  33. RemotingService::Get().CreateHostContext(),
  34. RemotingService::Get().CreatePolicyWatcher());
  35. mojom::StartSupportSessionResponsePtr response =
  36. mojom::StartSupportSessionResponse::NewObserver(
  37. std::move(pending_receiver));
  38. it2me_native_message_host_ash_->Connect(
  39. std::move(params), enterprise_params,
  40. base::BindOnce(std::move(callback), std::move(response)),
  41. base::BindOnce(&RemoteSupportHostAsh::OnSessionDisconnected,
  42. base::Unretained(this)));
  43. }
  44. // static
  45. mojom::SupportHostDetailsPtr RemoteSupportHostAsh::GetHostDetails() {
  46. return mojom::SupportHostDetails::New(
  47. STRINGIZE(VERSION), std::vector<std::string>({kFeatureAccessTokenAuth}));
  48. }
  49. void RemoteSupportHostAsh::OnSessionDisconnected() {
  50. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  51. if (it2me_native_message_host_ash_) {
  52. // Do not access any instance members after |cleanup_callback_| is run as
  53. // this instance will be destroyed by running this.
  54. std::move(cleanup_callback_).Run();
  55. }
  56. }
  57. } // namespace remoting