host_stopper.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2020 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. #ifndef REMOTING_HOST_SETUP_HOST_STOPPER_H_
  5. #define REMOTING_HOST_SETUP_HOST_STOPPER_H_
  6. #include "base/callback.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "base/values.h"
  9. #include "remoting/host/setup/daemon_controller.h"
  10. #include "remoting/host/setup/service_client.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. namespace remoting {
  13. // A helper class that stops and unregisters a host.
  14. class HostStopper final : public ServiceClient::Delegate {
  15. public:
  16. HostStopper(std::unique_ptr<ServiceClient> service_client,
  17. scoped_refptr<DaemonController> daemon_controller);
  18. HostStopper(const HostStopper&) = delete;
  19. HostStopper& operator=(const HostStopper&) = delete;
  20. ~HostStopper() override;
  21. // Stops the host running on the local computer, if any, and unregisters it.
  22. void StopLocalHost(std::string access_token, base::OnceClosure on_done);
  23. private:
  24. void OnConfigLoaded(absl::optional<base::Value::Dict> config);
  25. void StopHost();
  26. void OnStopped(DaemonController::AsyncResult);
  27. // remoting::ServiceClient::Delegate
  28. void OnHostRegistered(const std::string& authorization_code) override;
  29. void OnHostUnregistered() override;
  30. void OnOAuthError() override;
  31. void OnNetworkError(int response_code) override;
  32. std::unique_ptr<remoting::ServiceClient> service_client_;
  33. scoped_refptr<remoting::DaemonController> daemon_controller_;
  34. std::string access_token_;
  35. base::OnceClosure on_done_;
  36. base::WeakPtr<HostStopper> weak_ptr_;
  37. base::WeakPtrFactory<HostStopper> weak_ptr_factory_{this};
  38. };
  39. } // namespace remoting
  40. #endif // REMOTING_HOST_SETUP_HOST_STOPPER_H_