Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / base / prefs / persistent_pref_store.h
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 BASE_PREFS_PERSISTENT_PREF_STORE_H_
6 #define BASE_PREFS_PERSISTENT_PREF_STORE_H_
7
8 #include <string>
9
10 #include "base/prefs/base_prefs_export.h"
11 #include "base/prefs/writeable_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 BASE_PREFS_EXPORT PersistentPrefStore : public WriteablePrefStore {
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 explicit values of the enums as it will change the
21   // server's meaning of the histogram.
22   enum PrefReadError {
23     PREF_READ_ERROR_NONE = 0,
24     PREF_READ_ERROR_JSON_PARSE = 1,
25     PREF_READ_ERROR_JSON_TYPE = 2,
26     PREF_READ_ERROR_ACCESS_DENIED = 3,
27     PREF_READ_ERROR_FILE_OTHER = 4,
28     PREF_READ_ERROR_FILE_LOCKED = 5,
29     PREF_READ_ERROR_NO_FILE = 6,
30     PREF_READ_ERROR_JSON_REPEAT = 7,
31     // PREF_READ_ERROR_OTHER = 8,  // Deprecated.
32     PREF_READ_ERROR_FILE_NOT_SPECIFIED = 9,
33     // Indicates that ReadPrefs() couldn't complete synchronously and is waiting
34     // for an asynchronous task to complete first.
35     PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE = 10,
36     PREF_READ_ERROR_MAX_ENUM
37   };
38
39   class ReadErrorDelegate {
40    public:
41     virtual ~ReadErrorDelegate() {}
42
43     virtual void OnError(PrefReadError error) = 0;
44   };
45
46   // Equivalent to PrefStore::GetValue but returns a mutable value.
47   virtual bool GetMutableValue(const std::string& key,
48                                base::Value** result) = 0;
49
50   // Triggers a value changed notification. This function needs to be called
51   // if one retrieves a list or dictionary with GetMutableValue and change its
52   // value. SetValue takes care of notifications itself. Note that
53   // ReportValueChanged will trigger notifications even if nothing has changed.
54   virtual void ReportValueChanged(const std::string& key) = 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   // Whether the store is in a pseudo-read-only mode where changes are not
63   // actually persisted to disk.  This happens in some cases when there are
64   // read errors during startup.
65   virtual bool ReadOnly() const = 0;
66
67   // Gets the read error. Only valid if IsInitializationComplete() returns true.
68   virtual PrefReadError GetReadError() const = 0;
69
70   // Reads the preferences from disk. Notifies observers via
71   // "PrefStore::OnInitializationCompleted" when done.
72   virtual PrefReadError ReadPrefs() = 0;
73
74   // Reads the preferences from disk asynchronously. Notifies observers via
75   // "PrefStore::OnInitializationCompleted" when done. Also it fires
76   // |error_delegate| if it is not NULL and reading error has occurred.
77   // Owns |error_delegate|.
78   virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) = 0;
79
80   // Lands any pending writes to disk.
81   virtual void CommitPendingWrite() = 0;
82
83  protected:
84   virtual ~PersistentPrefStore() {}
85 };
86
87 #endif  // BASE_PREFS_PERSISTENT_PREF_STORE_H_