• 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_BROWSER_PREFS_OVERLAY_PERSISTENT_PREF_STORE_H_
6 #define CHROME_BROWSER_PREFS_OVERLAY_PERSISTENT_PREF_STORE_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/observer_list.h"
14 #include "chrome/browser/prefs/pref_value_map.h"
15 #include "chrome/common/persistent_pref_store.h"
16 
17 // PersistentPrefStore that directs all write operations into a in-memory
18 // PrefValueMap. Read operations are first answered by the PrefValueMap.
19 // If the PrefValueMap does not contain a value for the requested key,
20 // the look-up is passed on to an underlying PersistentPrefStore |underlay_|.
21 class OverlayPersistentPrefStore : public PersistentPrefStore,
22                                    public PrefStore::Observer {
23  public:
24   explicit OverlayPersistentPrefStore(PersistentPrefStore* underlay);
25   virtual ~OverlayPersistentPrefStore();
26 
27   // Returns true if a value has been set for the |key| in this
28   // OverlayPersistentPrefStore, i.e. if it potentially overrides a value
29   // from the |underlay_|.
30   virtual bool IsSetInOverlay(const std::string& key) const;
31 
32   // Methods of PrefStore.
33   virtual void AddObserver(PrefStore::Observer* observer);
34   virtual void RemoveObserver(PrefStore::Observer* observer);
35   virtual bool IsInitializationComplete() const;
36   virtual ReadResult GetValue(const std::string& key,
37                               const Value** result) const;
38 
39   // Methods of PersistentPrefStore.
40   virtual ReadResult GetMutableValue(const std::string& key, Value** result);
41   virtual void SetValue(const std::string& key, Value* value);
42   virtual void SetValueSilently(const std::string& key, Value* value);
43   virtual void RemoveValue(const std::string& key);
44   virtual bool ReadOnly() const;
45   virtual PrefReadError ReadPrefs();
46   virtual bool WritePrefs();
47   virtual void ScheduleWritePrefs();
48   virtual void CommitPendingWrite();
49   virtual void ReportValueChanged(const std::string& key);
50 
51  private:
52   // Methods of PrefStore::Observer.
53   virtual void OnPrefValueChanged(const std::string& key);
54   virtual void OnInitializationCompleted();
55 
56   ObserverList<PrefStore::Observer, true> observers_;
57   PrefValueMap overlay_;
58   scoped_refptr<PersistentPrefStore> underlay_;
59 
60   DISALLOW_COPY_AND_ASSIGN(OverlayPersistentPrefStore);
61 };
62 
63 #endif  // CHROME_BROWSER_PREFS_OVERLAY_PERSISTENT_PREF_STORE_H_
64