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

Side by Side Diff: base/prefs/testing_pref_store.h

Issue 1648403002: Move base/prefs to components/prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « base/prefs/testing_pref_service.cc ('k') | base/prefs/testing_pref_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 BASE_PREFS_TESTING_PREF_STORE_H_ 5 // TODO(brettw) remove this forwarding header when prefs is completely moved to
6 #define BASE_PREFS_TESTING_PREF_STORE_H_ 6 // components.
7 7 #include "components/prefs/testing_pref_store.h"
8 #include <stdint.h>
9
10 #include <string>
11
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "base/observer_list.h"
15 #include "base/prefs/persistent_pref_store.h"
16 #include "base/prefs/pref_value_map.h"
17
18 // |TestingPrefStore| is a preference store implementation that allows tests to
19 // explicitly manipulate the contents of the store, triggering notifications
20 // where appropriate.
21 class TestingPrefStore : public PersistentPrefStore {
22 public:
23 TestingPrefStore();
24
25 // Overriden from PrefStore.
26 bool GetValue(const std::string& key,
27 const base::Value** result) const override;
28 void AddObserver(PrefStore::Observer* observer) override;
29 void RemoveObserver(PrefStore::Observer* observer) override;
30 bool HasObservers() const override;
31 bool IsInitializationComplete() const override;
32
33 // PersistentPrefStore overrides:
34 bool GetMutableValue(const std::string& key, base::Value** result) override;
35 void ReportValueChanged(const std::string& key, uint32_t flags) override;
36 void SetValue(const std::string& key,
37 scoped_ptr<base::Value> value,
38 uint32_t flags) override;
39 void SetValueSilently(const std::string& key,
40 scoped_ptr<base::Value> value,
41 uint32_t flags) override;
42 void RemoveValue(const std::string& key, uint32_t flags) override;
43 bool ReadOnly() const override;
44 PrefReadError GetReadError() const override;
45 PersistentPrefStore::PrefReadError ReadPrefs() override;
46 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override;
47 void CommitPendingWrite() override;
48 void SchedulePendingLossyWrites() override;
49
50 // Marks the store as having completed initialization.
51 void SetInitializationCompleted();
52
53 // Used for tests to trigger notifications explicitly.
54 void NotifyPrefValueChanged(const std::string& key);
55 void NotifyInitializationCompleted();
56
57 // Some convenience getters/setters.
58 void SetString(const std::string& key, const std::string& value);
59 void SetInteger(const std::string& key, int value);
60 void SetBoolean(const std::string& key, bool value);
61
62 bool GetString(const std::string& key, std::string* value) const;
63 bool GetInteger(const std::string& key, int* value) const;
64 bool GetBoolean(const std::string& key, bool* value) const;
65
66 // Determines whether ReadPrefsAsync completes immediately. Defaults to false
67 // (non-blocking). To block, invoke this with true (blocking) before the call
68 // to ReadPrefsAsync. To unblock, invoke again with false (non-blocking) after
69 // the call to ReadPrefsAsync.
70 void SetBlockAsyncRead(bool block_async_read);
71
72 // Getter and Setter methods for setting and getting the state of the
73 // |TestingPrefStore|.
74 virtual void set_read_only(bool read_only);
75 void set_read_success(bool read_success);
76 void set_read_error(PersistentPrefStore::PrefReadError read_error);
77 bool committed() { return committed_; }
78
79 protected:
80 ~TestingPrefStore() override;
81
82 private:
83 // Stores the preference values.
84 PrefValueMap prefs_;
85
86 // Flag that indicates if the PrefStore is read-only
87 bool read_only_;
88
89 // The result to pass to PrefStore::Observer::OnInitializationCompleted
90 bool read_success_;
91
92 // The result to return from ReadPrefs or ReadPrefsAsync.
93 PersistentPrefStore::PrefReadError read_error_;
94
95 // Whether a call to ReadPrefsAsync should block.
96 bool block_async_read_;
97
98 // Whether there is a pending call to ReadPrefsAsync.
99 bool pending_async_read_;
100
101 // Whether initialization has been completed.
102 bool init_complete_;
103
104 // Whether the store contents have been committed to disk since the last
105 // mutation.
106 bool committed_;
107
108 scoped_ptr<ReadErrorDelegate> error_delegate_;
109 base::ObserverList<PrefStore::Observer, true> observers_;
110
111 DISALLOW_COPY_AND_ASSIGN(TestingPrefStore);
112 };
113
114 #endif // BASE_PREFS_TESTING_PREF_STORE_H_
OLDNEW
« no previous file with comments | « base/prefs/testing_pref_service.cc ('k') | base/prefs/testing_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698