Refactor: Migrate all prefs to string_view

There should be no behavioral changes, just how the parameters are
taken.

What's wrong with std::string:
    1. Data is heap allocated. Most usecase of pref involves look up
    some value with a compile time constant string. For example,
    |prefs.GetKey(kPrefsManifestBytes)|. When this code is executed,
    what it's doing is create a std::instance with kPrefsManifestBytes,
    which is a const char *. The program must first determine the length
    of |kPrefsManifestBytes|, allocate sufficient heap memory to store
    it, then copy all contents over. After prefs.GetKey() is called, the
    allocated string must be deallocated. Everytime we call GetKey()
    with a const char *, we execute the same
    strlen()-allocate()-copy()-deallocate() sequence. Which is not
    efficient.
    2. Often requires passing by reference, which introduces 1 more
    pointer indirection

Why/How std::string_view fixes these problems
    1. std::string_view does not own the underlying data. When you do
    std::string_view{kPrefsManifestBytes}, it merely takes the pointer
    in, store it, then compute the size. No heap allocation happens.
    However, since std::string_view doesn't own the underlying data,
    lifetime of std::string_view cannot exceed that of const char *.
    This is fine for our usecase, because constants like
    kPrefsManifestBytes are static constants and are valid thorugh out
    the entire program execution
    2. Since std::string_view is virtuall a tuple<const char *data,
    size_t size>, no need to pass it by reference. It can be efficiently
    passed around by value, reducing pointer indirection.

Side note:
std::string_view is essentially the C++ equivalence of go/java-tips/012

Test: th
Change-Id: I4c3f1d88a0587e36ac5eca43d553448da1e2e878
diff --git a/common/fake_prefs.h b/common/fake_prefs.h
index 430c291..7ae9fb9 100644
--- a/common/fake_prefs.h
+++ b/common/fake_prefs.h
@@ -17,6 +17,7 @@
 #ifndef UPDATE_ENGINE_COMMON_FAKE_PREFS_H_
 #define UPDATE_ENGINE_COMMON_FAKE_PREFS_H_
 
+#include <functional>
 #include <map>
 #include <string>
 #include <string_view>
@@ -40,24 +41,23 @@
   ~FakePrefs();
 
   // PrefsInterface methods.
-  bool GetString(const std::string& key, std::string* value) const override;
-  bool SetString(const std::string& key, std::string_view 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) const override;
-  bool SetBoolean(const std::string& key, const bool value) override;
+  bool GetString(std::string_view key, std::string* value) const override;
+  bool SetString(std::string_view key, std::string_view value) override;
+  bool GetInt64(std::string_view key, int64_t* value) const override;
+  bool SetInt64(std::string_view key, const int64_t value) override;
+  bool GetBoolean(std::string_view key, bool* value) const override;
+  bool SetBoolean(std::string_view key, const bool value) override;
 
-  bool Exists(const std::string& key) const override;
-  bool Delete(const std::string& key) override;
-  bool Delete(const std::string& key,
+  bool Exists(std::string_view key) const override;
+  bool Delete(std::string_view key) override;
+  bool Delete(std::string_view key,
               const std::vector<std::string>& nss) override;
 
-  bool GetSubKeys(const std::string& ns,
+  bool GetSubKeys(std::string_view ns,
                   std::vector<std::string>* keys) const override;
 
-  void AddObserver(const std::string& key,
-                   ObserverInterface* observer) override;
-  void RemoveObserver(const std::string& key,
+  void AddObserver(std::string_view key, ObserverInterface* observer) override;
+  void RemoveObserver(std::string_view key,
                       ObserverInterface* observer) override;
 
  private:
@@ -92,24 +92,25 @@
   static std::string GetTypeName(PrefType type);
 
   // Checks that the |key| is either not present or has the given |type|.
-  void CheckKeyType(const std::string& key, PrefType type) const;
+  void CheckKeyType(std::string_view key, PrefType type) const;
 
   // Helper function to set a value of the passed |key|. It sets the type based
   // on the template parameter T.
   template <typename T>
-  void SetValue(const std::string& key, T value);
+  void SetValue(std::string_view key, T value);
 
   // Helper function to get a value from the map checking for invalid calls.
   // The function fails the test if you attempt to read a value  defined as a
   // different type. Returns whether the get succeeded.
   template <typename T>
-  bool GetValue(const std::string& key, T* value) const;
+  bool GetValue(std::string_view key, T* value) const;
 
   // Container for all the key/value pairs.
-  std::map<std::string, PrefTypeValue> values_;
+  std::map<std::string, PrefTypeValue, std::less<>> values_;
 
   // The registered observers watching for changes.
-  std::map<std::string, std::vector<ObserverInterface*>> observers_;
+  std::map<std::string, std::vector<ObserverInterface*>, std::less<>>
+      observers_;
 
   DISALLOW_COPY_AND_ASSIGN(FakePrefs);
 };