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