Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2766)

Unified Diff: remoting/host/json_host_config.cc

Issue 10007048: Cleanup and simplify HostConfig and JsonHostConfig. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/json_host_config.h ('k') | remoting/host/json_host_config_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/json_host_config.cc
diff --git a/remoting/host/json_host_config.cc b/remoting/host/json_host_config.cc
index 4e8580c27cebc17a67150aa800c759ecb8f78a32..66e518c202622706aebb888455641b44c5f67042 100644
--- a/remoting/host/json_host_config.cc
+++ b/remoting/host/json_host_config.cc
@@ -9,52 +9,49 @@
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/location.h"
-#include "base/message_loop_proxy.h"
-#include "base/synchronization/lock.h"
+#include "base/memory/scoped_ptr.h"
#include "base/values.h"
namespace remoting {
-JsonHostConfig::JsonHostConfig(
- const FilePath& filename,
- base::MessageLoopProxy* file_message_loop_proxy)
- : filename_(filename),
- message_loop_proxy_(file_message_loop_proxy) {
+JsonHostConfig::JsonHostConfig(const FilePath& filename)
+ : filename_(filename) {
}
JsonHostConfig::~JsonHostConfig() {}
bool JsonHostConfig::Read() {
+ DCHECK(CalledOnValidThread());
+
// TODO(sergeyu): Implement better error handling here.
std::string file_content;
if (!file_util::ReadFileToString(filename_, &file_content)) {
+ LOG(WARNING) << "Failed to read " << filename_.value();
return false;
}
scoped_ptr<Value> value(base::JSONReader::Read(file_content, true));
if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) {
+ LOG(WARNING) << "Failed to parse " << filename_.value();
return false;
}
DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.release());
- base::AutoLock auto_lock(lock_);
values_.reset(dictionary);
return true;
}
-void JsonHostConfig::Save() {
- message_loop_proxy_->PostTask(
- FROM_HERE, base::Bind(&JsonHostConfig::DoWrite, this));
-}
+bool JsonHostConfig::Save() {
+ DCHECK(CalledOnValidThread());
-void JsonHostConfig::DoWrite() {
std::string file_content;
- base::AutoLock auto_lock(lock_);
base::JSONWriter::WriteWithOptions(values_.get(),
base::JSONWriter::OPTIONS_PRETTY_PRINT,
&file_content);
// TODO(sergeyu): Move ImportantFileWriter to base and use it here.
- file_util::WriteFile(filename_, file_content.c_str(), file_content.size());
+ int result = file_util::WriteFile(filename_, file_content.c_str(),
+ file_content.size());
+ return result == static_cast<int>(file_content.size());
}
} // namespace remoting
« no previous file with comments | « remoting/host/json_host_config.h ('k') | remoting/host/json_host_config_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698