summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prefs/pref_value_map.h
blob: 26b621452a72fe9aa039e67456afd0a1b64be9e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PREFS_PREF_VALUE_MAP_H_
#define CHROME_BROWSER_PREFS_PREF_VALUE_MAP_H_
#pragma once

#include <map>
#include <string>

#include "base/basictypes.h"

class Value;

// A generic string to value map used by the PrefStore implementations.
class PrefValueMap {
 public:
  PrefValueMap() {}
  virtual ~PrefValueMap();

  // Gets the value for |key| and stores it in |value|. Ownership remains with
  // the map. Returns true if a value is present. If not, |value| is not
  // touched.
  bool GetValue(const std::string& key, Value** value) const;

  // Sets a new |value| for |key|. Takes ownership of |value|, which must be
  // non-NULL. Returns true if the value changed.
  bool SetValue(const std::string& key, Value* value);

  // Removes the value for |key| from the map. Returns true if a value was
  // removed.
  bool RemoveValue(const std::string& key);

  // Clears the map.
  void Clear();

 private:
  typedef std::map<std::string, Value*> Map;

  Map prefs_;

  DISALLOW_COPY_AND_ASSIGN(PrefValueMap);
};

#endif  // CHROME_BROWSER_PREFS_PREF_VALUE_MAP_H_