summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-07 21:38:16 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-07 21:38:16 +0000
commit08113d3684190cf94fa5ee1a86b2c450cc076e7a (patch)
treef27d56de0ef609d8e50753b50979120c233ac008 /remoting
parent2325b6cf6e305be6c4f56f92dfc1e2399a60ed4d (diff)
downloadchromium_src-08113d3684190cf94fa5ee1a86b2c450cc076e7a.zip
chromium_src-08113d3684190cf94fa5ee1a86b2c450cc076e7a.tar.gz
chromium_src-08113d3684190cf94fa5ee1a86b2c450cc076e7a.tar.bz2
Implement GetConfig() and UpdateConfig in DaemonControllerLinux.
BUG=120950 Review URL: http://codereview.chromium.org/10008066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131296 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/plugin/daemon_controller_linux.cc63
-rwxr-xr-xremoting/tools/me2me_virtual_host.py10
2 files changed, 59 insertions, 14 deletions
diff --git a/remoting/host/plugin/daemon_controller_linux.cc b/remoting/host/plugin/daemon_controller_linux.cc
index 58ca210..d68be8a 100644
--- a/remoting/host/plugin/daemon_controller_linux.cc
+++ b/remoting/host/plugin/daemon_controller_linux.cc
@@ -12,20 +12,36 @@
#include "base/compiler_specific.h"
#include "base/environment.h"
#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
+#include "base/md5.h"
#include "base/process_util.h"
+#include "base/string_number_conversions.h"
#include "base/string_split.h"
+#include "base/string_util.h"
#include "base/threading/thread.h"
#include "base/values.h"
+#include "net/base/net_util.h"
+#include "remoting/host/host_config.h"
+#include "remoting/host/json_host_config.h"
namespace remoting {
namespace {
-const char* kDaemonScript = "me2me_virtual_host.py";
+const char kDaemonScript[] = "me2me_virtual_host.py";
const int64 kDaemonTimeoutMs = 5000;
+std::string GetMd5(const std::string& value) {
+ base::MD5Context ctx;
+ base::MD5Init(&ctx);
+ base::MD5Update(&ctx, value);
+ base::MD5Digest digest;
+ base::MD5Final(&digest, &ctx);
+ 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:
@@ -49,6 +65,9 @@ class DaemonControllerLinux : public remoting::DaemonController {
virtual void Stop(const CompletionCallback& done_callback) OVERRIDE;
private:
+ FilePath GetConfigPath();
+
+ void DoGetConfig(const GetConfigCallback& callback);
void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config,
const CompletionCallback& done_callback);
void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config,
@@ -133,7 +152,9 @@ remoting::DaemonController::State DaemonControllerLinux::GetState() {
}
void DaemonControllerLinux::GetConfig(const GetConfigCallback& callback) {
- NOTIMPLEMENTED();
+ // base::Unretained() is safe because we control lifetime of the thread.
+ file_io_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
+ &DaemonControllerLinux::DoGetConfig, base::Unretained(this), callback));
}
void DaemonControllerLinux::SetConfigAndStart(
@@ -159,6 +180,27 @@ void DaemonControllerLinux::Stop(const CompletionCallback& done_callback) {
done_callback));
}
+FilePath DaemonControllerLinux::GetConfigPath() {
+ std::string filename = "host#" + GetMd5(net::GetHostName()) + ".json";
+ return file_util::GetHomeDir().
+ Append(".config/chrome-remote-desktop").Append(filename);
+}
+
+void DaemonControllerLinux::DoGetConfig(const GetConfigCallback& callback) {
+ JsonHostConfig config(GetConfigPath());
+ scoped_ptr<base::DictionaryValue> result;
+ if (config.Read()) {
+ result.reset(new base::DictionaryValue());
+
+ std::string value;
+ if (config.GetString(kHostIdConfigPath, &value))
+ result->SetString(kHostIdConfigPath, value);
+ if (config.GetString(kXmppLoginConfigPath, &value))
+ result->SetString(kXmppLoginConfigPath, value);
+ }
+ callback.Run(result.Pass());
+}
+
void DaemonControllerLinux::DoSetConfigAndStart(
scoped_ptr<base::DictionaryValue> config,
const CompletionCallback& done_callback) {
@@ -181,8 +223,21 @@ void DaemonControllerLinux::DoSetConfigAndStart(
void DaemonControllerLinux::DoUpdateConfig(
scoped_ptr<base::DictionaryValue> config,
const CompletionCallback& done_callback) {
- NOTIMPLEMENTED();
- done_callback.Run(RESULT_OK);
+ JsonHostConfig config_file(GetConfigPath());
+ if (!config_file.Read())
+ done_callback.Run(RESULT_FAILED);
+
+ for (DictionaryValue::key_iterator key(config->begin_keys());
+ key != config->end_keys(); ++key) {
+ std::string value;
+ if (!config->GetString(*key, &value)) {
+ LOG(WARNING) << "Skipping " << *key << " because it is not a string.";
+ }
+ config_file.SetString(*key, value);
+ }
+ bool success = config_file.Save();
+ done_callback.Run(success ? RESULT_OK : RESULT_FAILED);
+ // TODO(sergeyu): Send signal to the daemon to restart the host.
}
void DaemonControllerLinux::DoStop(const CompletionCallback& done_callback) {
diff --git a/remoting/tools/me2me_virtual_host.py b/remoting/tools/me2me_virtual_host.py
index 56ff78f..69994d0 100755
--- a/remoting/tools/me2me_virtual_host.py
+++ b/remoting/tools/me2me_virtual_host.py
@@ -540,8 +540,6 @@ def main():
parser.add_option("", "--check-running", dest="check_running", default=False,
action="store_true",
help="return 0 if the daemon is running, or 1 otherwise")
- parser.add_option("", "--explicit-pin", dest="explicit_pin",
- help="set or unset the pin on the command line")
parser.add_option("", "--explicit-config", dest="explicit_config",
help="explicitly specify content of the config")
(options, args) = parser.parse_args()
@@ -598,14 +596,6 @@ def main():
host = Host(os.path.join(CONFIG_DIR, "host#%s.json" % host_hash))
register_host = not host.load_config()
- if options.explicit_pin != None:
- host.set_pin(options.explicit_pin)
- host.save_config()
- running, pid = PidFile(pid_filename).check()
- if running and pid != 0:
- os.kill(pid, signal.SIGUSR1)
- return 0
-
# Outside the loop so user doesn't get asked twice.
if register_host:
host.ask_pin()