summaryrefslogtreecommitdiffstats
path: root/remoting/host
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-16 21:19:03 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-16 21:19:03 +0000
commit8b67f635a2dee8788e98469d7b93d790bb7866b2 (patch)
tree1e35187f9358a9639c17150c54c24a42b20db94f /remoting/host
parentd2b5ad4cffed253421b3fdaf32e800d4ad72454b (diff)
downloadchromium_src-8b67f635a2dee8788e98469d7b93d790bb7866b2.zip
chromium_src-8b67f635a2dee8788e98469d7b93d790bb7866b2.tar.gz
chromium_src-8b67f635a2dee8788e98469d7b93d790bb7866b2.tar.bz2
Fix DaemonControllerLinux::SetConfigAndStart() to reload config automatically.
Also fixed several issues with managing chromoting from the webapp. Now it is possible to start the app and change PIN. BUG=120950 Review URL: https://chromiumcodereview.appspot.com/10824286 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151969 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r--remoting/host/host_config.h9
-rw-r--r--remoting/host/in_memory_host_config.cc19
-rw-r--r--remoting/host/in_memory_host_config.h2
-rw-r--r--remoting/host/plugin/daemon_controller_linux.cc53
-rw-r--r--remoting/host/plugin/daemon_controller_mac.cc13
5 files changed, 52 insertions, 44 deletions
diff --git a/remoting/host/host_config.h b/remoting/host/host_config.h
index 8befb0e..ec8162c 100644
--- a/remoting/host/host_config.h
+++ b/remoting/host/host_config.h
@@ -9,6 +9,10 @@
#include "base/basictypes.h"
+namespace base {
+class DictionaryValue;
+} // namespace base
+
namespace remoting {
// Following constants define names for configuration parameters.
@@ -60,6 +64,11 @@ class MutableHostConfig : public HostConfig {
const std::string& in_value) = 0;
virtual void SetBoolean(const std::string& path, bool in_value) = 0;
+ // Copy configuration from specified |dictionary|. Returns false if the
+ // |dictionary| contains some values that cannot be saved in the config. In
+ // that case, all other values are still copied.
+ virtual bool CopyFrom(const base::DictionaryValue* dictionary) = 0;
+
// Saves changes.
virtual bool Save() = 0;
diff --git a/remoting/host/in_memory_host_config.cc b/remoting/host/in_memory_host_config.cc
index 5e95127..b2f2991 100644
--- a/remoting/host/in_memory_host_config.cc
+++ b/remoting/host/in_memory_host_config.cc
@@ -44,4 +44,23 @@ void InMemoryHostConfig::SetBoolean(const std::string& path, bool in_value) {
values_->SetBoolean(path, in_value);
}
+bool InMemoryHostConfig::CopyFrom(const base::DictionaryValue* dictionary) {
+ bool result = true;
+
+ for (DictionaryValue::key_iterator key(dictionary->begin_keys());
+ key != dictionary->end_keys(); ++key) {
+ std::string str_value;
+ bool bool_value;
+ if (dictionary->GetString(*key, &str_value)) {
+ SetString(*key, str_value);
+ } else if (dictionary->GetBoolean(*key, &bool_value)) {
+ SetBoolean(*key, bool_value);
+ } else {
+ result = false;
+ }
+ }
+
+ return result;
+}
+
} // namespace remoting
diff --git a/remoting/host/in_memory_host_config.h b/remoting/host/in_memory_host_config.h
index 82b9f6f..7d5357c 100644
--- a/remoting/host/in_memory_host_config.h
+++ b/remoting/host/in_memory_host_config.h
@@ -34,6 +34,8 @@ class InMemoryHostConfig : public MutableHostConfig,
const std::string& in_value) OVERRIDE;
virtual void SetBoolean(const std::string& path, bool in_value) OVERRIDE;
+ virtual bool CopyFrom(const base::DictionaryValue* dictionary) OVERRIDE;
+
virtual bool Save() OVERRIDE;
protected:
diff --git a/remoting/host/plugin/daemon_controller_linux.cc b/remoting/host/plugin/daemon_controller_linux.cc
index a7698653..133992b 100644
--- a/remoting/host/plugin/daemon_controller_linux.cc
+++ b/remoting/host/plugin/daemon_controller_linux.cc
@@ -43,15 +43,6 @@ std::string GetMd5(const std::string& value) {
return StringToLowerASCII(base::HexEncode(digest.a, sizeof(digest.a)));
}
-// TODO(sergeyu): This is a very hacky implementation of
-// DaemonController interface for linux. Current version works, but
-// there are sevaral problems with it:
-// * All calls are executed synchronously, even though this API is
-// supposed to be asynchronous.
-// * The host is configured by passing configuration data as CL
-// argument - this is obviously not secure.
-// Rewrite this code to solve these two problems.
-// http://crbug.com/120950 .
class DaemonControllerLinux : public remoting::DaemonController {
public:
DaemonControllerLinux();
@@ -235,19 +226,9 @@ void DaemonControllerLinux::DoSetConfigAndStart(
scoped_ptr<base::DictionaryValue> config,
const CompletionCallback& done_callback) {
JsonHostConfig config_file(GetConfigPath());
- for (DictionaryValue::key_iterator key(config->begin_keys());
- key != config->end_keys(); ++key) {
- std::string value;
- if (!config->GetString(*key, &value)) {
- LOG(ERROR) << *key << " is not a string.";
- done_callback.Run(RESULT_FAILED);
- return;
- }
- config_file.SetString(*key, value);
- }
-
- bool success = config_file.Save();
- if (!success) {
+ if (!config_file.CopyFrom(config.get()) ||
+ !config_file.Save()) {
+ LOG(ERROR) << "Failed to update config file.";
done_callback.Run(RESULT_FAILED);
return;
}
@@ -268,23 +249,25 @@ void DaemonControllerLinux::DoUpdateConfig(
scoped_ptr<base::DictionaryValue> config,
const CompletionCallback& done_callback) {
JsonHostConfig config_file(GetConfigPath());
- if (!config_file.Read()) {
+ if (!config_file.Read() ||
+ !config_file.CopyFrom(config.get()) ||
+ !config_file.Save()) {
+ LOG(ERROR) << "Failed to update config file.";
done_callback.Run(RESULT_FAILED);
+ return;
}
- for (DictionaryValue::key_iterator key(config->begin_keys());
- key != config->end_keys(); ++key) {
- std::string value;
- if (!config->GetString(*key, &value)) {
- LOG(ERROR) << *key << " is not a string.";
- done_callback.Run(RESULT_FAILED);
- return;
- }
- config_file.SetString(*key, value);
+ std::vector<std::string> args;
+ args.push_back("--reload");
+ AsyncResult result;
+ int exit_code;
+ if (RunScript(args, &exit_code)) {
+ result = (exit_code == 0) ? RESULT_OK : RESULT_FAILED;
+ } else {
+ result = RESULT_FAILED;
}
- bool success = config_file.Save();
- done_callback.Run(success ? RESULT_OK : RESULT_FAILED);
- // TODO(sergeyu): Send signal to the daemon to restart the host.
+
+ done_callback.Run(result);
}
void DaemonControllerLinux::DoStop(const CompletionCallback& done_callback) {
diff --git a/remoting/host/plugin/daemon_controller_mac.cc b/remoting/host/plugin/daemon_controller_mac.cc
index 66505c8..54c59b3 100644
--- a/remoting/host/plugin/daemon_controller_mac.cc
+++ b/remoting/host/plugin/daemon_controller_mac.cc
@@ -228,15 +228,10 @@ void DaemonControllerMac::DoUpdateConfig(
done_callback.Run(RESULT_FAILED);
return;
}
- for (DictionaryValue::key_iterator key(config->begin_keys());
- key != config->end_keys(); ++key) {
- std::string value;
- if (!config->GetString(*key, &value)) {
- LOG(ERROR) << *key << " is not a string.";
- done_callback.Run(RESULT_FAILED);
- return;
- }
- config_file.SetString(*key, value);
+ if (!config_file.CopyFrom(config.get())) {
+ LOG(ERROR) << "Failed to update configuration.";
+ done_callback.Run(RESULT_FAILED);
+ return;
}
std::string config_data = config_file.GetSerializedData();