| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) { | 31 if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) { |
| 32 return false; | 32 return false; |
| 33 } | 33 } |
| 34 | 34 |
| 35 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.release()); | 35 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.release()); |
| 36 AutoLock auto_lock(lock_); | 36 AutoLock auto_lock(lock_); |
| 37 values_.reset(dictionary); | 37 values_.reset(dictionary); |
| 38 return true; | 38 return true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool JsonHostConfig::GetString(const std::wstring& path, | 41 bool JsonHostConfig::GetString(const std::string& path, |
| 42 std::wstring* out_value) { | |
| 43 AutoLock auto_lock(lock_); | |
| 44 return values_->GetString(path, out_value); | |
| 45 } | |
| 46 | |
| 47 bool JsonHostConfig::GetString(const std::wstring& path, | |
| 48 std::string* out_value) { | 42 std::string* out_value) { |
| 49 AutoLock auto_lock(lock_); | 43 AutoLock auto_lock(lock_); |
| 50 return values_->GetString(path, out_value); | 44 return values_->GetString(path, out_value); |
| 51 } | 45 } |
| 52 | 46 |
| 53 void JsonHostConfig::Update(Task* task) { | 47 void JsonHostConfig::Update(Task* task) { |
| 54 { | 48 { |
| 55 AutoLock auto_lock(lock_); | 49 AutoLock auto_lock(lock_); |
| 56 task->Run(); | 50 task->Run(); |
| 57 } | 51 } |
| 58 delete task; | 52 delete task; |
| 59 message_loop_proxy_->PostTask( | 53 message_loop_proxy_->PostTask( |
| 60 FROM_HERE, NewRunnableMethod(this, &JsonHostConfig::DoWrite)); | 54 FROM_HERE, NewRunnableMethod(this, &JsonHostConfig::DoWrite)); |
| 61 } | 55 } |
| 62 | 56 |
| 63 void JsonHostConfig::SetString(const std::wstring& path, | 57 void JsonHostConfig::SetString(const std::string& path, |
| 64 const std::wstring& in_value) { | |
| 65 lock_.AssertAcquired(); | |
| 66 values_->SetString(path, in_value); | |
| 67 } | |
| 68 | |
| 69 void JsonHostConfig::SetString(const std::wstring& path, | |
| 70 const std::string& in_value) { | 58 const std::string& in_value) { |
| 71 lock_.AssertAcquired(); | 59 lock_.AssertAcquired(); |
| 72 values_->SetString(path, in_value); | 60 values_->SetString(path, in_value); |
| 73 } | 61 } |
| 74 | 62 |
| 75 void JsonHostConfig::DoWrite() { | 63 void JsonHostConfig::DoWrite() { |
| 76 std::string file_content; | 64 std::string file_content; |
| 77 base::JSONWriter::Write(values_.get(), true, &file_content); | 65 base::JSONWriter::Write(values_.get(), true, &file_content); |
| 78 AutoLock auto_lock(lock_); | 66 AutoLock auto_lock(lock_); |
| 79 // TODO(sergeyu): Move ImportantFileWriter to base and use it here. | 67 // TODO(sergeyu): Move ImportantFileWriter to base and use it here. |
| 80 file_util::WriteFile(filename_, file_content.c_str(), file_content.size()); | 68 file_util::WriteFile(filename_, file_content.c_str(), file_content.size()); |
| 81 } | 69 } |
| 82 | 70 |
| 83 } // namespace remoting | 71 } // namespace remoting |
| OLD | NEW |