Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: chrome/browser/value_store/testing_value_store.h

Issue 24021002: Propagate more information about ValueStore errors to callers, notably an (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add Pass*() Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_ 5 #ifndef CHROME_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_
6 #define CHROME_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_ 6 #define CHROME_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "chrome/browser/value_store/value_store.h" 9 #include "chrome/browser/value_store/value_store.h"
10 10
11 // ValueStore for testing, with an in-memory storage but the ability to 11 // ValueStore for testing, with an in-memory storage but the ability to
12 // optionally fail all operations. 12 // optionally fail all operations.
13 class TestingValueStore : public ValueStore { 13 class TestingValueStore : public ValueStore {
14 public: 14 public:
15 TestingValueStore(); 15 TestingValueStore();
16 virtual ~TestingValueStore(); 16 virtual ~TestingValueStore();
17 17
18 // Sets whether to fail all requests (default is false). 18 // Sets the error code for requests. If OK, errors won't be thrown.
19 void SetFailAllRequests(bool fail_all_requests); 19 // Defaults to OK.
20 void set_error_code(ErrorCode error_code) { error_code_ = error_code; }
20 21
21 // Accessors for the number of reads/writes done by this value store. Each 22 // Accessors for the number of reads/writes done by this value store. Each
22 // Get* operation (except for the BytesInUse ones) counts as one read, and 23 // Get* operation (except for the BytesInUse ones) counts as one read, and
23 // each Set*/Remove/Clear operation counts as one write. This is useful in 24 // each Set*/Remove/Clear operation counts as one write. This is useful in
24 // tests seeking to assert that some number of reads/writes to their 25 // tests seeking to assert that some number of reads/writes to their
25 // underlying value store have (or have not) happened. 26 // underlying value store have (or have not) happened.
26 int read_count() { return read_count_; } 27 int read_count() { return read_count_; }
27 int write_count() { return write_count_; } 28 int write_count() { return write_count_; }
28 29
29 // ValueStore implementation. 30 // ValueStore implementation.
30 virtual size_t GetBytesInUse(const std::string& key) OVERRIDE; 31 virtual size_t GetBytesInUse(const std::string& key) OVERRIDE;
31 virtual size_t GetBytesInUse(const std::vector<std::string>& keys) OVERRIDE; 32 virtual size_t GetBytesInUse(const std::vector<std::string>& keys) OVERRIDE;
32 virtual size_t GetBytesInUse() OVERRIDE; 33 virtual size_t GetBytesInUse() OVERRIDE;
33 virtual ReadResult Get(const std::string& key) OVERRIDE; 34 virtual ReadResult Get(const std::string& key) OVERRIDE;
34 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE; 35 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
35 virtual ReadResult Get() OVERRIDE; 36 virtual ReadResult Get() OVERRIDE;
36 virtual WriteResult Set( 37 virtual WriteResult Set(
37 WriteOptions options, 38 WriteOptions options,
38 const std::string& key, 39 const std::string& key,
39 const Value& value) OVERRIDE; 40 const Value& value) OVERRIDE;
40 virtual WriteResult Set( 41 virtual WriteResult Set(
41 WriteOptions options, const DictionaryValue& values) OVERRIDE; 42 WriteOptions options, const DictionaryValue& values) OVERRIDE;
42 virtual WriteResult Remove(const std::string& key) OVERRIDE; 43 virtual WriteResult Remove(const std::string& key) OVERRIDE;
43 virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE; 44 virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
44 virtual WriteResult Clear() OVERRIDE; 45 virtual WriteResult Clear() OVERRIDE;
45 46
46 private: 47 private:
48 scoped_ptr<ValueStore::Error> TestingError();
49
47 DictionaryValue storage_; 50 DictionaryValue storage_;
48 int read_count_; 51 int read_count_;
49 int write_count_; 52 int write_count_;
50 bool fail_all_requests_; 53 ErrorCode error_code_;
51 54
52 DISALLOW_COPY_AND_ASSIGN(TestingValueStore); 55 DISALLOW_COPY_AND_ASSIGN(TestingValueStore);
53 }; 56 };
54 57
55 #endif // CHROME_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_ 58 #endif // CHROME_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/value_store/leveldb_value_store.cc ('k') | chrome/browser/value_store/testing_value_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698