[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 1 | // Copyright (c) 2010 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 | |
[email protected] | ea587b0 | 2010-05-21 15:01:35 | [diff] [blame] | 5 | #ifndef CHROME_COMMON_PREF_STORE_H_ |
| 6 | #define CHROME_COMMON_PREF_STORE_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 8 | |
| 9 | class DictionaryValue; |
| 10 | |
| 11 | // This is an abstract interface for reading and writing from/to a persistent |
| 12 | // preference store, used by |PrefService|. An implementation using a JSON file |
| 13 | // can be found in |JsonPrefStore|, while an implementation without any backing |
| 14 | // store (currently used for testing) can be found in |DummyPrefStore|. |
| 15 | class 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, |
[email protected] | c0858b0 | 2010-05-12 15:03:32 | [diff] [blame] | 30 | PREF_READ_ERROR_OTHER |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | virtual ~PrefStore() { } |
| 34 | |
| 35 | // Whether the store is in a pseudo-read-only mode where changes are not |
| 36 | // actually persisted to disk. This happens in some cases when there are |
| 37 | // read errors during startup. |
| 38 | virtual bool ReadOnly() { return true; } |
| 39 | |
[email protected] | c0858b0 | 2010-05-12 15:03:32 | [diff] [blame] | 40 | virtual DictionaryValue* prefs() = 0; |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 41 | |
| 42 | virtual PrefReadError ReadPrefs() = 0; |
| 43 | |
| 44 | virtual bool WritePrefs() { return true; } |
| 45 | |
| 46 | virtual void ScheduleWritePrefs() { } |
| 47 | }; |
| 48 | |
[email protected] | ea587b0 | 2010-05-21 15:01:35 | [diff] [blame] | 49 | #endif // CHROME_COMMON_PREF_STORE_H_ |
| 50 | |