remote_suggestions_status_service.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2016 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 COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_STATUS_SERVICE_H_
  5. #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_STATUS_SERVICE_H_
  6. #include "base/callback.h"
  7. #include "base/scoped_observation.h"
  8. #include "components/prefs/pref_change_registrar.h"
  9. namespace ntp_snippets {
  10. enum class RemoteSuggestionsStatus : int {
  11. // Suggestions are enabled and the user is signed in.
  12. ENABLED_AND_SIGNED_IN,
  13. // Suggestions are enabled; the user is signed out (sign-in is not required).
  14. ENABLED_AND_SIGNED_OUT,
  15. // Suggestions have been disabled as part of the service configuration.
  16. EXPLICITLY_DISABLED,
  17. };
  18. // Aggregates data from preferences and signin to notify the provider of
  19. // relevant changes in their states.
  20. class RemoteSuggestionsStatusService {
  21. public:
  22. using StatusChangeCallback =
  23. base::RepeatingCallback<void(RemoteSuggestionsStatus old_status,
  24. RemoteSuggestionsStatus new_status)>;
  25. virtual ~RemoteSuggestionsStatusService() = default;
  26. // Starts listening for changes from the dependencies. |callback| will be
  27. // called when a significant change in state is detected.
  28. virtual void Init(const StatusChangeCallback& callback) = 0;
  29. // To be called when the signin state changed. Will compute the new
  30. // state considering the initialisation configuration and the preferences,
  31. // and notify via the registered callback if appropriate.
  32. virtual void OnSignInStateChanged(bool has_signed_in) = 0;
  33. };
  34. } // namespace ntp_snippets
  35. #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_STATUS_SERVICE_H_