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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } else { | 226 } else { |
227 result.reset(); // Return NULL in case of error. | 227 result.reset(); // Return NULL in case of error. |
228 } | 228 } |
229 } | 229 } |
230 | 230 |
231 callback.Run(result.Pass()); | 231 callback.Run(result.Pass()); |
232 } | 232 } |
233 | 233 |
234 void DaemonControllerLinux::DoSetConfigAndStart( | 234 void DaemonControllerLinux::DoSetConfigAndStart( |
235 scoped_ptr<base::DictionaryValue> config, | 235 scoped_ptr<base::DictionaryValue> config, |
236 const CompletionCallback& done) { | 236 const CompletionCallback& done_callback) { |
| 237 JsonHostConfig config_file(GetConfigPath()); |
| 238 for (DictionaryValue::key_iterator key(config->begin_keys()); |
| 239 key != config->end_keys(); ++key) { |
| 240 std::string value; |
| 241 if (!config->GetString(*key, &value)) { |
| 242 LOG(ERROR) << *key << " is not a string."; |
| 243 done_callback.Run(RESULT_FAILED); |
| 244 return; |
| 245 } |
| 246 config_file.SetString(*key, value); |
| 247 } |
| 248 |
| 249 bool success = config_file.Save(); |
| 250 if (!success) { |
| 251 done_callback.Run(RESULT_FAILED); |
| 252 return; |
| 253 } |
| 254 |
237 std::vector<std::string> args; | 255 std::vector<std::string> args; |
238 args.push_back("--explicit-config"); | 256 args.push_back("--silent"); |
239 std::string config_json; | |
240 base::JSONWriter::Write(config.get(), &config_json); | |
241 args.push_back(config_json); | |
242 std::vector<std::string> no_args; | |
243 int exit_code = 0; | |
244 AsyncResult result; | 257 AsyncResult result; |
| 258 int exit_code; |
245 if (RunScript(args, &exit_code)) { | 259 if (RunScript(args, &exit_code)) { |
246 result = (exit_code == 0) ? RESULT_OK : RESULT_FAILED; | 260 result = (exit_code == 0) ? RESULT_OK : RESULT_FAILED; |
247 } else { | 261 } else { |
248 result = RESULT_FAILED; | 262 result = RESULT_FAILED; |
249 } | 263 } |
250 done.Run(result); | 264 done_callback.Run(result); |
251 } | 265 } |
252 | 266 |
253 void DaemonControllerLinux::DoUpdateConfig( | 267 void DaemonControllerLinux::DoUpdateConfig( |
254 scoped_ptr<base::DictionaryValue> config, | 268 scoped_ptr<base::DictionaryValue> config, |
255 const CompletionCallback& done_callback) { | 269 const CompletionCallback& done_callback) { |
256 JsonHostConfig config_file(GetConfigPath()); | 270 JsonHostConfig config_file(GetConfigPath()); |
257 if (!config_file.Read()) { | 271 if (!config_file.Read()) { |
258 done_callback.Run(RESULT_FAILED); | 272 done_callback.Run(RESULT_FAILED); |
259 } | 273 } |
260 | 274 |
261 for (DictionaryValue::key_iterator key(config->begin_keys()); | 275 for (DictionaryValue::key_iterator key(config->begin_keys()); |
262 key != config->end_keys(); ++key) { | 276 key != config->end_keys(); ++key) { |
263 std::string value; | 277 std::string value; |
264 if (!config->GetString(*key, &value)) { | 278 if (!config->GetString(*key, &value)) { |
265 LOG(ERROR) << *key << " is not a string."; | 279 LOG(ERROR) << *key << " is not a string."; |
266 done_callback.Run(RESULT_FAILED); | 280 done_callback.Run(RESULT_FAILED); |
| 281 return; |
267 } | 282 } |
268 config_file.SetString(*key, value); | 283 config_file.SetString(*key, value); |
269 } | 284 } |
270 bool success = config_file.Save(); | 285 bool success = config_file.Save(); |
271 done_callback.Run(success ? RESULT_OK : RESULT_FAILED); | 286 done_callback.Run(success ? RESULT_OK : RESULT_FAILED); |
272 // TODO(sergeyu): Send signal to the daemon to restart the host. | 287 // TODO(sergeyu): Send signal to the daemon to restart the host. |
273 } | 288 } |
274 | 289 |
275 void DaemonControllerLinux::DoStop(const CompletionCallback& done_callback) { | 290 void DaemonControllerLinux::DoStop(const CompletionCallback& done_callback) { |
276 std::vector<std::string> args; | 291 std::vector<std::string> args; |
277 args.push_back("--stop"); | 292 args.push_back("--stop"); |
278 int exit_code = 0; | 293 int exit_code = 0; |
279 AsyncResult result; | 294 AsyncResult result; |
280 if (RunScript(args, &exit_code)) { | 295 if (RunScript(args, &exit_code)) { |
281 result = (exit_code == 0) ? RESULT_OK : RESULT_FAILED; | 296 result = (exit_code == 0) ? RESULT_OK : RESULT_FAILED; |
282 } else { | 297 } else { |
283 result = RESULT_FAILED; | 298 result = RESULT_FAILED; |
284 } | 299 } |
285 done_callback.Run(result); | 300 done_callback.Run(result); |
286 } | 301 } |
287 | 302 |
288 } // namespace | 303 } // namespace |
289 | 304 |
290 scoped_ptr<DaemonController> remoting::DaemonController::Create() { | 305 scoped_ptr<DaemonController> remoting::DaemonController::Create() { |
291 return scoped_ptr<DaemonController>(new DaemonControllerLinux()); | 306 return scoped_ptr<DaemonController>(new DaemonControllerLinux()); |
292 } | 307 } |
293 | 308 |
294 } // namespace remoting | 309 } // namespace remoting |
OLD | NEW |