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 "base/macros.h" 16 #include "extensions/browser/value_store/value_store.h" 17 18 // Implementation Based on TestingValueStore 19 // ValueStore with an in-memory storage but the ability to 20 // optionally fail all operations. 21 class CefValueStore : public ValueStore { 22 public: 23 CefValueStore(); 24 ~CefValueStore() override; 25 26 // Accessors for the number of reads/writes done by this value store. Each 27 // Get* operation (except for the BytesInUse ones) counts as one read, and 28 // each Set*/Remove/Clear operation counts as one write. This is useful in 29 // tests seeking to assert that some number of reads/writes to their 30 // underlying value store have (or have not) happened. read_count()31 int read_count() const { return read_count_; } write_count()32 int write_count() const { return write_count_; } 33 34 // Sets the error code for requests. If OK, errors won't be thrown. 35 // Defaults to OK. 36 void set_status_code(StatusCode status_code); 37 38 // ValueStore implementation. 39 size_t GetBytesInUse(const std::string& key) override; 40 size_t GetBytesInUse(const std::vector<std::string>& keys) override; 41 size_t GetBytesInUse() override; 42 ReadResult Get(const std::string& key) override; 43 ReadResult Get(const std::vector<std::string>& keys) override; 44 ReadResult Get() override; 45 WriteResult Set(WriteOptions options, 46 const std::string& key, 47 const base::Value& value) override; 48 WriteResult Set(WriteOptions options, 49 const base::DictionaryValue& values) override; 50 WriteResult Remove(const std::string& key) override; 51 WriteResult Remove(const std::vector<std::string>& keys) override; 52 WriteResult Clear() override; 53 54 private: 55 base::DictionaryValue storage_; 56 int read_count_; 57 int write_count_; 58 ValueStore::Status status_; 59 60 DISALLOW_COPY_AND_ASSIGN(CefValueStore); 61 }; 62 63 #endif // CEF_LIBCEF_BROWSER_EXTENSIONS_VALUE_STORE_CEF_VALUE_STORE_H_ 64