summaryrefslogtreecommitdiffstats
path: root/remoting/host/in_memory_host_config.cc
blob: 486b2019af1014f379f95647aa571b8007057b69 (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
61
62
63
64
65
66
// Copyright (c) 2012 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 "remoting/host/in_memory_host_config.h"

#include "base/logging.h"
#include "base/values.h"

namespace remoting {

InMemoryHostConfig::InMemoryHostConfig()
    : values_(new base::DictionaryValue()) {
}

InMemoryHostConfig::~InMemoryHostConfig() {}

bool InMemoryHostConfig::GetString(const std::string& path,
                                   std::string* out_value) const {
  DCHECK(CalledOnValidThread());
  return values_->GetString(path, out_value);
}

bool InMemoryHostConfig::GetBoolean(const std::string& path,
                                    bool* out_value) const {
  DCHECK(CalledOnValidThread());
  return values_->GetBoolean(path, out_value);
}

bool InMemoryHostConfig::Save() {
  // Saving in-memory host config is not supported.
  NOTREACHED();
  return false;
}

void InMemoryHostConfig::SetString(const std::string& path,
                                   const std::string& in_value) {
  DCHECK(CalledOnValidThread());
  values_->SetString(path, in_value);
}

void InMemoryHostConfig::SetBoolean(const std::string& path, bool in_value) {
  DCHECK(CalledOnValidThread());
  values_->SetBoolean(path, in_value);
}

bool InMemoryHostConfig::CopyFrom(const base::DictionaryValue* dictionary) {
  bool result = true;

  for (base::DictionaryValue::Iterator it(*dictionary); !it.IsAtEnd();
       it.Advance()) {
    std::string str_value;
    bool bool_value;
    if (it.value().GetAsString(&str_value)) {
      SetString(it.key(), str_value);
    } else if (it.value().GetAsBoolean(&bool_value)) {
      SetBoolean(it.key(), bool_value);
    } else {
      result = false;
    }
  }

  return result;
}

}  // namespace remoting