Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/plugin/daemon_controller.h" | 5 #include "remoting/host/plugin/daemon_controller.h" |
| 6 | 6 |
| 7 #include <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 FilePath GetConfigPath(); | 71 FilePath GetConfigPath(); |
| 72 | 72 |
| 73 void DoGetConfig(const GetConfigCallback& callback); | 73 void DoGetConfig(const GetConfigCallback& callback); |
| 74 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, | 74 void DoSetConfigAndStart(scoped_ptr<base::DictionaryValue> config, |
| 75 const CompletionCallback& done); | 75 const CompletionCallback& done); |
| 76 void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config, | 76 void DoUpdateConfig(scoped_ptr<base::DictionaryValue> config, |
| 77 const CompletionCallback& done_callback); | 77 const CompletionCallback& done_callback); |
| 78 void DoStop(const CompletionCallback& done_callback); | 78 void DoStop(const CompletionCallback& done_callback); |
| 79 void DoGetVersion(const GetVersionCallback& done_callback); | |
| 79 | 80 |
| 80 base::Thread file_io_thread_; | 81 base::Thread file_io_thread_; |
| 81 | 82 |
| 82 DISALLOW_COPY_AND_ASSIGN(DaemonControllerLinux); | 83 DISALLOW_COPY_AND_ASSIGN(DaemonControllerLinux); |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 DaemonControllerLinux::DaemonControllerLinux() | 86 DaemonControllerLinux::DaemonControllerLinux() |
| 86 : file_io_thread_("DaemonControllerFileIO") { | 87 : file_io_thread_("DaemonControllerFileIO") { |
| 87 file_io_thread_.Start(); | 88 file_io_thread_.Start(); |
| 88 } | 89 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 &DaemonControllerLinux::DoStop, base::Unretained(this), | 188 &DaemonControllerLinux::DoStop, base::Unretained(this), |
| 188 done_callback)); | 189 done_callback)); |
| 189 } | 190 } |
| 190 | 191 |
| 191 void DaemonControllerLinux::SetWindow(void* window_handle) { | 192 void DaemonControllerLinux::SetWindow(void* window_handle) { |
| 192 // noop | 193 // noop |
| 193 } | 194 } |
| 194 | 195 |
| 195 void DaemonControllerLinux::GetVersion( | 196 void DaemonControllerLinux::GetVersion( |
| 196 const GetVersionCallback& done_callback) { | 197 const GetVersionCallback& done_callback) { |
| 197 // TODO(sergeyu): Implement this method. | 198 file_io_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
| 198 NOTIMPLEMENTED(); | 199 &DaemonControllerLinux::DoGetVersion, base::Unretained(this), |
| 199 done_callback.Run(""); | 200 done_callback)); |
| 200 } | 201 } |
| 201 | 202 |
| 202 FilePath DaemonControllerLinux::GetConfigPath() { | 203 FilePath DaemonControllerLinux::GetConfigPath() { |
| 203 std::string filename = "host#" + GetMd5(net::GetHostName()) + ".json"; | 204 std::string filename = "host#" + GetMd5(net::GetHostName()) + ".json"; |
| 204 return file_util::GetHomeDir(). | 205 return file_util::GetHomeDir(). |
| 205 Append(".config/chrome-remote-desktop").Append(filename); | 206 Append(".config/chrome-remote-desktop").Append(filename); |
| 206 } | 207 } |
| 207 | 208 |
| 208 void DaemonControllerLinux::DoGetConfig(const GetConfigCallback& callback) { | 209 void DaemonControllerLinux::DoGetConfig(const GetConfigCallback& callback) { |
| 209 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 210 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 int exit_code = 0; | 296 int exit_code = 0; |
| 296 AsyncResult result; | 297 AsyncResult result; |
| 297 if (RunHostScript(args, &exit_code)) { | 298 if (RunHostScript(args, &exit_code)) { |
| 298 result = (exit_code == 0) ? RESULT_OK : RESULT_FAILED; | 299 result = (exit_code == 0) ? RESULT_OK : RESULT_FAILED; |
| 299 } else { | 300 } else { |
| 300 result = RESULT_FAILED; | 301 result = RESULT_FAILED; |
| 301 } | 302 } |
| 302 done_callback.Run(result); | 303 done_callback.Run(result); |
| 303 } | 304 } |
| 304 | 305 |
| 306 void DaemonControllerLinux::DoGetVersion( | |
| 307 const GetVersionCallback& done_callback) { | |
| 308 FilePath script_path; | |
| 309 if (!GetScriptPath(&script_path)) { | |
| 310 done_callback.Run(""); | |
| 311 return; | |
| 312 } | |
| 313 CommandLine command_line(script_path); | |
| 314 command_line.AppendArg("--host-version"); | |
| 315 | |
| 316 std::string output; | |
|
Jamie
2012/09/06 01:29:50
TrimWhitespaceASCII states that it's safe to use t
Sergey Ulanov
2012/09/06 19:31:58
Done.
| |
| 317 int exit_code; | |
| 318 int result = | |
| 319 base::GetAppOutputWithExitCode(command_line, &output, &exit_code); | |
| 320 if (!result) { | |
|
Jamie
2012/09/06 01:29:50
LOG(ERROR) here?
Sergey Ulanov
2012/09/06 19:31:58
Done.
| |
| 321 done_callback.Run(""); | |
| 322 return; | |
| 323 } | |
| 324 | |
|
Jamie
2012/09/06 01:29:50
Perhaps add a test for exit_code being zero?
Sergey Ulanov
2012/09/06 19:31:58
Done.
| |
| 325 std::string version; | |
| 326 TrimWhitespaceASCII(output, TRIM_ALL, &version); | |
| 327 if (!ContainsOnlyChars(version, "0123456789.")) { | |
| 328 LOG(ERROR) << "Received invalid host version number: " << version; | |
| 329 done_callback.Run(""); | |
| 330 return; | |
| 331 } | |
| 332 | |
| 333 done_callback.Run(version); | |
| 334 } | |
| 335 | |
| 305 } // namespace | 336 } // namespace |
| 306 | 337 |
| 307 scoped_ptr<DaemonController> remoting::DaemonController::Create() { | 338 scoped_ptr<DaemonController> remoting::DaemonController::Create() { |
| 308 return scoped_ptr<DaemonController>(new DaemonControllerLinux()); | 339 return scoped_ptr<DaemonController>(new DaemonControllerLinux()); |
| 309 } | 340 } |
| 310 | 341 |
| 311 } // namespace remoting | 342 } // namespace remoting |
| OLD | NEW |