buffet: Extract StorageInterface and implementations into separate files

This will make it easy to reuse file storage and memory storage
implementations in the forthcoming state aggregator.

BUG=chromium:369322
TEST=Unittests

Change-Id: Ie0dc0dbbfcc13e038352ecf77e2ad28bd41907d9
Reviewed-on: https://chromium-review.googlesource.com/198045
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/storage_impls.h b/buffet/storage_impls.h
new file mode 100644
index 0000000..04d5f0f
--- /dev/null
+++ b/buffet/storage_impls.h
@@ -0,0 +1,47 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BUFFET_STORAGE_IMPLS_H_
+#define BUFFET_STORAGE_IMPLS_H_
+
+#include <base/basictypes.h>
+#include <base/file_util.h>
+#include <base/values.h>
+
+#include "buffet/storage_interface.h"
+
+namespace buffet {
+
+// Persists the given Value to an atomically written file.
+class FileStorage : public StorageInterface {
+ public:
+  FileStorage(const base::FilePath& file_path);
+  virtual ~FileStorage() = default;
+  virtual std::unique_ptr<base::Value> Load() override;
+  virtual bool Save(const base::Value* config) override;
+
+ private:
+  base::FilePath file_path_;
+  DISALLOW_COPY_AND_ASSIGN(FileStorage);
+};
+
+// StorageInterface for testing. Just stores the values in memory.
+class MemStorage : public StorageInterface {
+ public:
+  MemStorage() = default;
+  virtual ~MemStorage() = default;
+  virtual std::unique_ptr<base::Value> Load() override;
+  virtual bool Save(const base::Value* config) override;
+  int save_count() { return save_count_; }
+  void reset_save_count() { save_count_ = 0; }
+
+ private:
+  int save_count_ = 0;
+  std::unique_ptr<base::Value> cache_;
+  DISALLOW_COPY_AND_ASSIGN(MemStorage);
+};
+
+}  // namespace buffet
+
+#endif  // BUFFET_STORAGE_IMPLS_H_