remote_suggestions_status_service_impl.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2017 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_IMPL_H_
  5. #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_STATUS_SERVICE_IMPL_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/callback.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/scoped_observation.h"
  11. #include "components/ntp_snippets/remote/remote_suggestions_status_service.h"
  12. #include "components/prefs/pref_change_registrar.h"
  13. class PrefService;
  14. namespace ntp_snippets {
  15. class RemoteSuggestionsStatusServiceImpl
  16. : public RemoteSuggestionsStatusService {
  17. public:
  18. RemoteSuggestionsStatusServiceImpl(
  19. bool is_signed_in,
  20. PrefService* pref_service,
  21. const std::vector<std::string>& additional_toggle_prefs);
  22. RemoteSuggestionsStatusServiceImpl(
  23. const RemoteSuggestionsStatusServiceImpl&) = delete;
  24. RemoteSuggestionsStatusServiceImpl& operator=(
  25. const RemoteSuggestionsStatusServiceImpl&) = delete;
  26. ~RemoteSuggestionsStatusServiceImpl() override;
  27. // RemoteSuggestionsStatusService implementation.
  28. void Init(const StatusChangeCallback& callback) override;
  29. void OnSignInStateChanged(bool has_signed_in) override;
  30. private:
  31. // Callbacks for the PrefChangeRegistrar.
  32. void OnSnippetsEnabledChanged();
  33. void OnListVisibilityChanged();
  34. void OnStateChanged(RemoteSuggestionsStatus new_status);
  35. bool IsSignedIn() const;
  36. // Returns whether the service is explicitly disabled, by the user or by a
  37. // policy for example.
  38. bool IsExplicitlyDisabled() const;
  39. RemoteSuggestionsStatus GetStatusFromDeps() const;
  40. RemoteSuggestionsStatus status_;
  41. StatusChangeCallback status_change_callback_;
  42. // Name of preferences to be used as additional toggles to guard the remote
  43. // suggestions provider.
  44. std::vector<std::string> additional_toggle_prefs_;
  45. bool is_signed_in_;
  46. // Whether the list of remote suggestions was ever visible during the session.
  47. // In case it was visible and then gets hidden, the service will only be
  48. // disabled on the next startup of browser, provided that the list is still
  49. // hidden then.
  50. bool list_visible_during_session_;
  51. raw_ptr<PrefService> pref_service_;
  52. PrefChangeRegistrar pref_change_registrar_;
  53. };
  54. } // namespace ntp_snippets
  55. #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_STATUS_SERVICE_IMPL_H_