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