• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #pragma once
8 
9 #include <string>
10 
11 #include <chrome/common/pref_store.h>
12 
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 PersistentPrefStore : public PrefStore {
17  public:
~PersistentPrefStore()18   virtual ~PersistentPrefStore() {}
19 
20   // Unique integer code for each type of error so we can report them
21   // distinctly in a histogram.
22   // NOTE: Don't change the order here as it will change the server's meaning
23   // of the histogram.
24   enum PrefReadError {
25     PREF_READ_ERROR_NONE = 0,
26     PREF_READ_ERROR_JSON_PARSE,
27     PREF_READ_ERROR_JSON_TYPE,
28     PREF_READ_ERROR_ACCESS_DENIED,
29     PREF_READ_ERROR_FILE_OTHER,
30     PREF_READ_ERROR_FILE_LOCKED,
31     PREF_READ_ERROR_NO_FILE,
32     PREF_READ_ERROR_JSON_REPEAT,
33     PREF_READ_ERROR_OTHER,
34     PREF_READ_ERROR_FILE_NOT_SPECIFIED
35   };
36 
37   // Equivalent to PrefStore::GetValue but returns a mutable value.
38   virtual ReadResult GetMutableValue(const std::string& key,
39                                      Value** result) = 0;
40 
41   // Triggers a value changed notification. This function needs to be called
42   // if one retrieves a list or dictionary with GetMutableValue and change its
43   // value. SetValue takes care of notifications itself. Note that
44   // ReportValueChanged will trigger notifications even if nothing has changed.
45   virtual void ReportValueChanged(const std::string& key) = 0;
46 
47   // Sets a |value| for |key| in the store. Assumes ownership of |value|, which
48   // must be non-NULL.
49   virtual void SetValue(const std::string& key, Value* value) = 0;
50 
51   // Same as SetValue, but doesn't generate notifications. This is used by
52   // PrefService::GetMutableUserPref() in order to put empty entries
53   // into the user pref store. Using SetValue is not an option since existing
54   // tests rely on the number of notifications generated.
55   virtual void SetValueSilently(const std::string& key, Value* value) = 0;
56 
57   // Removes the value for |key|.
58   virtual void RemoveValue(const std::string& key) = 0;
59 
60   // Whether the store is in a pseudo-read-only mode where changes are not
61   // actually persisted to disk.  This happens in some cases when there are
62   // read errors during startup.
63   virtual bool ReadOnly() const = 0;
64 
65   // Reads the preferences from disk.
66   virtual PrefReadError ReadPrefs() = 0;
67 
68   // Writes the preferences to disk immediately.
69   virtual bool WritePrefs() = 0;
70 
71   // Schedules an asynchronous write operation.
72   virtual void ScheduleWritePrefs() = 0;
73 
74   // Lands any pending writes to disk.
75   virtual void CommitPendingWrite() = 0;
76 };
77 
78 #endif  // CHROME_COMMON_PERSISTENT_PREF_STORE_H_
79