OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_COMMON_PERSISTENT_PREF_STORE_H_ | |
6 #define CHROME_COMMON_PERSISTENT_PREF_STORE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "chrome/common/pref_store.h" | |
11 | |
12 // This interface is complementary to the PrefStore interface, declaring | |
13 // additional functionality that adds support for setting values and persisting | |
14 // the data to some backing store. | |
15 class PersistentPrefStore : public PrefStore { | |
16 public: | |
17 // Unique integer code for each type of error so we can report them | |
18 // distinctly in a histogram. | |
19 // NOTE: Don't change the order here as it will change the server's meaning | |
20 // of the histogram. | |
21 enum PrefReadError { | |
22 PREF_READ_ERROR_NONE = 0, | |
23 PREF_READ_ERROR_JSON_PARSE, | |
24 PREF_READ_ERROR_JSON_TYPE, | |
25 PREF_READ_ERROR_ACCESS_DENIED, | |
26 PREF_READ_ERROR_FILE_OTHER, | |
27 PREF_READ_ERROR_FILE_LOCKED, | |
28 PREF_READ_ERROR_NO_FILE, | |
29 PREF_READ_ERROR_JSON_REPEAT, | |
30 PREF_READ_ERROR_OTHER, | |
31 PREF_READ_ERROR_FILE_NOT_SPECIFIED, | |
32 PREF_READ_ERROR_MAX_ENUM | |
33 }; | |
34 | |
35 class ReadErrorDelegate { | |
36 public: | |
37 virtual ~ReadErrorDelegate() {} | |
38 | |
39 virtual void OnError(PrefReadError error) = 0; | |
40 }; | |
41 | |
42 // Equivalent to PrefStore::GetValue but returns a mutable value. | |
43 virtual ReadResult GetMutableValue(const std::string& key, | |
44 base::Value** result) = 0; | |
45 | |
46 // Triggers a value changed notification. This function needs to be called | |
47 // if one retrieves a list or dictionary with GetMutableValue and change its | |
48 // value. SetValue takes care of notifications itself. Note that | |
49 // ReportValueChanged will trigger notifications even if nothing has changed. | |
50 virtual void ReportValueChanged(const std::string& key) = 0; | |
51 | |
52 // Sets a |value| for |key| in the store. Assumes ownership of |value|, which | |
53 // must be non-NULL. | |
54 virtual void SetValue(const std::string& key, base::Value* value) = 0; | |
55 | |
56 // Same as SetValue, but doesn't generate notifications. This is used by | |
57 // PrefService::GetMutableUserPref() in order to put empty entries | |
58 // into the user pref store. Using SetValue is not an option since existing | |
59 // tests rely on the number of notifications generated. | |
60 virtual void SetValueSilently(const std::string& key, base::Value* value) = 0; | |
61 | |
62 // Removes the value for |key|. | |
63 virtual void RemoveValue(const std::string& key) = 0; | |
64 | |
65 // Marks that the |key| with empty ListValue/DictionaryValue needs to be | |
66 // persisted. | |
67 virtual void MarkNeedsEmptyValue(const std::string& key) = 0; | |
68 | |
69 // Whether the store is in a pseudo-read-only mode where changes are not | |
70 // actually persisted to disk. This happens in some cases when there are | |
71 // read errors during startup. | |
72 virtual bool ReadOnly() const = 0; | |
73 | |
74 // Gets the read error. Only valid if IsInitializationComplete() returns true. | |
75 virtual PrefReadError GetReadError() const = 0; | |
76 | |
77 // Reads the preferences from disk. Notifies observers via | |
78 // "PrefStore::OnInitializationCompleted" when done. | |
79 virtual PrefReadError ReadPrefs() = 0; | |
80 | |
81 // Reads the preferences from disk asynchronously. Notifies observers via | |
82 // "PrefStore::OnInitializationCompleted" when done. Also it fires | |
83 // |error_delegate| if it is not NULL and reading error has occurred. | |
84 // Owns |error_delegate|. | |
85 virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) = 0; | |
86 | |
87 // Lands any pending writes to disk. | |
88 virtual void CommitPendingWrite() = 0; | |
89 | |
90 protected: | |
91 virtual ~PersistentPrefStore() {} | |
92 }; | |
93 | |
94 #endif // CHROME_COMMON_PERSISTENT_PREF_STORE_H_ | |
OLD | NEW |