update_manager: Make Prefs Variable async.

The update_engine prefs, while stored in disk, are private daemon
values changed by the daemon only. There was a 5 minutes delay between
changing this value and the update policy checking it again, and there
was a log spam every 5 minutes due to policy re-evaluations.

This patch makes these Prefs-based variables async by implementing an
observer pattern in the PrefsInterface and makes these variables async.

Bug: chromium:367333
Test: Added uniittest. No more log spam every 5 minutes.

Change-Id: I8b3f7072cc87515972c9f5b1ddcc54b865ffe238
diff --git a/fake_prefs.h b/fake_prefs.h
index fbc8c67..2777ad6 100644
--- a/fake_prefs.h
+++ b/fake_prefs.h
@@ -19,6 +19,7 @@
 
 #include <map>
 #include <string>
+#include <vector>
 
 #include <base/macros.h>
 
@@ -34,19 +35,25 @@
 
 class FakePrefs : public PrefsInterface {
  public:
-  FakePrefs() {}
+  FakePrefs() = default;
+  ~FakePrefs();
 
   // PrefsInterface methods.
-  bool GetString(const std::string& key, std::string* value) override;
+  bool GetString(const std::string& key, std::string* value) const override;
   bool SetString(const std::string& key, const std::string& value) override;
-  bool GetInt64(const std::string& key, int64_t* value) override;
+  bool GetInt64(const std::string& key, int64_t* value) const override;
   bool SetInt64(const std::string& key, const int64_t value) override;
-  bool GetBoolean(const std::string& key, bool* value) override;
+  bool GetBoolean(const std::string& key, bool* value) const override;
   bool SetBoolean(const std::string& key, const bool value) override;
 
-  bool Exists(const std::string& key) override;
+  bool Exists(const std::string& key) const override;
   bool Delete(const std::string& key) override;
 
+  void AddObserver(const std::string& key,
+                   ObserverInterface* observer) override;
+  void RemoveObserver(const std::string& key,
+                      ObserverInterface* observer) override;
+
  private:
   enum class PrefType {
     kString,
@@ -95,6 +102,9 @@
   // Container for all the key/value pairs.
   std::map<std::string, PrefTypeValue> values_;
 
+  // The registered observers watching for changes.
+  std::map<std::string, std::vector<ObserverInterface*>> observers_;
+
   DISALLOW_COPY_AND_ASSIGN(FakePrefs);
 };