ftl_registration_manager.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2019 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_SIGNALING_FTL_REGISTRATION_MANAGER_H_
  5. #define REMOTING_SIGNALING_FTL_REGISTRATION_MANAGER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback_forward.h"
  9. #include "base/memory/scoped_refptr.h"
  10. #include "base/timer/timer.h"
  11. #include "net/base/backoff_entry.h"
  12. #include "remoting/signaling/registration_manager.h"
  13. namespace network {
  14. class SharedURLLoaderFactory;
  15. } // namespace network
  16. namespace remoting {
  17. namespace ftl {
  18. class SignInGaiaRequest;
  19. class SignInGaiaResponse;
  20. } // namespace ftl
  21. class FtlDeviceIdProvider;
  22. class OAuthTokenGetter;
  23. // Class for registering the user with FTL service.
  24. class FtlRegistrationManager final : public RegistrationManager {
  25. public:
  26. // |token_getter| must outlive |this|.
  27. FtlRegistrationManager(
  28. OAuthTokenGetter* token_getter,
  29. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
  30. std::unique_ptr<FtlDeviceIdProvider> device_id_provider);
  31. FtlRegistrationManager(const FtlRegistrationManager&) = delete;
  32. FtlRegistrationManager& operator=(const FtlRegistrationManager&) = delete;
  33. ~FtlRegistrationManager() override;
  34. // RegistrationManager implementations.
  35. void SignInGaia(DoneCallback on_done) override;
  36. void SignOut() override;
  37. bool IsSignedIn() const override;
  38. std::string GetRegistrationId() const override;
  39. std::string GetFtlAuthToken() const override;
  40. private:
  41. using SignInGaiaResponseCallback =
  42. base::OnceCallback<void(const ProtobufHttpStatus&,
  43. std::unique_ptr<ftl::SignInGaiaResponse>)>;
  44. friend class FtlRegistrationManagerTest;
  45. class RegistrationClient {
  46. public:
  47. virtual ~RegistrationClient() = default;
  48. virtual void SignInGaia(const ftl::SignInGaiaRequest& request,
  49. SignInGaiaResponseCallback on_done) = 0;
  50. virtual void CancelPendingRequests() = 0;
  51. };
  52. class RegistrationClientImpl;
  53. FtlRegistrationManager(
  54. std::unique_ptr<RegistrationClient> registration_client,
  55. std::unique_ptr<FtlDeviceIdProvider> device_id_provider);
  56. void DoSignInGaia(DoneCallback on_done);
  57. void OnSignInGaiaResponse(DoneCallback on_done,
  58. const ProtobufHttpStatus& status,
  59. std::unique_ptr<ftl::SignInGaiaResponse> response);
  60. std::unique_ptr<RegistrationClient> registration_client_;
  61. std::unique_ptr<FtlDeviceIdProvider> device_id_provider_;
  62. base::OneShotTimer sign_in_backoff_timer_;
  63. base::OneShotTimer sign_in_refresh_timer_;
  64. std::string registration_id_;
  65. std::string ftl_auth_token_;
  66. net::BackoffEntry sign_in_backoff_;
  67. };
  68. } // namespace remoting
  69. #endif // REMOTING_SIGNALING_FTL_REGISTRATION_MANAGER_H_