diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 01:54:52 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 01:54:52 +0000 |
commit | 1d31be9d5238491a971fb2b5d9a70041f3997e5a (patch) | |
tree | 6ccbe9d5df4bc50fb5920d64a479631c823d0ca4 /remoting/host | |
parent | 71a3d2e01be15bc21f792a94cc1c5cd4d272127d (diff) | |
download | chromium_src-1d31be9d5238491a971fb2b5d9a70041f3997e5a.zip chromium_src-1d31be9d5238491a971fb2b5d9a70041f3997e5a.tar.gz chromium_src-1d31be9d5238491a971fb2b5d9a70041f3997e5a.tar.bz2 |
Removed dependency on chrome/common.
JSONReader and JSONWriter are used to read/write json file instead
of JsonPrefStore.
BUG=none
TEST=unittests
Review URL: http://codereview.chromium.org/2819026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50809 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/json_host_config.cc | 36 | ||||
-rw-r--r-- | remoting/host/json_host_config.h | 9 |
2 files changed, 32 insertions, 13 deletions
diff --git a/remoting/host/json_host_config.cc b/remoting/host/json_host_config.cc index ecb54b9..891ca78 100644 --- a/remoting/host/json_host_config.cc +++ b/remoting/host/json_host_config.cc @@ -4,35 +4,50 @@ #include "remoting/host/json_host_config.h" +#include "base/file_util.h" +#include "base/json/json_reader.h" +#include "base/json/json_writer.h" #include "base/message_loop_proxy.h" #include "base/task.h" #include "base/values.h" -#include "chrome/common/json_pref_store.h" -#include "chrome/common/pref_store.h" namespace remoting { JsonHostConfig::JsonHostConfig( const FilePath& filename, base::MessageLoopProxy* file_message_loop_proxy) - : pref_store_(new JsonPrefStore(filename, file_message_loop_proxy)), + : filename_(filename), message_loop_proxy_(file_message_loop_proxy) { } bool JsonHostConfig::Read() { - return pref_store_->ReadPrefs() == PrefStore::PREF_READ_ERROR_NONE; + // TODO(sergeyu): Implement better error handling here. + std::string file_content; + if (!file_util::ReadFileToString(filename_, &file_content)) { + return false; + } + + scoped_ptr<Value> value(base::JSONReader::Read(file_content, true)); + if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) { + return false; + } + + DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.release()); + AutoLock auto_lock(lock_); + values_.reset(dictionary); + return true; } bool JsonHostConfig::GetString(const std::wstring& path, std::wstring* out_value) { AutoLock auto_lock(lock_); - return pref_store_->prefs()->GetString(path, out_value); + return values_->GetString(path, out_value); } bool JsonHostConfig::GetString(const std::wstring& path, std::string* out_value) { AutoLock auto_lock(lock_); - return pref_store_->prefs()->GetString(path, out_value); + return values_->GetString(path, out_value); } void JsonHostConfig::Update(Task* task) { @@ -48,18 +63,21 @@ void JsonHostConfig::Update(Task* task) { void JsonHostConfig::SetString(const std::wstring& path, const std::wstring& in_value) { lock_.AssertAcquired(); - pref_store_->prefs()->SetString(path, in_value); + values_->SetString(path, in_value); } void JsonHostConfig::SetString(const std::wstring& path, const std::string& in_value) { lock_.AssertAcquired(); - pref_store_->prefs()->SetString(path, in_value); + values_->SetString(path, in_value); } void JsonHostConfig::DoWrite() { + std::string file_content; + base::JSONWriter::Write(values_.get(), true, &file_content); AutoLock auto_lock(lock_); - pref_store_->WritePrefs(); + // TODO(sergeyu): Move ImportantFileWriter to base and use it here. + file_util::WriteFile(filename_, file_content.c_str(), file_content.size()); } } // namespace remoting diff --git a/remoting/host/json_host_config.h b/remoting/host/json_host_config.h index ac10272..8d73e66 100644 --- a/remoting/host/json_host_config.h +++ b/remoting/host/json_host_config.h @@ -7,13 +7,13 @@ #include <string> +#include "base/file_path.h" #include "base/lock.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "remoting/host/host_config.h" -class FilePath; -class JsonPrefStore; +class DictionaryValue; class Task; namespace base { @@ -46,9 +46,10 @@ class JsonHostConfig : public MutableHostConfig { private: void DoWrite(); - // |lock_| must be locked whenever we access pref_store_; + // |lock_| must be locked whenever we access values_; Lock lock_; - scoped_ptr<JsonPrefStore> pref_store_; + FilePath filename_; + scoped_ptr<DictionaryValue> values_; scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; DISALLOW_COPY_AND_ASSIGN(JsonHostConfig); |