| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/host_config.h" | 5 #include "remoting/host/host_config.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/files/important_file_writer.h" | 8 #include "base/files/important_file_writer.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 return nullptr; | 21 return nullptr; |
| 22 } | 22 } |
| 23 | 23 |
| 24 scoped_ptr<base::DictionaryValue> config( | 24 scoped_ptr<base::DictionaryValue> config( |
| 25 static_cast<base::DictionaryValue*>(value.release())); | 25 static_cast<base::DictionaryValue*>(value.release())); |
| 26 return config.Pass(); | 26 return config.Pass(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 std::string HostConfigToJson(const base::DictionaryValue& host_config) { | 29 std::string HostConfigToJson(const base::DictionaryValue& host_config) { |
| 30 std::string data; | 30 std::string data; |
| 31 base::JSONWriter::Write(&host_config, &data); | 31 base::JSONWriter::Write(host_config, &data); |
| 32 return data; | 32 return data; |
| 33 } | 33 } |
| 34 | 34 |
| 35 scoped_ptr<base::DictionaryValue> HostConfigFromJsonFile( | 35 scoped_ptr<base::DictionaryValue> HostConfigFromJsonFile( |
| 36 const base::FilePath& config_file) { | 36 const base::FilePath& config_file) { |
| 37 // TODO(sergeyu): Implement better error handling here. | 37 // TODO(sergeyu): Implement better error handling here. |
| 38 std::string serialized; | 38 std::string serialized; |
| 39 if (!base::ReadFileToString(config_file, &serialized)) { | 39 if (!base::ReadFileToString(config_file, &serialized)) { |
| 40 LOG(WARNING) << "Failed to read " << config_file.value(); | 40 LOG(WARNING) << "Failed to read " << config_file.value(); |
| 41 return nullptr; | 41 return nullptr; |
| 42 } | 42 } |
| 43 | 43 |
| 44 return HostConfigFromJson(serialized); | 44 return HostConfigFromJson(serialized); |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool HostConfigToJsonFile(const base::DictionaryValue& host_config, | 47 bool HostConfigToJsonFile(const base::DictionaryValue& host_config, |
| 48 const base::FilePath& config_file) { | 48 const base::FilePath& config_file) { |
| 49 std::string serialized = HostConfigToJson(host_config); | 49 std::string serialized = HostConfigToJson(host_config); |
| 50 return base::ImportantFileWriter::WriteFileAtomically(config_file, | 50 return base::ImportantFileWriter::WriteFileAtomically(config_file, |
| 51 serialized); | 51 serialized); |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace remoting | 54 } // namespace remoting |
| OLD | NEW |