Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: remoting/host/setup/daemon_controller_delegate_win.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "base/win/scoped_bstr.h" 18 #include "base/win/scoped_bstr.h"
18 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
19 #include "remoting/base/scoped_sc_handle_win.h" 20 #include "remoting/base/scoped_sc_handle_win.h"
20 #include "remoting/host/branding.h" 21 #include "remoting/host/branding.h"
21 #include "remoting/host/host_config.h" 22 #include "remoting/host/host_config.h"
22 #include "remoting/host/usage_stats_consent.h" 23 #include "remoting/host/usage_stats_consent.h"
23 #include "remoting/host/win/security_descriptor.h" 24 #include "remoting/host/win/security_descriptor.h"
24 25
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 kHostIdConfigPath, kHostOwnerConfigPath, kHostOwnerEmailConfigPath, 60 kHostIdConfigPath, kHostOwnerConfigPath, kHostOwnerEmailConfigPath,
60 kXmppLoginConfigPath }; 61 kXmppLoginConfigPath };
61 62
62 // The configuration keys whose values may be read by GetConfig(). 63 // The configuration keys whose values may be read by GetConfig().
63 const char* const kUnprivilegedConfigKeys[] = { 64 const char* const kUnprivilegedConfigKeys[] = {
64 kHostIdConfigPath, kXmppLoginConfigPath }; 65 kHostIdConfigPath, kXmppLoginConfigPath };
65 66
66 // Reads and parses the configuration file up to |kMaxConfigFileSize| in 67 // Reads and parses the configuration file up to |kMaxConfigFileSize| in
67 // size. 68 // size.
68 bool ReadConfig(const base::FilePath& filename, 69 bool ReadConfig(const base::FilePath& filename,
69 scoped_ptr<base::DictionaryValue>* config_out) { 70 std::unique_ptr<base::DictionaryValue>* config_out) {
70 std::string file_content; 71 std::string file_content;
71 if (!base::ReadFileToStringWithMaxSize(filename, &file_content, 72 if (!base::ReadFileToStringWithMaxSize(filename, &file_content,
72 kMaxConfigFileSize)) { 73 kMaxConfigFileSize)) {
73 PLOG(ERROR) << "Failed to read '" << filename.value() << "'."; 74 PLOG(ERROR) << "Failed to read '" << filename.value() << "'.";
74 return false; 75 return false;
75 } 76 }
76 77
77 // Parse the JSON configuration, expecting it to contain a dictionary. 78 // Parse the JSON configuration, expecting it to contain a dictionary.
78 scoped_ptr<base::Value> value = 79 std::unique_ptr<base::Value> value =
79 base::JSONReader::Read(file_content, base::JSON_ALLOW_TRAILING_COMMAS); 80 base::JSONReader::Read(file_content, base::JSON_ALLOW_TRAILING_COMMAS);
80 81
81 base::DictionaryValue* dictionary; 82 base::DictionaryValue* dictionary;
82 if (!value || !value->GetAsDictionary(&dictionary)) { 83 if (!value || !value->GetAsDictionary(&dictionary)) {
83 LOG(ERROR) << "Failed to parse '" << filename.value() << "'."; 84 LOG(ERROR) << "Failed to parse '" << filename.value() << "'.";
84 return false; 85 return false;
85 } 86 }
86 87
87 ignore_result(value.release()); 88 ignore_result(value.release());
88 config_out->reset(dictionary); 89 config_out->reset(dictionary);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return true; 153 return true;
153 } 154 }
154 155
155 // Writes the configuration file up to |kMaxConfigFileSize| in size. 156 // Writes the configuration file up to |kMaxConfigFileSize| in size.
156 bool WriteConfig(const std::string& content) { 157 bool WriteConfig(const std::string& content) {
157 if (content.length() > kMaxConfigFileSize) { 158 if (content.length() > kMaxConfigFileSize) {
158 return false; 159 return false;
159 } 160 }
160 161
161 // Extract the configuration data that the user will verify. 162 // Extract the configuration data that the user will verify.
162 scoped_ptr<base::Value> config_value = base::JSONReader::Read(content); 163 std::unique_ptr<base::Value> config_value = base::JSONReader::Read(content);
163 if (!config_value.get()) { 164 if (!config_value.get()) {
164 return false; 165 return false;
165 } 166 }
166 base::DictionaryValue* config_dict = nullptr; 167 base::DictionaryValue* config_dict = nullptr;
167 if (!config_value->GetAsDictionary(&config_dict)) { 168 if (!config_value->GetAsDictionary(&config_dict)) {
168 return false; 169 return false;
169 } 170 }
170 std::string email; 171 std::string email;
171 if (!config_dict->GetString(kHostOwnerEmailConfigPath, &email) && 172 if (!config_dict->GetString(kHostOwnerEmailConfigPath, &email) &&
172 !config_dict->GetString(kHostOwnerConfigPath, &email) && 173 !config_dict->GetString(kHostOwnerConfigPath, &email) &&
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 SERVICE_STATUS status; 362 SERVICE_STATUS status;
362 if (!::QueryServiceStatus(service.Get(), &status)) { 363 if (!::QueryServiceStatus(service.Get(), &status)) {
363 PLOG(ERROR) << "Failed to query the state of the '" 364 PLOG(ERROR) << "Failed to query the state of the '"
364 << kWindowsServiceName << "' service"; 365 << kWindowsServiceName << "' service";
365 return DaemonController::STATE_UNKNOWN; 366 return DaemonController::STATE_UNKNOWN;
366 } 367 }
367 368
368 return ConvertToDaemonState(status.dwCurrentState); 369 return ConvertToDaemonState(status.dwCurrentState);
369 } 370 }
370 371
371 scoped_ptr<base::DictionaryValue> DaemonControllerDelegateWin::GetConfig() { 372 std::unique_ptr<base::DictionaryValue>
373 DaemonControllerDelegateWin::GetConfig() {
372 base::FilePath config_dir = remoting::GetConfigDir(); 374 base::FilePath config_dir = remoting::GetConfigDir();
373 375
374 // Read the unprivileged part of host configuration. 376 // Read the unprivileged part of host configuration.
375 scoped_ptr<base::DictionaryValue> config; 377 std::unique_ptr<base::DictionaryValue> config;
376 if (!ReadConfig(config_dir.Append(kUnprivilegedConfigFileName), &config)) 378 if (!ReadConfig(config_dir.Append(kUnprivilegedConfigFileName), &config))
377 return nullptr; 379 return nullptr;
378 380
379 return config; 381 return config;
380 } 382 }
381 383
382 void DaemonControllerDelegateWin::UpdateConfig( 384 void DaemonControllerDelegateWin::UpdateConfig(
383 scoped_ptr<base::DictionaryValue> config, 385 std::unique_ptr<base::DictionaryValue> config,
384 const DaemonController::CompletionCallback& done) { 386 const DaemonController::CompletionCallback& done) {
385 // Check for bad keys. 387 // Check for bad keys.
386 for (size_t i = 0; i < arraysize(kReadonlyKeys); ++i) { 388 for (size_t i = 0; i < arraysize(kReadonlyKeys); ++i) {
387 if (config->HasKey(kReadonlyKeys[i])) { 389 if (config->HasKey(kReadonlyKeys[i])) {
388 LOG(ERROR) << "Cannot update config: '" << kReadonlyKeys[i] 390 LOG(ERROR) << "Cannot update config: '" << kReadonlyKeys[i]
389 << "' is read only."; 391 << "' is read only.";
390 InvokeCompletionCallback(done, false); 392 InvokeCompletionCallback(done, false);
391 return; 393 return;
392 } 394 }
393 } 395 }
394 // Get the old config. 396 // Get the old config.
395 base::FilePath config_dir = remoting::GetConfigDir(); 397 base::FilePath config_dir = remoting::GetConfigDir();
396 scoped_ptr<base::DictionaryValue> config_old; 398 std::unique_ptr<base::DictionaryValue> config_old;
397 if (!ReadConfig(config_dir.Append(kConfigFileName), &config_old)) { 399 if (!ReadConfig(config_dir.Append(kConfigFileName), &config_old)) {
398 InvokeCompletionCallback(done, false); 400 InvokeCompletionCallback(done, false);
399 return; 401 return;
400 } 402 }
401 403
402 // Merge items from the given config into the old config. 404 // Merge items from the given config into the old config.
403 config_old->MergeDictionary(config.release()); 405 config_old->MergeDictionary(config.release());
404 406
405 // Write the updated config. 407 // Write the updated config.
406 std::string config_updated_str; 408 std::string config_updated_str;
(...skipping 24 matching lines...) Expand all
431 // consent to collecting crash dumps. 433 // consent to collecting crash dumps.
432 if (remoting::GetUsageStatsConsent(&allowed, &set_by_policy)) { 434 if (remoting::GetUsageStatsConsent(&allowed, &set_by_policy)) {
433 consent.allowed = allowed; 435 consent.allowed = allowed;
434 consent.set_by_policy = set_by_policy; 436 consent.set_by_policy = set_by_policy;
435 } 437 }
436 438
437 return consent; 439 return consent;
438 } 440 }
439 441
440 void DaemonControllerDelegateWin::SetConfigAndStart( 442 void DaemonControllerDelegateWin::SetConfigAndStart(
441 scoped_ptr<base::DictionaryValue> config, 443 std::unique_ptr<base::DictionaryValue> config,
442 bool consent, 444 bool consent,
443 const DaemonController::CompletionCallback& done) { 445 const DaemonController::CompletionCallback& done) {
444 // Record the user's consent. 446 // Record the user's consent.
445 if (!remoting::SetUsageStatsConsent(consent)) { 447 if (!remoting::SetUsageStatsConsent(consent)) {
446 InvokeCompletionCallback(done, false); 448 InvokeCompletionCallback(done, false);
447 return; 449 return;
448 } 450 }
449 451
450 // Set the configuration. 452 // Set the configuration.
451 std::string config_str; 453 std::string config_str;
(...skipping 11 matching lines...) Expand all
463 InvokeCompletionCallback(done, false); 465 InvokeCompletionCallback(done, false);
464 return; 466 return;
465 } 467 }
466 468
467 // Start daemon. 469 // Start daemon.
468 InvokeCompletionCallback(done, StartDaemon()); 470 InvokeCompletionCallback(done, StartDaemon());
469 } 471 }
470 472
471 scoped_refptr<DaemonController> DaemonController::Create() { 473 scoped_refptr<DaemonController> DaemonController::Create() {
472 return new DaemonController( 474 return new DaemonController(
473 make_scoped_ptr(new DaemonControllerDelegateWin())); 475 base::WrapUnique(new DaemonControllerDelegateWin()));
474 } 476 }
475 477
476 } // namespace remoting 478 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/setup/daemon_controller_delegate_win.h ('k') | remoting/host/setup/host_starter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698