Stop using legacy GrContext member function aliases.
[chromium-blink-merge.git] / remoting / host / json_host_config.cc
blob58ea2aeaae1f3596aa81bf5d5205f865f85f2995
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.
5 #include "remoting/host/json_host_config.h"
7 #include "base/bind.h"
8 #include "base/files/file_util.h"
9 #include "base/files/important_file_writer.h"
10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h"
12 #include "base/location.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h"
16 namespace remoting {
18 JsonHostConfig::JsonHostConfig(const base::FilePath& filename)
19 : filename_(filename) {
22 JsonHostConfig::~JsonHostConfig() {}
24 bool JsonHostConfig::Read() {
25 DCHECK(CalledOnValidThread());
27 // TODO(sergeyu): Implement better error handling here.
28 std::string file_content;
29 if (!base::ReadFileToString(filename_, &file_content)) {
30 LOG(WARNING) << "Failed to read " << filename_.value();
31 return false;
34 return SetSerializedData(file_content);
37 bool JsonHostConfig::Save() {
38 DCHECK(CalledOnValidThread());
40 return base::ImportantFileWriter::WriteFileAtomically(filename_,
41 GetSerializedData());
44 std::string JsonHostConfig::GetSerializedData() {
45 std::string data;
46 base::JSONWriter::Write(values_.get(), &data);
47 return data;
50 bool JsonHostConfig::SetSerializedData(const std::string& config) {
51 scoped_ptr<base::Value> value(
52 base::JSONReader::Read(config, base::JSON_ALLOW_TRAILING_COMMAS));
53 if (value.get() == NULL || !value->IsType(base::Value::TYPE_DICTIONARY)) {
54 LOG(WARNING) << "Failed to parse " << filename_.value();
55 return false;
58 base::DictionaryValue* dictionary =
59 static_cast<base::DictionaryValue*>(value.release());
60 values_.reset(dictionary);
61 return true;
64 } // namespace remoting