summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remoting/host/json_host_config.cc36
-rw-r--r--remoting/host/json_host_config.h9
-rw-r--r--remoting/remoting.gyp1
3 files changed, 32 insertions, 14 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);
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 9a5e40c..8fdf56c 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -136,7 +136,6 @@
'target_name': 'chromoting_host',
'type': '<(library)',
'dependencies': [
- '../chrome/chrome.gyp:common',
'chromoting_base',
'chromoting_jingle_glue',
],