1 // Copyright 2017 The Chromium Embedded Framework Authors. 2 // Portions copyright 2016 The Chromium Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 6 #ifndef CEF_LIBCEF_BROWSER_EXTENSIONS_VALUE_STORE_CEF_VALUE_STORE_H_ 7 #define CEF_LIBCEF_BROWSER_EXTENSIONS_VALUE_STORE_CEF_VALUE_STORE_H_ 8 9 #include <stddef.h> 10 11 #include <string> 12 #include <vector> 13 14 #include "base/compiler_specific.h" 15 #include "components/value_store/value_store.h" 16 17 namespace value_store { 18 19 // Implementation Based on TestingValueStore. 20 // ValueStore with an in-memory storage but the ability to optionally fail all 21 // operations. 22 class CefValueStore : public ValueStore { 23 public: 24 CefValueStore(); 25 ~CefValueStore() override; 26 CefValueStore(const CefValueStore&) = delete; 27 CefValueStore& operator=(const CefValueStore&) = delete; 28 29 // Sets the error code for requests. If OK, errors won't be thrown. 30 // Defaults to OK. 31 void set_status_code(StatusCode status_code); 32 33 // Accessors for the number of reads/writes done by this value store. Each 34 // Get* operation (except for the BytesInUse ones) counts as one read, and 35 // each Set*/Remove/Clear operation counts as one write. This is useful in 36 // tests seeking to assert that some number of reads/writes to their 37 // underlying value store have (or have not) happened. read_count()38 int read_count() { return read_count_; } write_count()39 int write_count() { return write_count_; } 40 41 // ValueStore implementation. 42 size_t GetBytesInUse(const std::string& key) override; 43 size_t GetBytesInUse(const std::vector<std::string>& keys) override; 44 size_t GetBytesInUse() override; 45 ReadResult Get(const std::string& key) override; 46 ReadResult Get(const std::vector<std::string>& keys) override; 47 ReadResult Get() override; 48 WriteResult Set(WriteOptions options, 49 const std::string& key, 50 const base::Value& value) override; 51 WriteResult Set(WriteOptions options, 52 const base::DictionaryValue& values) override; 53 WriteResult Remove(const std::string& key) override; 54 WriteResult Remove(const std::vector<std::string>& keys) override; 55 WriteResult Clear() override; 56 57 private: 58 base::DictionaryValue storage_; 59 int read_count_ = 0; 60 int write_count_ = 0; 61 ValueStore::Status status_; 62 }; 63 64 } // namespace value_store 65 66 #endif // CEF_LIBCEF_BROWSER_EXTENSIONS_VALUE_STORE_CEF_VALUE_STORE_H_ 67