cros_settings_provider.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2013 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 ASH_COMPONENTS_SETTINGS_CROS_SETTINGS_PROVIDER_H_
  5. #define ASH_COMPONENTS_SETTINGS_CROS_SETTINGS_PROVIDER_H_
  6. #include <string>
  7. #include "base/callback.h"
  8. #include "base/component_export.h"
  9. namespace base {
  10. class Value;
  11. } // namespace base
  12. namespace ash {
  13. class COMPONENT_EXPORT(ASH_SETTINGS) CrosSettingsProvider {
  14. public:
  15. // The callback type that is called to notify the CrosSettings observers
  16. // about a setting change.
  17. using NotifyObserversCallback =
  18. base::RepeatingCallback<void(const std::string&)>;
  19. // Possible results of a trusted check.
  20. enum TrustedStatus {
  21. // The trusted values were populated in the cache and can be accessed
  22. // until the next iteration of the message loop.
  23. TRUSTED,
  24. // Either a store or a load operation is in progress. The provided
  25. // callback will be invoked once the verification has finished.
  26. TEMPORARILY_UNTRUSTED,
  27. // The verification of the trusted store has failed permanently. The
  28. // client should assume this state final and further checks for
  29. // trustedness will fail at least until the browser restarts.
  30. PERMANENTLY_UNTRUSTED,
  31. };
  32. // Creates a new provider instance. |notify_cb| will be used to notify
  33. // about setting changes.
  34. explicit CrosSettingsProvider(const NotifyObserversCallback& notify_cb);
  35. virtual ~CrosSettingsProvider();
  36. // Gets settings value of given |path| to |out_value|.
  37. virtual const base::Value* Get(const std::string& path) const = 0;
  38. // Requests the provider to fetch its values from a trusted store, if it
  39. // hasn't done so yet. Returns TRUSTED if the values returned by this provider
  40. // are trusted during the current loop cycle. Otherwise returns
  41. // TEMPORARILY_UNTRUSTED, takes ownership of |callback|, and will invoke it
  42. // later when trusted values become available. PrepareTrustedValues() should
  43. // be tried again in that case. Returns PERMANENTLY_UNTRUSTED if a permanent
  44. // error has occurred.
  45. virtual TrustedStatus PrepareTrustedValues(base::OnceClosure* callback) = 0;
  46. // Gets the namespace prefix provided by this provider.
  47. virtual bool HandlesSetting(const std::string& path) const = 0;
  48. void SetNotifyObserversCallback(const NotifyObserversCallback& notify_cb);
  49. protected:
  50. // Notifies the observers about a setting change.
  51. void NotifyObservers(const std::string& path);
  52. private:
  53. // Callback used to notify about setting changes.
  54. NotifyObserversCallback notify_cb_;
  55. };
  56. } // namespace ash
  57. // TODO(https://crbug.com/1164001): remove when the migration is finished.
  58. namespace chromeos {
  59. using ::ash::CrosSettingsProvider;
  60. } // namespace chromeos
  61. #endif // ASH_COMPONENTS_SETTINGS_CROS_SETTINGS_PROVIDER_H_