Home | History | Annotate | Download | only in host
      1 // Copyright (c) 2012 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 #include "remoting/host/in_memory_host_config.h"
      6 
      7 #include "base/logging.h"
      8 #include "base/values.h"
      9 
     10 namespace remoting {
     11 
     12 InMemoryHostConfig::InMemoryHostConfig()
     13     : values_(new base::DictionaryValue()) {
     14 }
     15 
     16 InMemoryHostConfig::~InMemoryHostConfig() {}
     17 
     18 bool InMemoryHostConfig::GetString(const std::string& path,
     19                                    std::string* out_value) const {
     20   DCHECK(CalledOnValidThread());
     21   return values_->GetString(path, out_value);
     22 }
     23 
     24 bool InMemoryHostConfig::GetBoolean(const std::string& path,
     25                                     bool* out_value) const {
     26   DCHECK(CalledOnValidThread());
     27   return values_->GetBoolean(path, out_value);
     28 }
     29 
     30 bool InMemoryHostConfig::Save() {
     31   // Saving in-memory host config is not supported.
     32   NOTREACHED();
     33   return false;
     34 }
     35 
     36 void InMemoryHostConfig::SetString(const std::string& path,
     37                                    const std::string& in_value) {
     38   DCHECK(CalledOnValidThread());
     39   values_->SetString(path, in_value);
     40 }
     41 
     42 void InMemoryHostConfig::SetBoolean(const std::string& path, bool in_value) {
     43   DCHECK(CalledOnValidThread());
     44   values_->SetBoolean(path, in_value);
     45 }
     46 
     47 bool InMemoryHostConfig::CopyFrom(const base::DictionaryValue* dictionary) {
     48   bool result = true;
     49 
     50   for (base::DictionaryValue::Iterator it(*dictionary); !it.IsAtEnd();
     51        it.Advance()) {
     52     std::string str_value;
     53     bool bool_value;
     54     if (it.value().GetAsString(&str_value)) {
     55       SetString(it.key(), str_value);
     56     } else if (it.value().GetAsBoolean(&bool_value)) {
     57       SetBoolean(it.key(), bool_value);
     58     } else {
     59       result = false;
     60     }
     61   }
     62 
     63   return result;
     64 }
     65 
     66 }  // namespace remoting
     67