summaryrefslogtreecommitdiffstats
path: root/chrome/service/service_process_prefs.cc
blob: 511709a7d8f5d5893f0f78d4a6c2b516bf62f24f (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2011 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.

#include "chrome/service/service_process_prefs.h"

#include "base/values.h"

ServiceProcessPrefs::ServiceProcessPrefs(
    const FilePath& pref_filename,
    base::MessageLoopProxy* file_message_loop_proxy)
    : prefs_(new JsonPrefStore(pref_filename, file_message_loop_proxy)) {
}

ServiceProcessPrefs::~ServiceProcessPrefs() {}

void ServiceProcessPrefs::ReadPrefs() {
  prefs_->ReadPrefs();
}

void ServiceProcessPrefs::WritePrefs() {
  prefs_->CommitPendingWrite();
}

void ServiceProcessPrefs::GetString(const std::string& key,
                                    std::string* result) {
  const Value* value;
  if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK)
    value->GetAsString(result);
}

void ServiceProcessPrefs::SetString(const std::string& key,
                                    const std::string& value) {
  prefs_->SetValue(key, Value::CreateStringValue(value));
}

void ServiceProcessPrefs::GetBoolean(const std::string& key, bool* result) {
  const Value* value;
  if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK)
    value->GetAsBoolean(result);
}

void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) {
  prefs_->SetValue(key, Value::CreateBooleanValue(value));
}

void ServiceProcessPrefs::GetDictionary(const std::string& key,
                                        const DictionaryValue** result) {
  const Value* value;
  if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK ||
      !value->IsType(Value::TYPE_DICTIONARY)) {
    return;
  }

  *result = static_cast<const DictionaryValue*>(value);
}

void ServiceProcessPrefs::RemovePref(const std::string& key) {
  prefs_->RemoveValue(key);
}