| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/json_host_config.h" | 5 #include "remoting/host/json_host_config.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 | 13 |
| 14 namespace remoting { | 14 namespace remoting { |
| 15 | 15 |
| 16 JsonHostConfig::JsonHostConfig( | 16 JsonHostConfig::JsonHostConfig( |
| 17 const FilePath& filename, | 17 const FilePath& filename, |
| 18 base::MessageLoopProxy* file_message_loop_proxy) | 18 base::MessageLoopProxy* file_message_loop_proxy) |
| 19 : filename_(filename), | 19 : filename_(filename), |
| 20 values_(new DictionaryValue()), | 20 values_(new DictionaryValue()), |
| 21 message_loop_proxy_(file_message_loop_proxy) { | 21 message_loop_proxy_(file_message_loop_proxy) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 JsonHostConfig::~JsonHostConfig() {} |
| 25 |
| 24 bool JsonHostConfig::Read() { | 26 bool JsonHostConfig::Read() { |
| 25 // TODO(sergeyu): Implement better error handling here. | 27 // TODO(sergeyu): Implement better error handling here. |
| 26 std::string file_content; | 28 std::string file_content; |
| 27 if (!file_util::ReadFileToString(filename_, &file_content)) { | 29 if (!file_util::ReadFileToString(filename_, &file_content)) { |
| 28 return false; | 30 return false; |
| 29 } | 31 } |
| 30 | 32 |
| 31 scoped_ptr<Value> value(base::JSONReader::Read(file_content, true)); | 33 scoped_ptr<Value> value(base::JSONReader::Read(file_content, true)); |
| 32 if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) { | 34 if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) { |
| 33 return false; | 35 return false; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 63 | 65 |
| 64 void JsonHostConfig::DoWrite() { | 66 void JsonHostConfig::DoWrite() { |
| 65 std::string file_content; | 67 std::string file_content; |
| 66 base::JSONWriter::Write(values_.get(), true, &file_content); | 68 base::JSONWriter::Write(values_.get(), true, &file_content); |
| 67 AutoLock auto_lock(lock_); | 69 AutoLock auto_lock(lock_); |
| 68 // TODO(sergeyu): Move ImportantFileWriter to base and use it here. | 70 // TODO(sergeyu): Move ImportantFileWriter to base and use it here. |
| 69 file_util::WriteFile(filename_, file_content.c_str(), file_content.size()); | 71 file_util::WriteFile(filename_, file_content.c_str(), file_content.size()); |
| 70 } | 72 } |
| 71 | 73 |
| 72 } // namespace remoting | 74 } // namespace remoting |
| OLD | NEW |