OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/setup/daemon_controller_delegate_win.h" | 5 #include "remoting/host/setup/daemon_controller_delegate_win.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // Extract the unprivileged fields from the configuration. | 179 // Extract the unprivileged fields from the configuration. |
180 base::DictionaryValue unprivileged_config_dict; | 180 base::DictionaryValue unprivileged_config_dict; |
181 for (int i = 0; i < arraysize(kUnprivilegedConfigKeys); ++i) { | 181 for (int i = 0; i < arraysize(kUnprivilegedConfigKeys); ++i) { |
182 const char* key = kUnprivilegedConfigKeys[i]; | 182 const char* key = kUnprivilegedConfigKeys[i]; |
183 base::string16 value; | 183 base::string16 value; |
184 if (config_dict->GetString(key, &value)) { | 184 if (config_dict->GetString(key, &value)) { |
185 unprivileged_config_dict.SetString(key, value); | 185 unprivileged_config_dict.SetString(key, value); |
186 } | 186 } |
187 } | 187 } |
188 std::string unprivileged_config_str; | 188 std::string unprivileged_config_str; |
189 base::JSONWriter::Write(&unprivileged_config_dict, &unprivileged_config_str); | 189 base::JSONWriter::Write(unprivileged_config_dict, &unprivileged_config_str); |
190 | 190 |
191 // Write the full configuration file to a temporary location. | 191 // Write the full configuration file to a temporary location. |
192 base::FilePath full_config_file_path = | 192 base::FilePath full_config_file_path = |
193 remoting::GetConfigDir().Append(kConfigFileName); | 193 remoting::GetConfigDir().Append(kConfigFileName); |
194 if (!WriteConfigFileToTemp(full_config_file_path, | 194 if (!WriteConfigFileToTemp(full_config_file_path, |
195 kConfigFileSecurityDescriptor, | 195 kConfigFileSecurityDescriptor, |
196 content)) { | 196 content)) { |
197 return false; | 197 return false; |
198 } | 198 } |
199 | 199 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 if (!ReadConfig(config_dir.Append(kConfigFileName), &config_old)) { | 406 if (!ReadConfig(config_dir.Append(kConfigFileName), &config_old)) { |
407 InvokeCompletionCallback(done, false); | 407 InvokeCompletionCallback(done, false); |
408 return; | 408 return; |
409 } | 409 } |
410 | 410 |
411 // Merge items from the given config into the old config. | 411 // Merge items from the given config into the old config. |
412 config_old->MergeDictionary(config.release()); | 412 config_old->MergeDictionary(config.release()); |
413 | 413 |
414 // Write the updated config. | 414 // Write the updated config. |
415 std::string config_updated_str; | 415 std::string config_updated_str; |
416 base::JSONWriter::Write(config_old.get(), &config_updated_str); | 416 base::JSONWriter::Write(*config_old, &config_updated_str); |
417 bool result = WriteConfig(config_updated_str); | 417 bool result = WriteConfig(config_updated_str); |
418 | 418 |
419 InvokeCompletionCallback(done, result); | 419 InvokeCompletionCallback(done, result); |
420 } | 420 } |
421 | 421 |
422 void DaemonControllerDelegateWin::Stop( | 422 void DaemonControllerDelegateWin::Stop( |
423 const DaemonController::CompletionCallback& done) { | 423 const DaemonController::CompletionCallback& done) { |
424 bool result = StopDaemon(); | 424 bool result = StopDaemon(); |
425 | 425 |
426 InvokeCompletionCallback(done, result); | 426 InvokeCompletionCallback(done, result); |
(...skipping 24 matching lines...) Expand all Loading... |
451 bool consent, | 451 bool consent, |
452 const DaemonController::CompletionCallback& done) { | 452 const DaemonController::CompletionCallback& done) { |
453 // Record the user's consent. | 453 // Record the user's consent. |
454 if (!remoting::SetUsageStatsConsent(consent)) { | 454 if (!remoting::SetUsageStatsConsent(consent)) { |
455 InvokeCompletionCallback(done, false); | 455 InvokeCompletionCallback(done, false); |
456 return; | 456 return; |
457 } | 457 } |
458 | 458 |
459 // Set the configuration. | 459 // Set the configuration. |
460 std::string config_str; | 460 std::string config_str; |
461 base::JSONWriter::Write(config.release(), &config_str); | 461 base::JSONWriter::Write(*config, &config_str); |
462 | 462 |
463 // Determine the config directory path and create it if necessary. | 463 // Determine the config directory path and create it if necessary. |
464 base::FilePath config_dir = remoting::GetConfigDir(); | 464 base::FilePath config_dir = remoting::GetConfigDir(); |
465 if (!base::CreateDirectory(config_dir)) { | 465 if (!base::CreateDirectory(config_dir)) { |
466 PLOG(ERROR) << "Failed to create the config directory."; | 466 PLOG(ERROR) << "Failed to create the config directory."; |
467 InvokeCompletionCallback(done, false); | 467 InvokeCompletionCallback(done, false); |
468 return; | 468 return; |
469 } | 469 } |
470 | 470 |
471 if (!WriteConfig(config_str)) { | 471 if (!WriteConfig(config_str)) { |
472 InvokeCompletionCallback(done, false); | 472 InvokeCompletionCallback(done, false); |
473 return; | 473 return; |
474 } | 474 } |
475 | 475 |
476 // Start daemon. | 476 // Start daemon. |
477 InvokeCompletionCallback(done, StartDaemon()); | 477 InvokeCompletionCallback(done, StartDaemon()); |
478 } | 478 } |
479 | 479 |
480 scoped_refptr<DaemonController> DaemonController::Create() { | 480 scoped_refptr<DaemonController> DaemonController::Create() { |
481 scoped_ptr<DaemonController::Delegate> delegate( | 481 scoped_ptr<DaemonController::Delegate> delegate( |
482 new DaemonControllerDelegateWin()); | 482 new DaemonControllerDelegateWin()); |
483 return new DaemonController(delegate.Pass()); | 483 return new DaemonController(delegate.Pass()); |
484 } | 484 } |
485 | 485 |
486 } // namespace remoting | 486 } // namespace remoting |
OLD | NEW |