value_map_pref_store.h revision ddb351dbec246cf1fab5ec20d2d5520909041de1
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_VALUE_MAP_PREF_STORE_H_
6#define CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_
7#pragma once
8
9#include "base/basictypes.h"
10#include "base/observer_list.h"
11#include "chrome/browser/prefs/pref_value_map.h"
12#include "chrome/common/pref_store.h"
13
14// A basic PrefStore implementation that uses a simple name-value map for
15// storing the preference values.
16class ValueMapPrefStore : public PrefStore {
17 public:
18  typedef std::map<std::string, Value*>::iterator iterator;
19  typedef std::map<std::string, Value*>::const_iterator const_iterator;
20
21  ValueMapPrefStore();
22  virtual ~ValueMapPrefStore();
23
24  // PrefStore overrides:
25  virtual ReadResult GetValue(const std::string& key,
26                              const Value** value) const;
27  virtual void AddObserver(PrefStore::Observer* observer);
28  virtual void RemoveObserver(PrefStore::Observer* observer);
29
30  iterator begin();
31  iterator end();
32  const_iterator begin() const;
33  const_iterator end() const;
34
35 protected:
36  // Store a |value| for |key| in the store. Also generates an notification if
37  // the value changed. Assumes ownership of |value|, which must be non-NULL.
38  void SetValue(const std::string& key, Value* value);
39
40  // Remove the value for |key| from the store. Sends a notification if there
41  // was a value to be removed.
42  void RemoveValue(const std::string& key);
43
44  // Notify observers about the initialization completed event.
45  void NotifyInitializationCompleted();
46
47 private:
48  PrefValueMap prefs_;
49
50  ObserverList<PrefStore::Observer, true> observers_;
51
52  DISALLOW_COPY_AND_ASSIGN(ValueMapPrefStore);
53};
54
55#endif  // CHROME_BROWSER_PREFS_VALUE_MAP_PREF_STORE_H_
56